Александр Старочкин 7fdea619c4 add: cool banner | hai 10 meses | |
---|---|---|
src | hai 10 meses | |
tests | hai 10 meses | |
translations | hai 1 ano | |
.gitignore | %!s(int64=3) %!d(string=hai) anos | |
README.md | hai 10 meses | |
localize.nimble | hai 10 meses |
Localize your applications at compile-time
app.nim
import localize
requireLocalesToBeTranslated ("ru", "")
echo tr"Hello, world" # "Hello, world"
globalLocale = locale "ru"
echo tr"Hello, world" # "Привет, мир"
when isMainModule:
updateTranslations() # traslations is readed and updated when compiling
translations/ru.json
{
"app.nim": {
"Hello, world": {
"": "Привет, мир"
}
}
}
"it is working!".tr # same as "" context
"it is working!".tr("") # "оно работает!"
"it is working!".tr("code") # "он работает!"
{
"app.nim": {
"it is working!": {
"": "оно работает!",
"code": "он работает!"
}
}
}
tr is auto-calling fmt
let name = stdin.readline
echo tr"Hi, {name}"
{
"app.nim": {
"Hi, {name}": {
"": "Привет, {name}",
}
}
}
globalLocale[0] = systemLocale()
import json
globalLocale = (
("zh", ""),
parseLocaleTable %*{
"mypackage": {
"src/myapp.nim": {
"Hello, world": {
"": "你好,世界",
},
},
},
}
)