{"id":13396289,"url":"https://github.com/keevitaja/linguist","last_synced_at":"2025-03-13T22:32:04.265Z","repository":{"id":35292946,"uuid":"39554079","full_name":"keevitaja/linguist","owner":"keevitaja","description":"Easy multilingual urls and redirection support for the Laravel framework","archived":false,"fork":false,"pushed_at":"2019-09-18T10:58:38.000Z","size":45,"stargazers_count":191,"open_issues_count":2,"forks_count":15,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-24T16:24:32.428Z","etag":null,"topics":["estonia","i18n","laravel","linguist","locales","localization","multilingual","php","translation"],"latest_commit_sha":null,"homepage":"","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/keevitaja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-23T08:02:39.000Z","updated_at":"2024-03-04T14:40:13.000Z","dependencies_parsed_at":"2022-08-04T00:45:13.067Z","dependency_job_id":null,"html_url":"https://github.com/keevitaja/linguist","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keevitaja%2Flinguist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keevitaja%2Flinguist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keevitaja%2Flinguist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keevitaja%2Flinguist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keevitaja","download_url":"https://codeload.github.com/keevitaja/linguist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221417379,"owners_count":16816873,"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":["estonia","i18n","laravel","linguist","locales","localization","multilingual","php","translation"],"created_at":"2024-07-30T18:00:43.968Z","updated_at":"2024-10-25T10:32:03.299Z","avatar_url":"https://github.com/keevitaja.png","language":"PHP","readme":"# Linguist - Multilingual urls and redirects for Laravel\n\nThis package provides an easy multilingual urls and redirection support for the Laravel framework. \n\nIn short Laravel will generate localized urls for links and redirections.\n\n```php\nroute('people') \n```\n\n```\nhttp://site.com/people\nhttp://site.com/fr/people\n```\n\n\u003e Linguist works perfectly well with https://github.com/tightenco/ziggy named Laravel routes for javascript package!\n\n## Installation\n\nLinguist is very easy to use. The locale slug is removed from the REQUEST_URI leaving the developer with the cleanest multilingual environment possible.\n\nInstall using Composer:\n\n```bash\ncomposer require keevitaja/linguist\n```\n\nThere are several options to make Linguist work.\n\n### Option 1: Modify the `public/index.php`\n\nAdd following line after the vendor autoloading to your projects `public/index.php` file.\n\n```php\n(new Keevitaja\\Linguist\\UriFixer)-\u003efixit();\n```\n\nEnd result would be this:\n\n```php\n/*\n|--------------------------------------------------------------------------\n| Register The Auto Loader\n|--------------------------------------------------------------------------\n|\n| Composer provides a convenient, automatically generated class loader for\n| our application. We just need to utilize it! We'll simply require it\n| into the script here so that we don't have to worry about manual\n| loading any of our classes later on. It feels great to relax.\n|\n*/\n\nrequire __DIR__.'/../vendor/autoload.php';\n\n(new Keevitaja\\Linguist\\UriFixer)-\u003efixit();\n```\n\n### Option 2: Use LocalizedKernel\n\n\u003e Note: This option works only if you have not changed your applications root namespace. Default is `App`.\n\nIn your projects `bootstrap/app.php` swap the `App\\Http\\Kernel` with `Keevitaja\\Linguist\\LocalazedKernel`:\n\n```php\n/*\n|--------------------------------------------------------------------------\n| Bind Important Interfaces\n|--------------------------------------------------------------------------\n|\n| Next, we need to bind some important interfaces into the container so\n| we will be able to resolve them when needed. The kernels serve the\n| incoming requests to this application from both the web and CLI.\n|\n*/\n\n$app-\u003esingleton(\n    Illuminate\\Contracts\\Http\\Kernel::class,\n    //App\\Http\\Kernel::class\n    Keevitaja\\Linguist\\LocalizedKernel::class\n);\n```\n\n### Option 3: modify the `App\\Http\\Kernel`\n\n\u003e Note: This also works with custom root namespace. \n\n```php\n\u003c?php\n\nnamespace App\\Http;\n\nuse Illuminate\\Contracts\\Foundation\\Application;\nuse Illuminate\\Foundation\\Http\\Kernel as HttpKernel;\nuse Illuminate\\Routing\\Router;\nuse Keevitaja\\Linguist\\UriFixer;\n\nclass Kernel extends HttpKernel\n{\n\n    public function __construct(Application $app, Router $router)\n    {\n        (new UriFixer)-\u003efixit();\n\n        parent::__construct($app, $router);\n    }\n```\n\n### Publish config\n\nFinally you need to publish the Linguist config to set your enabled locales and other relavant configurations. \n\n```\nphp artisan vendor:publish --provider=\"Keevitaja\\Linguist\\LinguistServiceProvider\"\n```\n\nYour personal configuration file will be `config/linguist.php`.\n\n## Usage\n\nYou can add the LocalizeUrls middleware your web middleware group as the first item to get the linguist support:\n\n```php\n/**\n * The application's route middleware groups.\n *\n * @var array\n */\nprotected $middlewareGroups = [\n    'web' =\u003e [\n        \\Keevitaja\\Linguist\\LocalizeUrls::class,\n```\n\n\u003e Note: This middleware has to be the first item in group!\n\nAnother option is to use Linguist in your applications service provider:\n\n```php\nclass AppServiceProvider extends ServiceProvider\n{\n    /**\n     * Bootstrap any application services.\n     *\n     * @return void\n     */\n    public function boot(\\Keevitaja\\Linguist\\Linguist $linguist)\n    {\n        $linguist-\u003elocalize();\n    }\n```\n\n`UrlGenerator` will add the locale slug in front of the URI when needed. No extra actions needed.\n\n```php\nRoute::get('people', ['as' =\u003e 'people.index', 'uses' =\u003e ''PeopleController@index'']);\n```\n\n```twig\n{{ route('people.index') }} or {{ url('people') }}\n```\n\n```\nhttp://site.com/people // default locale from linguist config\nhttp://site.com/fr/people\nhttp://site.com/ru/people\n```\n\nSwitcher is a little helper to get the current URLs for the locale switcher.\n\n```php\n$urls = dispatch_now(new \\Keevitaja\\Linguist\\Switcher);\n```\n\nNB! Both config and route caching are working!\n\n## Assets\n\nUse linguist helpers for a correct routing of assets\n\n**Regular Assets**\n \n ```twig\n \u003clink rel=\"stylesheet\" href=\"{{ linguist_asset('css/style.css') }}\"\u003e\n \u003cscript type=\"text/javascript\" src=\"{{ linguist_asset('js/my_js.js') }}\"\u003e\u003c/script\u003e\n ```\n \n **Secure Assets**\n \n ```twig\n \u003clink rel=\"stylesheet\" href=\"{{ secure_linguist_asset('css/style.css') }}\"\u003e\n \u003cscript type=\"text/javascript\" src=\"{{ secure_linguist_asset('js/my_js.js') }}\"\u003e\u003c/script\u003e\n```\n\n## Queues\n\nTo make localization work in queues you need to run `Linguist-\u003elocalize($theLocaleYouWant)` inside the queued item.\n\n## Licence\n\nMIT","funding_links":[],"categories":["Popular Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeevitaja%2Flinguist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeevitaja%2Flinguist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeevitaja%2Flinguist/lists"}