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.
Sourceauthors_label(locale = @@locale) :
String Returns the label for the authors section.
SourceDetects the best matching locale from the browser's Accept-Language header.
Parses the header and compares against AVAILABLE_LOCALES.
Sourceinit_translations
Initializes translations by loading YAML files from i18n/ directory.
Should be called once during application startup.
SourceSets the global default locale.
Validates that lang is in AVAILABLE_LOCALES, otherwise falls back
to DEFAULT_LOCALE.
SourceDetermines the appropriate locale for the given request context.
Checks sources in order of precedence:
- Query parameter
locale
- Cookie
locale
- Browser
Accept-Language headers
- Environment variable
PLANETA_LOCALE
Sourcelocale_from_env
Returns the locale configured in the environment variable PLANETA_LOCALE.
Sourcenext(locale = @@locale) :
String Returns the 'Next' pagination label.
Sourceno_entries(locale = @@locale) :
String Returns the message shown when no entries are found.
Sourcepage_of(page, total, count, feeds, locale = @@locale) :
String Returns the formatted pagination info string.
Sourcepowered_by(locale = @@locale) :
String Returns the 'Powered by' text.
Sourceprevious(locale = @@locale) :
String Returns the 'Previous' pagination label.
Sourceread_more(locale = @@locale) :
String Returns the 'Read more' text.
Sourcerender_time(time_us :
Int64, locale = @@locale) :
String Returns the formatted render time string.
Sourcesearch_placeholder(locale = @@locale) :
String Returns the search placeholder text.
SourceReturns the label for the language switch link.
SourceTranslates 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