Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Overview

Laravel Larex

Version Downloads PHP Laravel License Build Coverage

Translate Laravel Apps from a CSV File

Laravel Larex lets you translate your whole Laravel application from a single CSV file.

You can import translation entries from resources/lang files into a structured CSV, edit the translations and export them back to Laravel PHP files.

Laravel Larex also supports functionalities to sort entries and find strings that aren't localized yet.

See Plugins section for other features.

🚀 Installation

You can install the package using composer

composer require lukasss93/laravel-larex --dev

Then add the service provider to config/app.php.
This step can be skipped if package auto-discovery is enabled.

'providers' => [
    Lukasss93\Larex\LarexServiceProvider::class
];

Publishing the config file

Publishing the config file is optional:

php artisan vendor:publish --provider="Lukasss93\Larex\LarexServiceProvider" --tag="larex-config"

👓 Usage

  1. First, you must create the initial CSV file with php artisan larex:init.
    Or you can use php artisan larex:import to import entries from resources/lang files.
    The csv file has the following columns:

    • group (basically the file name)
    • key (the array key)
    • en (the language code)
    • other language codes...
  2. Open the project-root/resources/lang/localization.csv file and edit it as you see fit.

  3. Finally, you can use php artisan larex:export to translate your entries from the csv file to the laravel php files.

Tips

  • You can import existing laravel php files with php artisan larex:import.
  • You can use php artisan larex:init --base to init the CSV file with default Laravel entries.
  • The key column inside the CSV file supports the dot notation for nested arrays.
  • You can watch your CSV file with php artisan larex:export --watch
  • You can use php artisan larex:sort to sort the CSV file by group and key.
  • Be careful when using the php artisan larex:export command! It will overwrite all files named with the group names inside the CSV.
  • Be careful when using the dot notation! Only the last entry will override the value.
  • You can use php artisan larex:insert to add new items via CLI too!
  • You can use php artisan larex:import --include=en,it to import only "en" and "it" items.
  • You can use php artisan larex:import --exclude=it to import all items except "it" item.
  • You can use php artisan larex:export --include=en,it to export only "en" and "it" columns.
  • You can use php artisan larex:export --exclude=it to export all columns except "it" column.
  • You can use php artisan larex:localize to find unlocalized strings (use the --import option to add strings in your CSV).
  • You can use php artisan larex:find to search existing groups or keys in your CSV file.
  • You can use php artisan larex:remove to remove existing strings in your CSV file.

📝 Example

  1. Run php artisan larex:init command

  2. Edit the project-root/resources/lang/localization.csv file

    group key en it
    app hello Hello Ciao
    app list.developers Developers Sviluppatori
    app list.teachers Teachers Insegnanti
  3. Run php artisan larex:export command

  4. You'll get the following files:

    //project-root/resources/lang/en/app.php
    
    
    
    return [
        'hello' => 'Hello',
        'list' => [
            'developers' => 'Developers',
            'teachers' => 'Teachers',
        ]
    ];
    //project-root/resources/lang/it/app.php
    
    
    
    return [
        'hello' => 'Ciao',
        'list' => [
            'developers' => 'Sviluppatori',
            'teachers' => 'Insegnanti',
        ]
    ];

Exporters

The larex:export command exports CSV strings to a specific location based on the selected exporter.

Exporter Default Description
laravel Yes Export data from CSV to Laravel localization files
json:group No Export data from CSV to JSON by group
json:lang No Export data from CSV to JSON by language
How to create an exporter:
  1. Create a class that implements the Lukasss93\Larex\Contracts\Exporter interface
  2. Add your exporter inside the larex config

Importers

The larex:import command imports the strings of the selected importer, into the CSV.

Importer Default Description
laravel Yes Import data from Laravel localization files to CSV
json:group No Import data from JSON by group to CSV
json:lang No Import data from JSON by language to CSV
How to create an importer:
  1. Create a class that implements the Lukasss93\Larex\Contracts\Importer interface
  2. Add your importer inside the larex config

🔍 Linters

Larex provides a linting system by using the php artisan larex:lint command to validate your CSV file.

