gettext/languages
Auto-generated language and plural-rule data from CLDR for gettext. Includes a CLI (export-plural-rules) to export rules for selected locales, with options like ASCII-only and deduping, and output formats such as JSON, PHP, Ruby, HTML, and XML.
Install via Composer: composer require gettext/languages. Start with static exports for performance—run vendor/bin/export-plural-rules php --output=lang_data.php during build/deploy. In code, include it: $langs = include 'lang_data.php';. For quick prototyping, use dynamic loading: Language::getById('fr_FR') returns a rich Gettext\Languages\Language object with id, name, formula, and categories.
export-plural-rules php) to avoid runtime overhead in production. Useful for CLI tools, CMS plugins, or localization scaffolding.Language::getAll() to populate language dropdowns with full metadata (e.g., territory, script) for UIs. Filter by base language via baseLanguage or territory for smart defaults.formula and categories into custom pluralization engines (e.g., for JS or custom i18n libraries). The package supplies exact CLDR-derived plural forms—critical for accurate messaging like “1 item” vs “0 items”..po headers (export-plural-rules po --language=es) to auto-generate header templates for translation workflows (e.g., Poedit, Weblate).export-plural-rules in deployment scripts—use --reduce=yes to trim redundant variants (e.g., omit nl_BE when nl suffices) or --us-ascii for environments with encoding constraints.--parenthesis=yes is essential—omit it for non-PHP targets (e.g., Ruby, JS) where associativity differs. Always double-check generated formulas if embedding into other languages.GettextLanguages\*; modern versions use Gettext\Languages\*. Update imports if upgrading from legacy code.getById('en-us') and getById('en_US') are both accepted and normalized to en_US—safe for user input but confirm case consistency in stored IDs.getAll() hydrates all 300+ languages; cache or pre-filter in production. Use getById() or static exports for better scalability.supersededBy when processing legacy locale IDs (e.g., jw → jv). Handle gracefully to avoid missing translations.How can I help you explore Laravel packages today?