go-localize alternatives and similar packages
Based on the "Natural Language Processing" category.
Alternatively, view go-localize alternatives based on common mentions on social networks and blogs.
-
prose
:book: A Golang library for text processing, including tokenization, part-of-speech tagging, and named-entity extraction. -
gse
Go efficient multilingual NLP and text segmentation; support English, Chinese, Japanese and others. -
spaGO
Self-contained Machine Learning and Natural Language Processing library in Go -
kagome
Self-contained Japanese Morphological Analyzer written in pure Go -
nlp
[UNMANTEINED] Extract values from strings and fill your structs with nlp. -
universal-translator
:speech_balloon: i18n Translator for Go/Golang using CLDR data + pluralization rules -
locales
:earth_americas: a set of locales generated from the CLDR Project which can be used independently or within an i18n package; these were built for use with, but not exclusive to https://github.com/go-playground/universal-translator -
RAKE.go
A Go port of the Rapid Automatic Keyword Extraction algorithm (RAKE) -
go-nlp
Utilities for working with discrete probability distributions and other tools useful for doing NLP work. -
segment
A Go library for performing Unicode Text Segmentation as described in Unicode Standard Annex #29 -
textcat
A Go package for n-gram based text categorization, with support for utf-8 and raw text -
stemmer
Stemmer packages for Go programming language. Includes English, German and Dutch stemmers. -
petrovich
Golang port of Petrovich - an inflector for Russian anthroponyms. -
paicehusk
Golang implementation of the Paice/Husk Stemming Algorithm -
go-tinydate
A tiny date object in Go. Tinydate uses only 4 bytes of memory -
golibstemmer
Go bindings for the snowball libstemmer library including porter 2 -
gotokenizer
A tokenizer based on the dictionary and Bigram language models for Go. (Now only support chinese segmentation) -
spreak
Flexible translation and humanization library for Go, based on the concepts behind gettext. -
gosentiwordnet
💬 Sentiment analyzer library using SentiWordnet in Go -
spelling-corrector
Spelling corrector for Spanish language
Clean code begins in your IDE with SonarLint
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of go-localize or a related project?
Popular Comparisons
README
go-localize
Simple and easy to use i18n (Internationalization and localization) engine written in Go, used for translating locale strings. Use with go generate or on the CLI. Currently supports JSON, YAML, TOML and CSV translation files
Why another i18n library?
This package aims to be as simple and easy to use as possible. It also takes inspiration from popular localization libraries/packages in other languages - so makes it easier to reason about coming from other languages and frameworks.
Usage
Go generate
The suggested way to use go-localize is to use go generate
. For example, take the following directory structure:
goapp
└── localizations_src
├── en
│ └── messages.yaml
└── es
├── customer
│ └── messages.json
└── messages.json
Example of JSON translation file:
{
"hello": "Hola",
"how_are_you": "¿Cómo estás?",
"whats_your_name": "¿Cuál es tu nombre?",
"hello_my_name_is": "Hola, mi nombre es {{.name}}"
}
Example of YAML translation file:
hello: hello
how_are_you: How are you?
whats_your_name: "What's your name?"
hello_my_name_is: Hello my name is {{.name}}
hello_firstname_lastname: Hello {{.firstname}} {{.lastname}}
Example of CSV translation file:
hello, hello
how_are_you, How are you?
Example of TOML translation file:
hello = "hello"
how_are_you = "How are you?"
To then generate the localization package, add the following to your main.go
or another one of your .go
files:
//go:generate go-localize -input localizations_src -output localizations
Now you'll be able to use the localization like so:
l := localizations.New("en", "es")
println(l.Get("messages.how_are_you")) // How are you?
println(l.GetWithLocale("es", "messages.hello_my_name_is", &localizations.Replacements{"name":"steve"})) // "Hola, mi nombre es steve"
With en
being the locale and es
being the fallback. The localization keys are worked out using folder structure, eg:
en/customer/messages.json
with the contents being:
{
"hello": "hello customer!"
}
You'll be able to access this using the key: customer.messages.hello
.
Suggestions
It is suggested to instead of using hardcoded locale keys i.e. en
to use the language keys included in key, i.e: language.BritishEnglish.String()
which is en-GB
Replacements
Take this replacement string for example:
hello_firstname_lastname: Hello {{.firstname}} {{.lastname}}
To then replace firstname
and the lastname
variable, you can use
something like this:
l := localizations.New("en", "es")
println(l.Get("hello_firstname_lastname", &localizations.Replacements{"firstname": "steve", "lastname": "steve"}))
You can also append numerous replacements if you have them like so:
println(l.Get("hello_firstname_lastname", &localizations.Replacements{"firstname": "steve"}, &localizations.Replacements{"lastname": "steve"}))
Locale defining and localization fallbacks
You can define the locale and fallbacks using:
l := localizations.New("en", "es")
Where en
is the locale and es
is the fallback. If no translation key-value is
found then the key will be returned. For example
println(l.Get("key_doesnt_exist")) //"key_doesnt_exist" will be printed
Translation file support
We currently support JSON and YAML translation files. Please suggest missing file type using issues or pull requests.
CLI
Instead of using go generate you can just generate the localizations manually using go-localize
:
Usage of go-localize:
-input string
input localizations folder
-output string
where to output the generated package