{"id":21557034,"url":"https://github.com/josephnc/translation","last_synced_at":"2026-05-22T05:05:22.119Z","repository":{"id":57001713,"uuid":"197909149","full_name":"JosephNC/translation","owner":"JosephNC","description":"The fastest automatic translator for Laravel 5","archived":false,"fork":false,"pushed_at":"2019-08-23T20:38:36.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T10:32:39.281Z","etag":null,"topics":["automatic-translation","google-translate-api","laravel","laravel-5-package","php-framework","php7","translation"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JosephNC.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-20T09:31:46.000Z","updated_at":"2020-05-19T01:50:18.000Z","dependencies_parsed_at":"2022-08-21T12:10:40.525Z","dependency_job_id":null,"html_url":"https://github.com/JosephNC/translation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephNC%2Ftranslation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephNC%2Ftranslation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephNC%2Ftranslation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephNC%2Ftranslation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JosephNC","download_url":"https://codeload.github.com/JosephNC/translation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244148378,"owners_count":20406170,"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":["automatic-translation","google-translate-api","laravel","laravel-5-package","php-framework","php7","translation"],"created_at":"2024-11-24T08:10:43.555Z","updated_at":"2026-05-22T05:05:17.087Z","avatar_url":"https://github.com/JosephNC.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Translation\n\n[![Travis CI](https://img.shields.io/travis/josephnc/translation.svg?style=flat-square)](https://travis-ci.org/josephnc/translation)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/josephnc/translation.svg?style=flat-square)](https://scrutinizer-ci.com/g/josephnc/translation/?branch=master)\n[![License](https://img.shields.io/packagist/l/josephnc/translation.svg?style=flat-square)](https://packagist.org/packages/josephnc/translation)\n\n## Description\n\nForked and updated from https://github.com/stevebauman/translation \u003cbr\u003e\n\nNow the fastest automatic translator for laravel 5\n\nFor example:\n\nController:\n```php\npublic function index()\n{\n    return view('home.index');\n}\n```\n\nView:\n\n```php\n@extends('layout.default')\n\n{{ ___trans('Welcome to our home page') }}\n```\n\nSeen:\n\n    Welcome to our home page\n\nWhen you visit the page, you won't notice anything different, but if you take a look at your database, your default\napplication locale has already been created, and the translation attached to that locale.\n\nNow if we set locale to something different, such as French (fr), it'll automatically translate it for you.\n\nController:\n\n```php\npublic function index()\n{\n    App::setLocale('fr');\n\n    // Or Translation::setLocale( 'fr' );\n\n    return view('home.index');\n}\n```\n\nView:\n\n```php\n@extends('layout.default')\n\n{{ __trans('Welcome to our home page') }}\n```\n\nSeen:\n\n    Bienvenue sur notre page d'accueil\n\nWe can even use placeholders for dynamic content:\n\nView:\n```php\n{{ __trans('Welcome :name, to our home page', ['name' =\u003e 'John']) }}\n```\n\nSeen:\n\n    Bienvenue John , à notre page d'accueil\n\nNotice that we didn't actually change the text inside the view, which means everything stays completely readable in your\nlocale to you (the developer!), which means no more managing tons of translation files and trying to decipher what text may be inside that dot-notated translation\npath:\n    \n## Installation\n\nRequire the translation package \n\n    composer require josephnc/translation\n\nAdd the service provider to your `config/app.php` config file\n\n```php\nJosephNC\\Translation\\TranslationServiceProvider::class,\n```\n\nAdd the facade to your aliases in your `config/app.php` config file\n\n```php\n'Translation' =\u003e JosephNC\\Translation\\Facades\\Translation::class,\n```\n\nPublish the migrations\n\n    php artisan vendor:publish --provider=\"JosephNC\\Translation\\TranslationServiceProvider\"\n    \nRun the migrations\n\n    php artisan migrate\n\nYour good to go!\n\n## Usage\n\nAnywhere in your application, either use the the shorthand function (can be disabled in config file)\n\n```php\n__trans('Translate')\n```\n\nOr\n\n```php\nTranslation::translate('Translate')\n```\n\nThis is typically most useful in blade views:\n\n```php\n{{ __trans('Translate') }}\n```\n\nAnd you can even translate models easily by just plugging in your content:\n\n```php\n{{ __trans($post-\u003etitle) }}\n```\n\nOr use placeholders:\n\n```php\n{{ __trans('Post :title', ['title' =\u003e $post-\u003etitle]) }}\n```\n\nIn your `translations` database table you'll have something like this:\n\n    | id |     text     |                  data                |\n      1     'Translate'    {\"en\":\"Translate\",\"fr\":\"Traduire\"}\n\nTo switch languages for the users session, all you need to call is:\n\n```php\nApp::setLocale('fr') // Setting to French locale\n\n// Or use this, they both work\nTranslation::setLocale('fr') // Setting to French locale\n```\n\nLocales are automatically created when you call the `Translation::setLocale($code)` method,\nand when the translate function is called, it will automatically create a new translation record\nfor the new locale, with the default locale translation. The default locale is taken from the laravel `app.php` config file.\n\nYou can now update the translation on the new record and it will be shown wherever it's called:\n\n```php\n__trans('Translate me!')\n```\n\n###### Need to translate a single piece of text without setting the users default locale?\n\nJust pass in the locale into the third argument inside the translation functions show above like so:\n\n\nView:\n```php\n{{ __trans('Our website also supports russian!', [], 'ru') }}\n```\n\u003cbr\u003e\n\n```php\n{{ __trans('And french!', [], 'fr') }}\n```\n\nSeen:\n\n    Наш сайт также поддерживает России !\n    \n    Et françaises !\n    \nThis is great for showing users that your site supports different languages without changing the entire site\nlanguage itself. You can also perform replacements like usual:\n\nView:\n\n```php\n{{ __trans('Hello :name, we also support french!', ['name' =\u003e 'John Doe'], 'fr') }}\n```\n\nSeen:\n\n    Bonjour John Doe , nous soutenons aussi le français !\n\n## Routes\n\nTranslating your site with a locale prefix couldn't be easier. First inside your `app/Http/Kernel.php` file, insert\nthe locale middleware:\n\n```php\n/**\n * The application's route middleware.\n *\n * @var array\n\t*/\nprotected $routeMiddleware = [\n    'auth' =\u003e \\App\\Http\\Middleware\\Authenticate::class,\n    'auth.basic' =\u003e \\Illuminate\\Auth\\Middleware\\AuthenticateWithBasicAuth::class,\n    'guest' =\u003e \\App\\Http\\Middleware\\RedirectIfAuthenticated::class,\n\n    // Insert Locale Middleware\n    'locale' =\u003e \\JosephNC\\Translation\\Middleware\\LocaleMiddleware::class\n];\n```\n\nNow, in your `app/Http/routes.php` file, insert the middleware and the following Translation method in the route\ngroup prefix like so:\n\n```php\nRoute::group([\n    'prefix'        =\u003e Translation::getRoutePrefix(),\n    'middleware'    =\u003e ['locale'],\n], function () {\n\n    Route::get('home', function () {\n        return view('home');\n    });\n});\n```\n\nYou should now be able to access routes such as:\n\n    http://localhost/home\n    http://localhost/en/home\n    http://localhost/fr/home\n\n## Automatic Translation\n\nAutomatic translation is enabled by default in the configuration file. It utilizes this fantastic packages \u003cbr\u003e\n[Stichoza Google Translate PHP](https://github.com/Stichoza/google-translate-php).\u003cbr\u003e\n[Viniciusgava Google Translate PHP](https://github.com/viniciusgava/google-translate-php-client).\u003cbr\u003e\n\nUsing automatic translation will send the inserted text to google and save the returned text to the database.\nOnce a translation is saved in the database, it is never sent back to google to get re-translated.\nThis means that you don't have to worry about hitting a cap that google may impose. You effectively \u003cb\u003eown\u003c/b\u003e that translation.\n\n## Questions / Concerns\n\n#### Why are there underscores where my placeholders should be in my database translations?\n\nWhen you add placeholders to your translation, and add the data to replace it, for example:\n\n```php\n__trans('Hi :name', ['name' =\u003e 'John'])\n```\n\nTranslation parses each entry in the data array to see if the placeholder actually exists for the data inserted. For example,\nin the translation field in your database, here is what is saved:\n\n```php\n__trans('Hi :name', ['name' =\u003e 'John']) // Hi __name__\n\n__trans('Hi :name', ['test' =\u003e 'John']) // Hi :name\n```\n\nSince the placeholder data inserted doesn't match a placeholder inside the string, the text will be left as is. The\nreason for the underscores is because google translate will try to translate text containing `:name`, however providing\ndouble underscores on both sides of the placeholder, prevents google from translating that specific word, allowing us to translate\neverything else, but keep placeholders in tact. Translation then replaces the double underscore variant of the placeholder\n(in this case `__name__`) at runtime.\n\n#### If I update / modify the text inside the translation function, what happens to it's translations?\n\nIf you modify the text inside a translation function, it will create a new record and you will need to translate it again.\nThis is intended because it could be a completely different translation after modification.\n\nFor example using:\n\n```php\n{{ __trans('Welcome!') }}\n```\n\nAnd modifying it to:\n\n```php\n{{ __trans('Welcome') }}\n```\n\nWould automatically generate a new translation record.\n\n#### Is there a maximum amount of text that can be auto-translated?\n\nThe package use the [Viniciusgava's](https://github.com/viniciusgava/google-translate-php-client) Google translate client\nthen falls back to [Stichoza's](https://github.com/Stichoza/google-translate-php) if any error occurred.\n\nHowever, [Stichoza's](https://github.com/Stichoza/google-translate-php) new 3.0 update allows you to translate\nup to 4200 words per request (tested, possibly more allowed).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephnc%2Ftranslation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephnc%2Ftranslation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephnc%2Ftranslation/lists"}