{"id":15293934,"url":"https://github.com/sribna/laravel-csv-translation","last_synced_at":"2026-04-16T17:43:03.457Z","repository":{"id":57058578,"uuid":"229338770","full_name":"sribna/laravel-csv-translation","owner":"sribna","description":"An alternative translation system for Laravel 6","archived":false,"fork":false,"pushed_at":"2019-12-25T20:14:26.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T15:47:53.298Z","etag":null,"topics":["laravel","laravel-framework","laravel-locales","laravel-package","laravel6","localization"],"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/sribna.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-12-20T21:26:52.000Z","updated_at":"2019-12-25T20:11:11.000Z","dependencies_parsed_at":"2022-08-24T04:23:05.746Z","dependency_job_id":null,"html_url":"https://github.com/sribna/laravel-csv-translation","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sribna/laravel-csv-translation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sribna%2Flaravel-csv-translation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sribna%2Flaravel-csv-translation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sribna%2Flaravel-csv-translation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sribna%2Flaravel-csv-translation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sribna","download_url":"https://codeload.github.com/sribna/laravel-csv-translation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sribna%2Flaravel-csv-translation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266221281,"owners_count":23894966,"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":["laravel","laravel-framework","laravel-locales","laravel-package","laravel6","localization"],"created_at":"2024-09-30T16:53:45.731Z","updated_at":"2026-04-16T17:42:58.433Z","avatar_url":"https://github.com/sribna.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Laravel CSV translation (a.k.a LCT) offers a different approach to translate strings in Laravel 6. Translations are stored in safe, non-executable CSV files so you can edit them easily with any spreadsheet editor.\n\n**Please note:** this concept is experimental. Feel free to open issues and submit your PRs!\n\n## Why ##\nBy default, Laravel provides two ways of storing translations - PHP arrays and JSON strings.\n\n**Disadvantages of PHP arrays:**\n\nExecutable code requires translators to properly escape characters, use valid PHP syntax, otherwise you get a fatal error. Message IDs could be a nightmare when you develop large applications.\n\n**Disadvantages of JSON**\n\nAlthough JSON could be considered as a safe format, translators still have to properly escape characters and deal with the non-human-friendly format. No message IDs, but now you cannot divide your translations, which means all the strings (thousands and thousands for large apps) are loaded in memory.\n\n## Introducing LCT ##\n\n\n- Safe, human-readable format\n- Handy. Use regular spreadsheet programs to edit translations\n- DRY. No message IDs\n- Optimized. Automatically splits translations by \"context\" files\n- Smart. Finds and adds untranslated strings to original files on the fly\n\n\n## Usage ##\n\nLCT provides the following functions (and corresponding Blade directives):\n\nTranslate regular strings:\n    \n    t(string $key, array $replace = [], string $context = null)\n\nTranslate plural strings:\n    \n    tp(string $key, $number, array $replace = [], string $context = null)\n\nSet global translation contex:\n\n    trans_context(string $context = null)\n\n## How it works ##\n\nLet's see what happens when translating `Hello :user` into ukrainian language\n\n\tapp()-\u003esetLocale('uk'); // Set ukrainian language globally\n    \n    echo t('Hello :user', ['user' =\u003e 'Юра'], 'user');\n\nFirst, LCT will try to find and parse a CSV file for the current context. We have specified \"user\" so the expected file is `resources/lang/uk/context/user.csv`.\n\nOnce found and parsed, LCT checks `Hello :user` key in the array of translations. If key `Hello :user` is set, further processing is stopped and we see a localized text.\n\nOtherwise, LCT will check \"parent\" file `resources/lang/uk/context/_uk.csv`, which is a copy of `resources/lang/uk/_uk.csv` (it has been copied automatically during translator initialization)\n\nIf the parent file doesn't contain `Hello :user`, LCT loads the distributed translation file `resources/lang/uk/uk.csv` (contains all translations for your app) and appends `Hello :user` key to `resources/lang/uk/context/user.csv` and `resources/lang/uk/context/_uk.csv` so you can translate it later using a spreadsheet editor.\n\n*As you see, specifying context in `t()` function can be quite tedious. You can skip it and use default route URI context or set globally (e.g per view)*\n\n**Route URI context**\n\nThis is by default. Say we're at page \"product/some-id\" which is result of this route definition:\n\n    Route::get('product/{id}', function () {\n      return view('product');\n    });\n\nThe expected context file for this route will be `resources/lang/uk/context/uri-product-id.csv`.\n\n**Setting context globally**\n\nUse `trans_context()` in regular PHP files and `@trans_context` in Blade views\n\n    \u003c?php\n    \n    trans_context('user');\n    \n    echo t('Hello :user', ['user' =\u003e 'Юра']); // Uses \"user\" context\n    \n    trans_context(); // Reset context to default\n    \n    echo t('Hello :user', ['user' =\u003e 'Юра']); // Uses URI context\n\nBlade views:\n\n    @trans_context('user');\n    \n    {{ t('Hello :user', ['user' =\u003e 'Юра']) }} \u003c!-- Uses \"user\" context --\u003e\n    \n    @trans_context; \u003c!-- Reset context to default --\u003e\n    \n    {{ @t('Hello :user', ['user' =\u003e 'Юра']) }} \u003c!-- Uses URI context --\u003e\n\n\n**Pluralization**\n\nUse `tp()` in regular PHP files and `@tp()` in Blade views. They are equal to Laravel's [trans_choice()](https://laravel.com/docs/6.x/localization#pluralization)\n\n## Installation ##\n\n    composer require sribna/laravel-csv-translation\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsribna%2Flaravel-csv-translation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsribna%2Flaravel-csv-translation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsribna%2Flaravel-csv-translation/lists"}