Translatable strings ✨
Provides DSL for autotranslatable strings
With this module you can easily write multilanguage programs!
Minimal Example 👨🔬
translable: "Hello, world!": # "Hello, world!" by default "ru" -> "Привет, мир!" "fr" -> "Bonjour, monde!" serve("127.0.0.1", 5000): get "/": return translate("Hello, world!")
Types
LanguageSettings = object lang*: string
Macros
macro translatable(body: untyped): untyped
-
Make translations for strings
Use standalone file with your translations for good practice.
Example
translatable: # If language is unknown than "default" key. # if it does not exists than used "My own string" "My own string": "default" -> "this you can see by default" "ru" -> "Моя собственная строка" "fr" -> "..."
macro translate(self: string; variables: varargs[string]): string
-
Translates self string to current client language (SPA) or accept-language header (SSG/SSR)Note: in JS backend this works like procedure calling.
Example
translatable: "hello_world": "default" -> "Hello, $1th world!" "ru" -> "Привет, $1ый мир!" echo translate("hello_world", "10") # Hello, 10th world!
Templates
template i18n(body: untyped): untyped
- Shorthand for translatable macro