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