Skip to content

Latest commit

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation


A simple i18n library for Nim

nimble install oris

API reference
Github ActionsGithub Actions

😍 Key Features

  • Simple, macro-based interface
  • Switch between languages at runtime
  • Support for pluralization
  • Support for interpolation of variables in translations
  • Encode/Decode language data to/from disk using FastBinaryEncoding (FBE)

Examples

This example shows how to define multiple languages, retrieve translations with interpolation, and serialize/deserialize language data using FastBinaryEncoding (FBE) format via pkg/openparser.

import pkg/oris
var i18n =newOris(default ="en")
# Define English languagenewLanguage i18n, "en":
welcome: "Welcome to Oris!"
welcome_message: "Your Oris instance is now live. You have $count new messages."
dashboard_title: "Dashboard"
dashboard_description: "This is your Oris dashboard where you can manage your projects, settings, and more."
greeting_user: "Hello, $name! Welcome back."animalsdo(dogs: int, cats: int):
result="$dogs and $cats"case dogs:
 of1: "one dog"else: "$dogs dogs"case cats:
 of1: "one cat"else: "$cats cats"# Define Spanish languagenewLanguage i18n, "es":
welcome: "¡Bienvenido a Oris!"
welcome_message: "Tu instancia de Oris ya está en vivo. Tienes $count nuevos mensajes."
dashboard_title: "Panel de Control"
dashboard_description: "Este es tu panel de control de Oris donde puedes administrar tus proyectos, configuraciones y más."
greeting_user: "¡Hola, $name! Bienvenido de nuevo."animalsdo(dogs: int, cats: int):
result="$dogs y $cats"case dogs:
 of1: "un perro"else: "$dogs perros"case cats:
 of1: "un gato"else: "$cats gatos"# Showcase translations in the default language ("en")echo i18n.translate("welcome")
# "Welcome to Oris!"echo i18n.translate("welcome_message", ["3"])
# "Your Oris instance is now live. You have 3 new messages."echo i18n.translate("greeting_user", @["Alice"])
# "Hello, Alice! Welcome back."echo i18n.translate("animals", [("dogs", 2), ("cats", 1)])
# "2 dogs and one cat"# Showcase translations in Spanish ("es")echo i18n.translate("es", "welcome")
# "¡Bienvenido a Oris!"echo i18n.translate("es", "welcome_message", ["5"])
# "Tu instancia de Oris ya está en vivo. Tienes 5 nuevos mensajes."echo i18n.translate("es", "greeting_user", @["Carlos"])
# "¡Hola, Carlos! Bienvenido de nuevo."echo i18n.translate("es", "animals", [("dogs", 1), ("cats", 3)])
# "un perro y 3 gatos"

Encode and Decode language data

Encode language data to disk using FBE format and decode it back to verify that translations are preserved correctly

# Encode the English language to disk using FastBinaryEncoding (FBE) format
i18n.languages["en"].encode("en.fbe")
# Decode the language from disk and verify translationsvar enDecoded: Language
enDecoded.decode("en.fbe")
# Verify translations from the decoded languageecho enDecoded.translate("welcome")
# "Welcome to Oris!"echo enDecoded.translate("welcome_message", ["2"])
# "Your Oris instance is now live. You have 2 new messages."echo enDecoded.translate("animals", [("dogs", 1), ("cats", 2)])
# "one dog and 2 cats"# Encode the Spanish language to disk
i18n.languages["es"].encode("es.fbe")
# Decode the Spanish language from disk and verify translationsvar esDecoded: Language
esDecoded.decode("es.fbe")
# Verify translations from the decoded Spanish languageecho esDecoded.translate("welcome")
# "¡Bienvenido a Oris!"echo esDecoded.translate("welcome_message", ["4"])
# "Tu instancia de Oris ya está en vivo. Tienes 4 nuevos mensajes."echo esDecoded.translate("animals", [("dogs", 3), ("cats", 1)])
# "3 perros y un gato"

Other serialization formats

You can use pkg/openparser/json(with/without pkg/openparser/bson), pkg/jsony, pkg/flatty to encode/decode Language data to/from JSON, JSONY, or binary formats as well.

Inspiration

Inspired by other i18n libraries from Nim community:

❤ Contributions & Support

🎩 License

MIT license. Made by Humans from OpenPeeps.
Copyright © 2026 OpenPeeps & Contributors — All rights reserved.

Releases

Packages

Used by

Contributors

Languages

Generated from openpeeps/pistachio