Александр Старочкин 7fdea619c4 add: cool banner | 10 months ago | |
---|---|---|
src | 10 months ago | |
tests | 10 months ago | |
translations | 1 year ago | |
.gitignore | 3 years ago | |
README.md | 10 months ago | |
localize.nimble | 10 months ago |
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": {
"": "你好,世界",
},
},
},
}
)