{"id":19722960,"url":"https://github.com/translation/laravel","last_synced_at":"2025-05-15T12:04:41.807Z","repository":{"id":25703850,"uuid":"104565097","full_name":"translation/laravel","owner":"translation","description":"Laravel translation made __('simple').","archived":false,"fork":false,"pushed_at":"2025-02-25T16:58:39.000Z","size":258,"stargazers_count":170,"open_issues_count":5,"forks_count":22,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-11T21:48:58.331Z","etag":null,"topics":["gettext","i18n","laravel-5-package","laravel-6-package","laravel-localization","laravel-package","laravel-php","localization","php","translation"],"latest_commit_sha":null,"homepage":"https://translation.io/laravel","language":"PHP","has_issues":true,"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/translation.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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}},"created_at":"2017-09-23T12:14:36.000Z","updated_at":"2025-03-31T10:58:54.000Z","dependencies_parsed_at":"2024-01-15T18:46:07.506Z","dependency_job_id":"4139a0d1-281e-4654-9fc9-69515a34142e","html_url":"https://github.com/translation/laravel","commit_stats":{"total_commits":190,"total_committers":5,"mean_commits":38.0,"dds":"0.10526315789473684","last_synced_commit":"2f20274be2d78188f03d89ce19b94350be5fa167"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/translation%2Flaravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/translation%2Flaravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/translation%2Flaravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/translation%2Flaravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/translation","download_url":"https://codeload.github.com/translation/laravel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253938675,"owners_count":21987404,"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":["gettext","i18n","laravel-5-package","laravel-6-package","laravel-localization","laravel-package","laravel-php","localization","php","translation"],"created_at":"2024-11-11T23:19:06.078Z","updated_at":"2025-05-15T12:04:36.784Z","avatar_url":"https://github.com/translation.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Development Tools"],"readme":"# [Translation.io](https://translation.io/laravel) client for Laravel 5.5+ to 12.x\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Build Status](https://github.com/translation/laravel/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/translation/laravel/actions/workflows/test.yml)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/552e1ddc3f3f604d4908/test_coverage)](https://codeclimate.com/github/translation/laravel/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/552e1ddc3f3f604d4908/maintainability)](https://codeclimate.com/github/translation/laravel/maintainability)\n[![Package Version](https://img.shields.io/packagist/v/tio/laravel?style=flat-square)](https://packagist.org/packages/tio/laravel)\n[![Downloads](https://img.shields.io/packagist/dt/tio/laravel.svg?style=flat-square)](https://packagist.org/packages/tio/laravel)\n\nAdd this package to localize your **Laravel** application.\n\nUse the official Laravel syntax (with [PHP](#laravel-localization-php-keyvalues) or [JSON](#laravel-localization-json-source-text) files),\nor use the [GetText](#gettext) syntax.\n\nWrite only the source text, and keep it synchronized with your translators on [Translation.io](https://translation.io/laravel).\n\n\u003ca href=\"https://translation.io/laravel\"\u003e\n  \u003cimg width=\"720px\" alt=\"Translation.io interface\" src=\"https://translation.io/gifs/translation.gif\"\u003e\n\u003c/a\u003e\n\n[Technical Demo](https://translation.io/videos/laravel.mp4) (2.5min)\n\nNeed help? [contact@translation.io](mailto:contact@translation.io)\n\n## Table of contents\n\n * [Localization syntaxes](#localization-syntaxes)\n   * [Laravel Localization (PHP key/values)](#laravel-localization-php-keyvalues)\n   * [Laravel Localization (JSON source text)](#laravel-localization-json-source-text)\n   * [GetText](#gettext)\n * [Installation](#installation)\n * [Usage](#usage)\n   * [Sync](#sync)\n   * [Sync and Show Purgeable](#sync-and-show-purgeable)\n   * [Sync and Purge](#sync-and-purge)\n * [Manage Languages](#manage-languages)\n   * [Add or Remove Language](#add-or-remove-language)\n   * [Edit Language](#edit-language)\n   * [Custom Languages](#custom-languages)\n * [Change the current locale](#change-the-current-locale)\n   * [Globally](#globally)\n   * [Locally](#locally)\n * [Frontend Localization](#frontend-localization)\n   * [Using this package](#using-this-package)\n   * [Using our official React \u0026 JavaScript package](#using-our-official-react--javascript-package)\n * [Advanced Configuration Options](#advanced-configuration-options)\n   * [Ignored PHP keys](#ignored-php-keys)\n * [Testing](#testing)\n * [Contributing](#contributing)\n * [List of clients for Translation.io](#list-of-clients-for-translationio)\n   * [Ruby on Rails (Ruby)](#ruby-on-rails-ruby)\n   * [Laravel (PHP)](#laravel-php)\n   * [React, React Native and JavaScript](#react-react-native-and-javascript)\n   * [Angular](#angular)\n   * [Others](#others)\n * [License](#license)\n\n## Localization syntaxes\n\n### Laravel Localization (PHP key/values)\n\nThe [default Laravel method to localize](https://laravel.com/docs/master/localization#using-short-keys).\n\n~~~php\n// Regular\n__('inbox.title');\n\n// Regular with sublevel key\n__('inbox.menu.title');\n\n// Pluralization\ntrans_choice('inbox.messages', $number);\n\n// Interpolation\n__('inbox.hello', ['name' =\u003e $user-\u003ename]);\n~~~\n\nWith the PHP file `lang/en/inbox.php`:\n\n~~~php\n\u003c?php\nreturn [\n    'title' =\u003e 'Title to be translated',\n    'hello' =\u003e 'Hello :name',\n    'messages' =\u003e 'One message|Many messages',\n    'menu' =\u003e [\n        'title' =\u003e 'Title of menu'\n    ]\n];\n~~~\n\nNotes:\n\n * `trans` can also be used instead of `__`.\n * You can organize your PHP files with subfolders like `en/subfolder/inbox.php` using keys like `subfolder/inbox.title`.\n\n### Laravel Localization (JSON source text)\n\n[A new feature](https://laravel.com/docs/5.4/localization#using-translation-strings-as-keys) of Laravel 5.4\nis the possibility to use `__` with the source text (and not only with keys like in the previous section).\n\nThese translations are stored into JSON files located in the `lang` directory.\n\n~~~php\n// Regular\n__(\"Text to be translated\");\n\n// Pluralization\ntrans_choice(__('One message|Many messages'), $number);\n\n// Interpolation\n__('Hello :name', ['name' =\u003e $user-\u003ename]);\n~~~\n\nWith the JSON file `lang/en.json`:\n\n~~~json\n{\n    \"Text to be translated\": \"\",\n    \"One message|Many messages\": \"\",\n    \"Hello :name\": \"\"\n}\n~~~\n\nNotes: \n\n * To spend less time dealing with multiple JSON files, we advise to only edit\nthe original language (usually `en.json`) to add new strings, and leave the\ntranslations empty. During a [sync](#sync), This package will automatically \ncreate and fill the JSON files of the target languages.\n\n * If you want to organize your JSON files by feature, you can register\nnew paths in `AppServiceProvider` like this:\n\n~~~php\npublic function boot()\n{\n    $loader = $this-\u003eapp['translation.loader'];\n\n    // or 'resources/lang/my_feature' in Laravel \u003c 9\n    $loader-\u003eaddJsonPath(base_path('lang/my_feature')); \n}\n~~~\n\n### GetText\n\nThis package adds the GetText support to Laravel. We [strongly suggest](https://translation.io/blog/gettext-is-better-than-rails-i18n)\nthat you use GetText to localize your application since it allows an easier and more complete syntax.\n\nMoreover, you won't need to create and manage any PHP or JSON file since your code will be\nautomatically scanned for any string to translate.\n\n~~~php\n// Regular\nt(\"Text to be translated\");\n\n// Pluralization\nn(\"Singular text\", \"Plural text\", $number);\n\n// Regular with context\np(\"context\", \"Text to be translated\");\n\n// Pluralization with context\nnp(\"context\", \"Singular text\", \"Plural text\", $number);\n\n// Simple Interpolations (works with n, p and np too)\nt('Hello %s', $user-\u003ename);\n\n// Complex Interpolations (works with n, p and np too)\nt(':city1 is bigger than :city2', [ ':city1' =\u003e 'NYC', ':city2' =\u003e 'BXL' ]);\n~~~\n\n## Installation\n\n 1. Add the package via Composer:\n\n~~~bash\ncomposer require tio/laravel\n~~~\n\n 2. Create a new translation project [from the UI](https://translation.io/laravel).\n 3. Copy the initializer into your Laravel app (`config/translation.php`) or execute `php artisan vendor:publish`.\n\nThe initializer looks like this:\n\n~~~php\n\u003c?php\nreturn [\n    'key' =\u003e env('TRANSLATIONIO_KEY'),\n    'source_locale' =\u003e 'en',\n    'target_locales' =\u003e ['fr', 'nl', 'de', 'es']\n];\n~~~\n\n 4. Add the API key (`TRANSLATIONIO_KEY`) in your `.env` file.\n 5. Initialize your project and push existing translations to Translation.io with:\n\n~~~bash\nphp artisan translation:init\n~~~\n\nNote: since **Laravel 9**, the `lang` directory and the default set of language files\nused by Laravel are **not** included by default in new projects\n(see [official documentation](https://laravel.com/docs/master/localization#publishing-the-language-files)),\nso you may need to run the `lang:publish` command to generate them:\n\n~~~bash\nphp artisan lang:publish\n~~~\n\n\nIf you need to add or remove languages in the future, please read\n[this section](#add-or-remove-language) about that.\n\n## Usage\n\n### Sync\n\nTo send new translatable keys/strings and get new translations from Translation.io, simply run:\n\n~~~bash\nphp artisan translation:sync\n~~~\n\n### Sync and Show Purgeable\n\nIf you need to find out what are the unused keys/strings from Translation.io, using the current branch as reference:\n\n~~~bash\nphp artisan translation:sync_and_show_purgeable\n~~~\n\nAs the name says, this operation will also perform a sync at the same time.\n\n### Sync and Purge\n\nIf you need to remove unused keys/strings from Translation.io, using the current branch as reference:\n\n~~~bash\nphp artisan translation:sync_and_purge\n~~~\n\nAs the name says, this operation will also perform a sync at the same time.\n\nWarning: all keys that are not present in the current local branch\nwill be **permanently deleted from Translation.io**.\n\n## Manage Languages\n\n### Add or Remove Language\n\nYou can add or remove a language by updating `'target_locales' =\u003e []` in your\n`config/translation.php` file, and executing `php artisan translation:sync`.\n\nIf you want to add a new language with existing translations (ex. if you already have\na translated PHP file in your `lang` directory), you will need to create a new project on\nTranslation.io and run `php artisan translation:init` for them to appear.\n\n### Edit Language\n\nTo edit existing languages while keeping their translations (e.g. changing from `en` to `en-US`).\n\n 1. Create a new project on Translation.io with the correct languages.\n 2. Adapt `config/translation.php` (new API key and languages)\n 3. Adapt directory language names in `lang` or `resources/lang` (optional: adapt GetText `.po` headers)\n 4. Execute `php artisan translation:init` and check that everything went fine.\n 5. Invite your collaborators in the new project.\n 6. Remove the old project.\n\nSince you created a new project, the translation history and tags will unfortunately be lost.\n\n### Custom Languages\n\nA custom language is always derived from an existing language. It's useful if you want\nto adapt some translations to another instance of your application, or to a specific\ncustomer.\n\nThe structure of a custom language is: `existing language code` + `-` + `custom text`, where\n`custom text` can only contain alphanumeric characters and `-`.\n\nExamples: `en-microsoft` or `fr-BE-custom`.\n\nCustom languages can be added and used like any other language.\n\n## Change the current locale\n\n### Globally\n\nThe easiest way to change the current locale is with the `set.locale` Middleware.\n\n~~~php\n// in routes/web.php\n\n// Solution 1: Apply the locale selection to root.\n//             =\u003e https://yourdomain.com?locale=fr\nRoute::get('/', function () {\n    return view('welcome');\n})-\u003emiddleware('set.locale');\n\n// Solution 2: Apply the locale selection to many routes.\n//             =\u003e https://yourdomain.com/...?locale=fr\nRoute::middleware('set.locale')-\u003egroup(function () {\n    Route::get('/', function () {\n        return view('welcome');\n    });\n});\n\n// Solution 3: prefix your routes with the locale and apply it.\n//             =\u003e https://yourdomain.com/fr\n//             =\u003e https://yourdomain.com/fr/...\nRoute::prefix('{locale?}')-\u003emiddleware('set.locale')-\u003egroup(function() {\n    Route::get('/', function () {\n        return view('welcome');\n    });\n});\n~~~\n\nFirst time the user will connect, it will automatically set the locale extracted\nfrom the browser `HTTP_ACCEPT_LANGUAGE` value, and keep it in the session between\nrequests.\n\nThe `set.locale` Middleware code is [here](https://github.com/translation/laravel/blob/master/src/Middleware/SetLocaleMiddleware.php),\nfeel free to adapt it with your own locale management.\n\n### Locally\n\nChange the current locale with:\n\n~~~php\nuse Tio\\Laravel\\Facade as Translation;\n\nTranslation::setLocale('fr');\n~~~\n\n## Frontend Localization\n\n### Using this Package\n\nThis package is also able to cover frontend localization (React, Vue, ...).\n\nThere are several ways to pass the translation strings from the backend\nto the frontend: JavaScript serialization, `data-` HTML attributes, JSON files etc.\n\nThe easiest strategy when dealing with React/Vue would be to pass the corresponding\ntranslations as props when mounting the components.\n\n**Notes:**\n\n * You can structure the i18n props with multiple levels of depth and pass the subtree as props to each of your sub-components.\n * It also works great with server-side rendering of your components.\n\n### Using our official React \u0026 JavaScript package\n\nAs Translation.io is directly integrated in the great\n[Lingui](https://lingui.dev/) internationalization framework,\nyou can also consider frontend localization as a completely different\nlocalization project.\n\nPlease read more about this on:\n\n * Website: [https://translation.io/lingui](https://translation.io/lingui)\n * GitHub page: [https://github.com/translation/lingui](https://github.com/translation/lingui)\n\n## Advanced Configuration Options\n\nThe `config/translation.php` file can take several optional configuration options.\n\nSome options are described below but for an exhaustive list, please refer to\n[translation.php](https://github.com/translation/laravel/blob/master/config/translation.php).\n\n### Ignored PHP keys\n\nIf you would like to ignore specific PHP keys, or even entire PHP files or\nsubdirectories from the source language, you can use the `ignored_key_prefixes` option.\n\nFor example:\n\n~~~php\n\u003c?php\nreturn [\n    ...\n    'ignored_key_prefixes' =\u003e [\n        'validation',        // ignore the whole validation.php file.\n        'validation.custom', // ignore the \"custom\" subtree in validation.php file.\n        'subfolder/more',    // ignore the whole subfolder/more.php file.\n    ],\n    ...\n];\n~~~\n\n## Testing\n\nTo run the specs with oldest dependencies:\n\n~~~bash\ncomposer update --no-interaction --prefer-stable --prefer-lowest\n./vendor/bin/phpunit\n~~~\n\nTo run the specs with latest dependencies:\n\n~~~bash\ncomposer update --no-interaction --prefer-stable\n./vendor/bin/phpunit\n~~~\n\n## Contributing\n\nPlease read the [CONTRIBUTING](CONTRIBUTING.md) file.\n\n## List of clients for Translation.io\n\nThe following clients are officially supported by [Translation.io](https://translation.io)\nand are well documented.\n\nSome of these implementations (and other non-officially supported ones)\nwere started by contributors for their own translation projects.\nWe are thankful to all contributors for their hard work!\n\n### Ruby on Rails (Ruby)\n\nOfficially supported on [https://translation.io/rails](https://translation.io/rails)\n\n * GitHub: https://github.com/translation/rails\n * RubyGems: https://rubygems.org/gems/translation/\n\nCredits: [@aurels](https://github.com/aurels), [@michaelhoste](https://github.com/michaelhoste)\n\n### Laravel (PHP)\n\nOfficially supported on [https://translation.io/laravel](https://translation.io/laravel)\n\n * GitHub: https://github.com/translation/laravel\n * Packagist: https://packagist.org/packages/tio/laravel\n\nCredits: [@armandsar](https://github.com/armandsar), [@michaelhoste](https://github.com/michaelhoste)\n\n### React, React Native and JavaScript\n\nOfficially supported on [https://translation.io/lingui](https://translation.io/lingui)\n\nTranslation.io is directly integrated in the great\n[Lingui](https://lingui.dev/) internationalization project.\n\n * GitHub: https://github.com/translation/lingui\n * NPM: https://www.npmjs.com/package/@translation/lingui\n\n### Angular\n\nOfficially supported on [https://translation.io/angular](https://translation.io/angular)\n\n * GitHub: https://github.com/translation/angular\n * NPM: https://www.npmjs.com/package/@translation/angular\n \nCredits: [@SimonCorellia](https://github.com/SimonCorellia), [@didier-84](https://github.com/didier-84), [@michaelhoste](https://github.com/michaelhoste)\n\n### Others\n\nIf you want to create a new client for your favorite language or framework, please read our\n[Create a Translation.io Library](https://translation.io/docs/create-library)\nguide and use the special\n[init](https://translation.io/docs/create-library#initialization) and\n[sync](https://translation.io/docs/create-library#synchronization) endpoints.\n\nYou can also use the more [traditional API](https://translation.io/docs/api).\n\nFeel free to contact us on [contact@translation.io](mailto:contact@translation.io)\nif you need some help or if you want to share your library.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftranslation%2Flaravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftranslation%2Flaravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftranslation%2Flaravel/lists"}