Download the PHP package rogervila/laravel-csv-translations without Composer
On this page you can find all versions of the php package rogervila/laravel-csv-translations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rogervila/laravel-csv-translations
More information about rogervila/laravel-csv-translations
Files in rogervila/laravel-csv-translations
Package laravel-csv-translations
Short Description Load Laravel localizations from a CSV File
License MIT
Informations about the package laravel-csv-translations
Laravel CSV Translations
Load Laravel localizations from a CSV File
Installation
To use Laravel CSV Translations you will have to replace the Laravel TranslationServiceProvider with the package one.
If your project uses Illuminate\Support\ServiceProvider
, replace it via the replace
method.
To make it work without modifying any configuration, Create a lang.csv
file placed in the lang
folder.
Translations will be loaded from the CSV file if it exists. Otherwise, Laravel's built-in translation system will handle them.
Configuration
The package allows configuring some of its features.
There is no config file published by the package. You might create it to override the package defaults:
CSV format
The CSV data should have keys on the first column, and then one column per locale with its ISO 639-1 code as a header.
keys | custom column | en | es | ca |
---|---|---|---|---|
greetings.good_morning | Columns that do not match the current locale are just ignored | Good morning :name! | Buenos días, :name! | Bon dia, :name! |
CSV features
The CSV format is quite flexible. These are some of its features:
Dimensions
Laravel's PHP translation array files allow having more than one dimension that can be accessed with dots.
The CSV only allows one dimension, but it allows to use dots, as shown in the CSV Format example.
Translation keys column
While keys must be placed on the first column, its header content does not matter, so it's not necessary to name it "keys".
Column order
Except for the translation keys column, the order does not matter, so you can have N custom columns between locale columns if you need them.
Custom columns
Sometimes, business wants to have additional columns for translation files, like the view where a translation is placed, its context, etc.
You can have as many columns as you need, placed in the order you need.
CSV data resolver
By default, the package uses the CSVLocalFileResolver
class that will try to load a lang.csv
file from the project's lang
path.
You may create your own CSV Resolver to customize the way to get the data:
Access raw data
Sometimes it is useful to access the raw data to list all available translation keys and their values.
To do so, CSVLoader
comes with a handy raw
method that returns an associative array with all translation keys and their raw values.
Author
Created by Roger Vilà
License
This package is open-sourced software licensed under the MIT license.
Package icon made by Freepik - Flaticon