{"id":13541403,"url":"https://github.com/spatie/laravel-translation-loader","last_synced_at":"2025-05-14T19:07:57.606Z","repository":{"id":11561740,"uuid":"70038687","full_name":"spatie/laravel-translation-loader","owner":"spatie","description":"Store your translations in the database or other sources","archived":false,"fork":false,"pushed_at":"2025-02-21T11:46:00.000Z","size":125,"stargazers_count":775,"open_issues_count":0,"forks_count":96,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-14T19:07:53.190Z","etag":null,"topics":["i18n","language","laravel","php","translation"],"latest_commit_sha":null,"homepage":"https://freek.dev/593-a-laravel-package-to-store-language-lines-in-the-database","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2016-10-05T07:28:35.000Z","updated_at":"2025-05-14T10:46:00.000Z","dependencies_parsed_at":"2024-11-10T02:07:19.542Z","dependency_job_id":"b02d4733-0746-4f32-8f3b-2457089a7fb3","html_url":"https://github.com/spatie/laravel-translation-loader","commit_stats":{"total_commits":146,"total_committers":31,"mean_commits":4.709677419354839,"dds":0.3904109589041096,"last_synced_commit":"b45980636d3d60a3426ac44f5a51517bca8cb63a"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translation-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translation-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translation-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translation-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-translation-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","language","laravel","php","translation"],"created_at":"2024-08-01T10:00:46.647Z","updated_at":"2025-05-14T19:07:56.564Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://spatie.be/open-source/support-us"],"categories":["Popular Packages"],"sub_categories":[],"readme":"# Store your language lines in the database\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-translation-loader.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-translation-loader)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-translation-loader/run-tests.yml?branch=main\u0026label=Tests\u0026style=flat-square)](https://github.com/spatie/laravel-translation-loader/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-translation-loader.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-translation-loader)\n\nIn a vanilla Laravel or Lumen installation, you can use [language files](https://laravel.com/docs/localization) to\nlocalize your app. This package will enable the translations to be stored in the database. You can still use all the\nfeatures of [the `__` helper function](https://laravel.com/docs/localization#retrieving-translation-strings) you know\nand love.\n\n```php\n__('messages.welcome', ['name' =\u003e 'dayle']);\n```\n\nYou can even mix using language files and the database. If a translation is present in both a file and the database, the\ndatabase version will be returned.\n\nWant to use a different source for your translations? No problem! The package\nis [easily extendable](https://github.com/spatie/laravel-translation-loader#creating-your-own-translation-providers).\n\nSpatie is a web design agency based in Antwerp, Belgium.\nYou'll find an overview of all our open source\nprojects [on our website](https://spatie.be/opensource).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-translation-loader.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-translation-loader)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can\nsupport us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\nYou'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards\non [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require spatie/laravel-translation-loader\n```\n\nIn `config/app.php` (Laravel) or `bootstrap/app.php` (Lumen) you should replace Laravel's translation service provider\n\n```php\nIlluminate\\Translation\\TranslationServiceProvider::class,\n```\n\nby the one included in this package:\n\n```php\nSpatie\\TranslationLoader\\TranslationServiceProvider::class,\n```\n\nYou must publish and run the migrations to create the `language_lines` table:\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\TranslationLoader\\TranslationServiceProvider\" --tag=\"translation-loader-migrations\"\nphp artisan migrate\n```\n\nOptionally, you could publish the config file using this command.\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\TranslationLoader\\TranslationServiceProvider\" --tag=\"translation-loader-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n\n    /*\n     * Language lines will be fetched by these loaders. You can put any class here that implements\n     * the Spatie\\TranslationLoader\\TranslationLoaders\\TranslationLoader-interface.\n     */\n    'translation_loaders' =\u003e [\n        Spatie\\TranslationLoader\\TranslationLoaders\\Db::class,\n    ],\n\n    /*\n     * This is the model used by the Db Translation loader. You can put any model here\n     * that extends Spatie\\TranslationLoader\\LanguageLine.\n     */\n    'model' =\u003e Spatie\\TranslationLoader\\LanguageLine::class,\n\n    /*\n     * This is the translation manager that overrides the default Laravel `translation.loader`\n     */\n    'translation_manager' =\u003e Spatie\\TranslationLoader\\TranslationLoaderManager::class,\n\n];\n```\n\n\u003e **Note:** publishing assets doesn't work out of the box in Lumen. Instead, you have to copy the files from the repo.\n\n## Usage\n\nYou can create a translation in the database by creating and saving an instance of\nthe `Spatie\\TranslationLoader\\LanguageLine`-model:\n\n```php\nuse Spatie\\TranslationLoader\\LanguageLine;\n\nLanguageLine::create([\n   'group' =\u003e 'validation',\n   'key' =\u003e 'required',\n   'text' =\u003e ['en' =\u003e 'This is a required field', 'nl' =\u003e 'Dit is een verplicht veld'],\n]);\n```\n\nYou can fetch the translation\nwith [Laravel's default `__` function](https://laravel.com/docs/localization#retrieving-translation-strings):\n\n```php\n__('validation.required'); // returns 'This is a required field'\n\napp()-\u003esetLocale('nl');\n\n__('validation.required'); // returns 'Dit is een verplicht veld'\n```\n\nYou can still keep using the default language files as well. If a requested translation is present in both the database\nand the language files, the database version will be returned.\n\nIf you need to store/override JSON translation lines, just create a normal LanguageLine with `group =\u003e '*'`.\n\n## Creating your own translation providers\n\nThis package ships with a translation provider that can fetch translations from the database.\nIf you're storing your translations in a yaml-file, a csv-file, etc.,\nyou can easily extend this package by creating your own translation provider.\n\nA translation provider can be any class that implements\nthe `Spatie\\TranslationLoader\\TranslationLoaders\\TranslationLoader`-interface. It contains only one method:\n\n```php\nnamespace Spatie\\TranslationLoader\\TranslationLoaders;\n\ninterface TranslationLoader\n{\n    /*\n     * Returns all translations for the given locale and group.\n     */\n    public function loadTranslations(string $locale, string $group): array;\n}\n```\n\nTranslation providers can be registered in the `translation_loaders` key of the config file.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security, please mail [security@spatie.be](mailto:security@spatie.be) instead of using\nthe issue tracker.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-translation-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-translation-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-translation-loader/lists"}