Available linters:
Linter Enabled by default Description
ValidHeaderLinter Yes Validate the header structure
ValidLanguageCodeLinter Yes Validate the language codes in the header columns
DuplicateKeyLinter Yes Find duplicated keys
ConcurrentKeyLinter Yes Find concurrent keys
NoValueLinter Yes Find missing values
DuplicateValueLinter Yes Find duplicated values in the same row
UntranslatedStringsLinter No Find untranslated strings
UntranslatedStringsLinter No Find unused strings
ValidHtmlValueLinter No Check valid html values

You can enable/disable any linter you want by comment/uncomment it inside the larex config.

How to create a linter:
  1. Create a class that implements the Lukasss93\Larex\Contracts\Linter interface
  2. Add your linter inside the larex config

🧩 Plugins

  • Crowdin Plugin
    A Laravel Larex plugin to import/export localization strings from/to Crowdin

⚗️ Testing

composer test

🔰 Version Support

Larex PHP Laravel
1.0 7.2 ≥ 5.8
≥ 1.2 and ≤ 2.1 7.2 | 7.3 | 7.4 ≥ 6
≥ 3.0 7.4 | 8.0 ≥ 7

📃 Changelog

Please see the CHANGELOG.md for more information on what has changed recently.

🏅 Credits

📖 License

Please see the LICENSE.md file for more information.

Comments
  • Not standard csv file

    Not standard csv file

    The current csv delimiter is ";" instead of ",". It's necessary to change it to support standard csv files provided by external programs like google sheets, etc...

    enhancement 
    opened by Lukasss93 2
  • Sentences with line break aren't escaped!

    Sentences with line break aren't escaped!

    Input:

    group;key;en
    app;test;test
    app;hello;"hello
    friends"
    app;ok;ok
    

    After larex:sort (missing escaping):

    group;key;en
    app;hello;hello
    friends
    app;ok;ok
    app;test;test
    
    bug 
    opened by Lukasss93 2
  • No way of ordering languages with import command.

    No way of ordering languages with import command.

    The larex:import command orders languages alphabetically to the CSV. How can you order them differently? In my case using the larex crowdin plugin that wants the third key to be the source language and my file: group,key,af,am,ar,en

    enhancement 
    opened by Abdaaf 1
  • Wrong enclosure with larex:insert

    Wrong enclosure with larex:insert

    The larex:insert command add wrong enclosure if there is a quotation mark with a comma.

    Example:

    Input: test "cool" and, oops

    Output: ""test ""cool"" and, oops""

    Expected: "test ""cool"" and, oops"

    bug 
    opened by Lukasss93 1
  • Added confirmation and correction possibility to the insert command

    Added confirmation and correction possibility to the insert command

    Added confirmation to the insert command. If user do not confirm, the questions will be reprompted printing the values previously inserted by the user. User can reuse the old value just pressing ENTER.

    image

    opened by tiaxter 1
  • Invalid escaping on export command

    Invalid escaping on export command

    Value on CSV:

    group;key;en
    app;example;This is a \"string\"
    

    Value after export command:

    // resources/lang/en/app.php
    <?php
    
    return [
        'example' => 'This is a \"string\"'
    ];
    

    How it should be:

    // resources/lang/en/app.php
    <?php
    
    return [
        'example' => 'This is a "string"'
    ];
    
    bug 
    opened by Lukasss93 1
  • Change commands export/import

    Change commands export/import

    The commands larex:export and larex:import could be confusing to users.

    Possible solutions:

    • Replace larex:export with larex:build:lang and larex:import with larex:build:csv
    • Add larex:build:lang as alias for larex:export and larex:build:csv as alias for larex:import
    enhancement help wanted question 
    opened by Lukasss93 1
  • Add support for

    Add support for "Overriding Package Language Files"

    https://laravel.com/docs/9.x/localization#overriding-package-language-files

    Which path to take?

    A) Create another localization.csv for every package inside /lang/vendor/. Example:

    • /lang/vendor/packageA/localization.csv
    • /lang/vendor/packageB/localization.csv

    B) Use the default localization.csv file using an alias prefix in the larex.php config

    // <project-root>/config/larex.php
    
    'vendor' => [
        'enabled' => false,
        'prefix' => 'vendor',
        'alias' => [
            'packageA' => 'a',
            'packageB' => 'b',
        ]
    ]
    

    |group|key |en |it | |-------|----|---|---| |vendor.a.app|car|Car|Auto| |vendor.b.common|hello|Hello|Ciao|

    new feature 
    opened by Lukasss93 0
