Language & Localization Class
The Language class is the core engine behind GeniXCMS's global reach. It manages Internationalization (i18n) and Localization (l10n) by handling locale detection, user preferences, and the dynamic rendering of multi-language content across the system.
⚡ Multilingual Orchestration
Language::isActive()
Detects the currently active 2-letter ISO language code (e.g., 'en', 'id', 'es').
- Logic: It prioritizes the URL locale parameter first, falling back to the session value, and finally the system default.
- Return:
string
Language::setActive(string $lang_code)
Programmatically forces the active language for the current browser session. Typically used when a user manually clicks a language flag.
🌎 Content Translation
GeniXCMS supports per-post translation by storing localized metadata in the postparam table.
Language::getLangParam(string $lang, int $post_id)
Retrieves translated block (Title or Body) for a specific post.
// Retrieve the Indonesian title for post ID 42
$translated_title = Language::getLangParam('id', 42);
🎨 UI Components & Locales
Language::flagList()
Generates a semantic HTML list (<ul>) of language switching flags.
- Automation: It automatically injects the necessary flag-icon-css library from its CDN into the page footer.
- Config: It pulls available languages from the
multilang_country system option.
// In your theme's header.php
<?= Language::flagList(); ?>
⚙️ Configuration Schema
The behavior of the Language engine is dictated by several global options found in the Settings Dashboard.
| Option Key |
Description |
multilang_enable |
Global toggle for translation features. |
multilang_default |
The primary ISO code for the website (e.g., en). |
multilang_country |
A JSON manifest mapping codes to display names and flag icons. |
🛠️ Translation Best Practices
- Shorthand: Use the global
_('Translation Key') function (aliased to Gettext) for system and theme messages.
- Post Translations: When creating content, ensure you use the Translate tab in the Post Editor to define version for each active locale.
- Assets: Theme-specific translations should be placed in
inc/themes/{your-theme}/inc/lang/.
lightbulbTipSEO Localization: The Language class integrates with the Router to support path-based locale detection (e.g., /en/post.html). Always ensure your theme's <html> tag uses lang="{$website_lang}" for correct search engine indexing.
See Also