blumewas/laravel-locale-fallbacks

Opiniated variant on how localizations should be resolved

Maintainers

Package info

github.com/blumewas/laravel-locale-fallbacks

pkg:composer/blumewas/laravel-locale-fallbacks

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

dev-main 2026-01-12 18:55 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Opiniated variant on how localizations for an app should be loaded.

Installation

You can install the package via composer:

composer require blumewas/laravel-locale-fallbacks

You can publish the config file with:

php artisan vendor:publish --tag="laravel-locale-fallbacks-config"

This is the contents of the published config file:

return [
    /**
     * Define the fallback chain for each locale.
     * The keys are the locale codes, and the values are arrays of fallback locales.
     * For example, if 'de' falls back to 'en', you would set:
     * 'de' => ['en'].
     * This means that if a translation is not found in 'de', it will look for
     * the translation in 'en'.
     * You can define multiple fallbacks for a locale.
     * For example, 'de' => ['en', 'fr'] means it will first
     * try 'en', and if not found, it will try 'fr'.
     * A fallback chain is also composed. E.g. if 'de' falls back to 'en',
     * and 'de-DE' falls back to 'de', we will first try 'de-DE',
     * then 'de', and finally 'en'. This would be equivalent to:
     * 'de-DE' => ['de', 'en'],
     * 'de' => ['en'].
     */
    'fallbacks' => [
        'de' => ['en'],
    ],

    /**
     * Whether to automatically add two-letter language codes as fallbacks.
     * This is useful for apps that have regional variations of languages
     * (e.g., 'en-US' and 'en-GB') and want to ensure that
     * the two-letter code ('en') is always available as a fallback.
     */
    'autofallback_two_letter_codes' => true,
];

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.