Releases(v4.3.0)
  • v4.3.0(Nov 30, 2022)

    What's Changed

    Added

    • Added larex:lang:order command
    • Added ability to set source language for "larex:import" command

    Fixed

    • Fixed: wrong export message (#26)
    • Fixed: duplicate lint message (#27) in "SameParametersLinter" file

    Full Changelog: https://github.com/Lukasss93/laravel-larex/compare/v4.2...v4.3.0

    ℹ️ Please check the UPGRADING.md file to update the larex config.

    Source code(tar.gz)
    Source code(zip)
  • v4.2(Jul 12, 2022)

    What's Changed

    • Added new linter: SameParametersLinter

    Full Changelog: https://github.com/Lukasss93/laravel-larex/compare/v4.1...v4.2

    ℹ️ Please check the UPGRADING.md file to update the larex config.

    Source code(tar.gz)
    Source code(zip)
  • v4.1(Jun 28, 2022)

  • v4.0(Feb 3, 2022)

    v4.0 - 2022-02-04

    ⚠️ Please check the UPGRADING.md file before upgrading to this major version!

    Added

    • Added support for Laravel 9

    Changed

    • Changed path value in larex config

    Removed

    • Dropped PHP 7.4 support
    • Dropped Laravel 7 support
    Source code(tar.gz)
    Source code(zip)
  • v3.5.2(Sep 12, 2021)

  • v3.5.1(Aug 24, 2021)

  • v3.5(Aug 12, 2021)

  • v3.4(Aug 11, 2021)

  • v3.3.2(Aug 4, 2021)

  • v3.3.1(Aug 3, 2021)

  • v3.3(Aug 3, 2021)

  • v3.2(Jul 1, 2021)

  • v3.1(May 22, 2021)

  • v3.0.1(Apr 12, 2021)

  • v3.0(Apr 11, 2021)

    v3.0 - 2021-04-11

    Added

    • Added Exporters
    • Added Importers
    • Added possibility to change exporter in larex:insert command with --export=<exporter> option
    • Added larex:localize command to find unlocalized strings

    Changed

    • Now the larex:export command optionally accepts an exporter as argument
    • Now the larex:import command optionally accepts an importer as argument
    • Changed Linter interface signature

    Removed

    • Removed larex command
    • Removed csv options from larex config: delimiter, enclosure, escape
    • Dropped PHP 7.3 support
    • Dropped Laravel 6 support
    Source code(tar.gz)
    Source code(zip)
  • v2.1(Apr 3, 2021)

    v2.1 - 2021-04-03

    Added

    • Added a confirmation in larex:insert command (#8)
    • Added check if group/key already exists when using the larex:insert command

    Fixed

    • Fix null values to group and key questions in larex:insert command
    • Fix "Insert command has problems with utf-8 characters" (#9)
    • Fix "Wrong enclosure with larex:insert" (#10)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Mar 11, 2021)

  • v2.0(Jan 9, 2021)

    v2.0 - 2021-01-09

    Please check the UPGRADING.md file before upgrading to this major version!

    Added

    • Added new command php artisan larex:lint

    Changed

    • Changed default csv format:
      • Delimiter changed from ; to ,
      • Escape character changed from \" to ""
    Source code(tar.gz)
    Source code(zip)
  • v1.6(Jan 2, 2021)

    v1.6 - 2021-01-02

    Added

    • Added warning message in export command when used with -v option
    • Added support for PHP 8

    Fixed

    • Config values inaccessible when project is optimized before installing larex
    • Missing enclosures when string contains escaped enclosures

    Removed

    • Dropped support for PHP 7.2
    Source code(tar.gz)
    Source code(zip)
  • v1.5.1(Sep 15, 2020)

  • v1.5(Aug 29, 2020)

  • v1.4(Aug 28, 2020)

  • v1.3.1(Aug 10, 2020)

  • v1.3(Aug 8, 2020)

    v1.3 - 2020-08-08

    Added

    • Added larex:export command (it's an alias of larex command)

    Changed

    • Deprecated larex command (it will be removed in the next release)

    Fixed

    • Sentences with line break aren't escaped.
    Source code(tar.gz)
    Source code(zip)
  • v1.2(Jul 18, 2020)

  • v1.1(Jul 7, 2020)

  • v1.0(Jul 4, 2020)

Owner
Luca Patera
Full Stack Developer
Luca Patera
Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.

Laravel Eloquent Scope as Select Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes an

Protone Media 75 Dec 7, 2022
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

salman zafar 10 May 17, 2022
The package lets you generate TypeScript interfaces from your Laravel models.

Laravel TypeScript The package lets you generate TypeScript interfaces from your Laravel models. Introduction Say you have a model which has several p

Boris Lepikhin 296 Dec 24, 2022
🏭This package lets you create factory classes for your Laravel project.

Laravel Factories Reloaded ?? This package generates class-based model factories, which you can use instead of the ones provided by Laravel. Laravel 8

Christoph Rumpel 372 Dec 27, 2022
This Package helps you in laravel application to log all desired activity for each request from request entry point to generate response at a single snapshot.

Laravel Scenario Logger This Package helps you in laravel application to log all desired activity for each request from request entry point to generat

Mehrdad Mahdian 6 Sep 27, 2021
Renamify is a package for Laravel used to rename a file before uploaded to prevent replacing exists file which has the same name to this new uploaded file.

Renamify Laravel package for renaming file before uploaded on server. Renamify is a package for Laravel used to rename a file before uploaded to preve

MB'DUSENGE Callixte 2 Oct 11, 2022
A simple pure PHP RADIUS client supporting Standard and Vendor-Specific Attributes in single file

BlockBox-Radius A simple pure PHP RADIUS client supporting Standard and Vendor-Specific Attributes in single file Author: Daren Yeh [email protected]

null 2 Oct 2, 2022
cybercog 996 Dec 28, 2022
This Laravel Nova tool lets you run artisan and bash commands directly from Nova 4 or higher.

Laravel Nova tool for running Artisan & Shell commands. This Nova tool lets you run artisan and bash commands directly from nova. This is an extended

Artem Stepanenko 17 Dec 15, 2022
Easily integrate single-database multi tenant features into your Laravel application

Laravel Tenant Aware Easily integrate single-database multi tenant features into your Laravel application. Installation You can install the package vi

H-FARM Innovation 9 Dec 21, 2022
Translate eloquent entity models

Translate entity About package This package is intended for adding multi language support to your models. If your application already be working and y

null 7 Aug 7, 2020
Update multiple Laravel Model records, each with it's own set of values, sending a single query to your database!

Laravel Mass Update Update multiple Laravel Model records, each with its own set of values, sending a single query to your database! Installation You

Jorge González 88 Dec 31, 2022
Laravel 5 package for reading and writing CSV files.

CSV Laravel 5 package for reading and writing CSV files. Warning The package has been updated to PHP 7. If you can't update to PHP 7 use version 0.6.x

Maciej Wilgucki 48 Nov 29, 2022
Laravel Nova's Queued Export As CSV Action

Laravel Nova's Queued Export As CSV Action Installation To install through composer, run the following command from terminal: composer require "nova-k

null 9 Dec 15, 2022
The list of all Algerian provinces and cities according to the official division in different formats: csv, xlsx, php, json, etc.

algeria-cities This repository contains the list of all the administrative provinces and cities in Algeria. The data is up-to-date according to the of

Ramtani Othmane 393 Jan 2, 2023
If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

hirwa-products-plugin If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

NIYIBIZI HIRWA 1 Aug 23, 2022
Electrik is a full-featured, open-source, starter-kit to help you build you your SaaS application.

Electrik Electrik is a full-featured and open-source stater-kit for for your next SaaS application. It's built on top of Laravel, Livewire, neerajsoha

Electrik 129 Dec 31, 2022
A Single Table Inheritance Trait for Eloquent/Laravel

Single Table Inheritance Credit This code is a fork of Nanigans/single-table-inheritance. I've only updated it to work with Laravel 5 Single Table Inh

Peter Haza 15 Feb 17, 2022
Rinvex Tenantable is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy.

Rinvex Tenants is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.

Rinvex 80 Oct 21, 2022