Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Languages Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Build-time data generation: Embed generated PHP files (export-plural-rules php) to avoid runtime overhead in production. Useful for CLI tools, CMS plugins, or localization scaffolding.
  • Dynamic locale selection: Use 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.
  • Plural rule integration: Feed 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”.
  • Legacy systems: Export .po headers (export-plural-rules po --language=es) to auto-generate header templates for translation workflows (e.g., Poedit, Weblate).
  • CLI tooling: Wrap 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.

Gotchas and Tips

  • PHP ternary precedence: The default --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.
  • Namespace change: Prior to v2.0, used GettextLanguages\*; modern versions use Gettext\Languages\*. Update imports if upgrading from legacy code.
  • Locale normalization: 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.
  • CLDR drift: Re-run exports periodically (e.g., via CI). Major CLDR upgrades (e.g., v46→v47) can alter plural rules (Italian, Spanish, etc.); test plural behavior post-update.
  • Performance caveat: getAll() hydrates all 300+ languages; cache or pre-filter in production. Use getById() or static exports for better scalability.
  • Superseded codes: Check supersededBy when processing legacy locale IDs (e.g., jwjv). Handle gracefully to avoid missing translations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests