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

Overview

Laravel Larex

Version Downloads PHP Laravel License Build Coverage

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

You can import translation entries from lang folder 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 lang folder.
    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/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.
  • You can use php artisan larex:lang:add to add a new language column to your CSV file.
  • You can use php artisan larex:lang:remove to remove a language column from your CSV file.

๐Ÿ“ Example

  1. Run php artisan larex:init command

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

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

  2. You'll get the following files:

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

โซ Exporters

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

Exporter Default Description
laravel โœ… Export data from CSV to Laravel localization files
json:group โŒ Export data from CSV to JSON by group
json:lang โŒ 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 <importer> command imports the strings of the selected importer, into the CSV.

Importer Default Description
laravel โœ… Import data from Laravel localization files to CSV
json:group โŒ Import data from JSON by group to CSV
json:lang โŒ 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 โœ… Validate the header structure
ValidLanguageCodeLinter โœ… Validate the language codes in the header columns
DuplicateKeyLinter โœ… Find duplicated keys
ConcurrentKeyLinter โœ… Find concurrent keys
NoValueLinter โœ… Find missing values
DuplicateValueLinter โœ… Find duplicated values in the same row
UntranslatedStringsLinter โŒ Find untranslated strings
UntranslatedStringsLinter โŒ Find unused strings
ValidHtmlValueLinter โŒ Check valid html values
SameParametersLinter โŒ Check same parameters in each language

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 L5.8 L6.x L7.x L8.x L9.x
^1.0 โœ… โœ… โœ… โœ… โŒ
^1.2 | ^2.0 โŒ โœ… โœ… โœ… โŒ
^3.0 โŒ โŒ โœ… โœ… โŒ
^4.0 โŒ โŒ โŒ โœ… โœ…
Larex PHP7.2 PHP7.3 PHP7.4 PHP8.0 PHP8.1
^1.0 โœ… โœ… โœ… โŒ โŒ
^1.6 | ^2.0 โŒ โœ… โœ… โœ… โœ…
^3.0 โŒ โŒ โœ… โœ… โœ…
^4.0 โŒ โŒ โŒ โœ… โœ…

๐Ÿ“ƒ 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
๐Ÿงฌ Nano is a zero-config, no skeleton, minimal Hyperf distribution that allows you to quickly build a Hyperf application with just a single PHP file.

Nano is a zero-config, no skeleton, minimal Hyperf distribution that allows you to quickly build a Hyperf application with just a single PHP file.

Hyperf 273 Jan 4, 2023
This Pocketmine-MP plugin lets you implement the ultimate birthday wishing system on your server.

BirthdaysPE This Pocketmine-MP plugin will let you wish player(s) a happy birthday and notify others to wish them too. Commands /birthday <set/reset>

MCA7 3 Jul 25, 2022
LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

Teniola Fatunmbi 2 Aug 22, 2022
A complete solution for group projects in organizations that lets you track your work in any scenario. Working in a team is a cumbersome task, ease it using our project management system.

SE-Project-Group24 What is Evolo? Evolo is Dashboard based Project Management System. A complete solution for group projects in organizations that let

Devanshi Savla 2 Oct 7, 2022
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

Class Preloader 356 Nov 26, 2022
High-performance, low-memory-footprint, single-file embedded database for key/value storage

LDBA - a fast, pure PHP, key-value database. Information LDBA is a high-performance, low-memory-footprint, single-file embedded database for key/value

Simplito 12 Nov 13, 2022
Simple, single-file and dependency-free AWS S3 client.

Simple, single-file and dependency-free AWS S3 client. Why? In some scenarios we want the simplest and lightest S3 client possible. For example in Bre

Matthieu Napoli 28 Nov 15, 2022
An open source tool that lets you create a SaaS website from docker images in 10 minutes.

็ฎ€ไฝ“ไธญๆ–‡ Screenshots for members ( who subscribe the plan ) for admin โš ๏ธ This document was translated into English by deepl and can be improved by PR An o

Easy 669 Jan 5, 2023
This simple code lets you to get how many % of this year had passed

Year-Percent-PHP This simple code lets you to get how many % of this year had passed Code is part of Telegram bot and was made for Telegram channel Ye

Puzzak 1 Jan 3, 2022
A PocketMine-MP plugin that lets you teleport among offline players

OfflinePlayerTP A PocketMine-MP plugin that lets you teleport among offline players. Commands Command Description /otp <player> Teleport to (offline)

Muqsit Rayyan 8 Sep 23, 2022
This module integrates Silverstripe CMS with Google Translate API and then allows content editors to use automatic translation for every translatable field.

Autotranslate This module integrates Silverstripe CMS with Google Translate API and then allows content editors to use automatic translation for every

null 4 Jan 3, 2022
Parse your humble choice / monthly data and compile a CSV list for better overview

humbleparser Parse your humble choice / monthly data and compile a CSV list for better overview Requirements PHP CLI (>= 7.4)) php-curl Note I have ne

null 1 May 4, 2022
Simple user settings facade for Hyperf. Settings are stored as JSON in a single database column, so you can easily add it to an existing table.

hyperf-user-settings Simple user settings util for hyperf Settings are stored as JSON in a single database column, so you can easily add it to an exis

lysice 1 Oct 15, 2021
Magento 2 Module for parsing xlsx, xlsm and csv files from Excel

Magento 2 Spreadsheet Parser Facts Parse XLSX, XLSM and CSV Files from Excel Requirements PHP >= 7.0.* Magento >= 2.1.* Compatibility Magento >= 2.1 U

Stรคmpfli AG 9 Sep 24, 2020
Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel

Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel , mapping of any format, Google Sheet, data and price modification, improved speed and a lot more!

Firebear Studio 173 Dec 17, 2022
I create this code to upload CSV in database in packets of 100.

PHP-CSV-Upload I create this code to upload CSV in the database in packets of 100 elements in one for loop. Hi, This is Anmol Singh. To reach our Goal

Anmol Singh 2 Feb 12, 2022
Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files

Icinga Web 2 Fileshipper module The main purpose of this module is to extend Icinga Director using some of it's exported hooks. Based on them it offer

Icinga 25 Sep 18, 2022