src/happyx/spa/translatable

Search:
Group by:

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 lang is unknown than used "My own string"
  "My own string":
    "ru" -> "Моя собствСнная строка"
    "fr" -> "..."
macro translate(self: string): string
Translates self string to current client language (SPA) or accept-language header (SSG/SSR)