Sometimes, clients will use translation services and supply CSV files with translations. You can use this package to import those translations.
You can install the package via composer:
composer require dive-be/laravel-lingo
This is the contents of the published config file:
return [
'exclude' => [],
];
A common usage is to load or export specific translations from a CSV file.
You can take the loaded translations and save them to your local Laravel project.
Lingo::make()
->parseFile('/path/to/translations.csv', 'nl')
->persist('nl');
You may wish to load the existing translations from your Laravel app first, and then save (overwrite) the merged list of translations:
Lingo::make()
->load('nl')
->parseFile('/path/to/translations.csv', 'nl')
->persist('nl');
If you do not want to override translation keys that already exist (and only import new ones), you can configure this when parsing the file:
Lingo::make()
->load('es')
->parseFile(
filePath: '/path/to/translations.csv',
locales: 'es',
replacingExistingValues: false,
)
->persist('es');
Another common use case is exporting your translations to a CSV file, so you can send these to a client or translator.
Note: If you have keys for translations that only exist for a given language, you may wish to load all translations, and export for all languages. This way you can get the union of all translation keys across all those languages, along with the localized version. If translations are missing, those fields will be left empty.
This can easily be accomplished like this:
Lingo::make()
->load($languages = ['en', 'nl', 'fr'])
->exportToCsvFile('path/to/output.csv', $languages);
- The CSV file must have headers corresponding to the different locales.
- The translation key's header must be
key
. - By default, you must use a semicolon (
;
) to separate columns. (You can modify the delimiter character.) - You cannot have duplicate column names (you may wish to rename empty columns after exporting from Excel or Numbers).
A valid file looks like this:
key,nl,en
auth-login.title;Aanmelden;Log In
auth-login.description;Vul hieronder je gegevens in.;Fill in your details below.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email oss@dive.be instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.