Extract Untranslated Strings from Laravel Projects

Packages

December 29th, 2020

localizator-featured.jpg

Localizator is a small tool for Laravel that gives you the ability to extract untranslated strings from project files. It works using the artisan command line and the provided localize command:

1php artisan localize de,fr

The above command will create a de.json and fr.json file in the resources/lang folder or add missing keys if these files already exist.

You can also use the configuration value in app.locale by running the command without arguments:

1# Use the `config('app.locale')` value
2php artisan localize

The package also provides configurable values to suit your project’s needs, along with sensible defaults:

1return [
2 
3 /**
4 * Search criteria for files.
5 */
6 'search' => [
7 /**
8 * Directories which should be looked inside.
9 */
10 'dirs' => ['resources/views'],
11 
12 /**
13 * Patterns by which files should be queried.
14 * The values can be a regular expresion, glob, or just a string.
15 */
16 'patterns' => ['*.php'],
17 
18 /**
19 * Functions that the strings will be extracted from.
20 * Add here any custom defined functions.
21 * NOTE: The translation string should always be the first argument.
22 */
23 'functions' => ['__', 'trans', '@lang']
24 ],
25 
26 /**
27 * Should the localize command sort extracted strings alphabetically?
28 */
29 'sort' => true,
30 
31];

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.