module

Planeta::I18n

Internationalization and localization module for Planeta.

This module handles translation of UI elements, locale detection from various sources (environment, cookies, query parameters, browser headers), and provides thread-safe translation methods.

Constants

AVAILABLE_LOCALES = ["en", "es"]

List of available locales in the application.

DEFAULT_LOCALE = "en"

Default locale used when no other locale can be determined.

Class methods

all_authors(locale = @@locale) : String

Returns the label for 'All' authors.

Source
authors_label(locale = @@locale) : String

Returns the label for the authors section.

Source
detect_browser_locale(env : HTTP::Server::Context) : String | Nil

Detects the best matching locale from the browser's Accept-Language header.

Parses the header and compares against AVAILABLE_LOCALES.

Source
init_translations

Initializes translations by loading YAML files from i18n/ directory.

Should be called once during application startup.

Source
locale
Source
locale=(lang : String)

Sets the global default locale.

Validates that lang is in AVAILABLE_LOCALES, otherwise falls back to DEFAULT_LOCALE.

Source
locale_from_context(env : HTTP::Server::Context) : String

Determines the appropriate locale for the given request context.

Checks sources in order of precedence:

  1. Query parameter locale
  2. Cookie locale
  3. Browser Accept-Language headers
  4. Environment variable PLANETA_LOCALE
Source
locale_from_env

Returns the locale configured in the environment variable PLANETA_LOCALE.

Source
next(locale = @@locale) : String

Returns the 'Next' pagination label.

Source
no_entries(locale = @@locale) : String

Returns the message shown when no entries are found.

Source
page_of(page, total, count, feeds, locale = @@locale) : String

Returns the formatted pagination info string.

Source
powered_by(locale = @@locale) : String

Returns the 'Powered by' text.

Source
previous(locale = @@locale) : String

Returns the 'Previous' pagination label.

Source
read_more(locale = @@locale) : String

Returns the 'Read more' text.

Source
render_time(time_us : Int64, locale = @@locale) : String

Returns the formatted render time string.

Source
search_placeholder(locale = @@locale) : String

Returns the search placeholder text.

Source
t(key : String, locale = @@locale, **args) : String

Translates a key for the given locale.

Optionally replaces placeholders in the translation string with args. Falls back to DEFAULT_LOCALE if key is missing in locale.

Source