english русский
Quick and easy localization of your Go projects!
This package is based on the go-l10n package created by iafan.
as simple as another packages:
go get github.com/xelaj/go-l10n
code examples are here
The main struct you will use is l10n.Pool
. on init func it takes filepath to
locale dirs, the name of your application and the main language into which you will translate
messages.
messages are taken from the directory that you specify during initialization. however, it must have certain structure:
locale
en_US
YourApp
locale.json
another folder
locale.json
third.json
info.cfg
ru_RU
YourApp
locale.json
another folder
locale.json
third.json
info.cfg
ua_UA
...
es_ES
...
info.cfg
is a summary of the locale. it is written to the l10n.Locale object. she keeps in
The following parameters:
# name of language on ascii
name = Russian
# localized name of language
translate = Russian
# which language it extends. if you have unsupported locale name, package returns key name
extends =
all three parameters are optional. however, the file itself in each folder with the same name is required.
YourApp
essentially implements the namespaces of various applications.
inside the directory of your application, you can do absolutely any structure of your files, the only important thing is that the names of the messages in all these files do not overlap. if that happens then The translation closest to the root directory will be selected.
each locale file is a json file with the following parameters:
{
"about": {
"message": "this is locale file!",
"description": "use this description to message message"
},
"hello text": {
"message": "hello!"
}
}
examples of file struvture can be seen here
Please read contributing guide if you want to help. And the help is very necessary!
- Igor Afanasyev — base library - iafan
- Richard Cooper — other stuff - ololosha228
This project is licensed under the MIT License - see the LICENSE.md file for details