How to find missing translations on Laravel

Have you ever been on the situation where you are working on a multi-locale application and maybe missed a translation for a given locale, or maybe you spend too much time on code reviews making sure that no translation key is missing.

I’ve been working with multi language apps for several years, in all sort of stacks, but lately Laravel with front-end handled by Livewire, so, basically, I’m leveraging all the front end translation to laravel built in funcionality.

Working on multi-language apps, the issues described on the first paragraph were a very commong scenario, that’s why, I started looking for a package to tackle this, maybe a already existing solution in Laravel itself, and, after failing to find a solution, I decided to build one myself.

This is how Easy locale for Laravel [https://github.com/inspirapuntodo/easy-locale-for-laravel] was born, in very few words, this packages allows to handle repetitive tasks while working with multi-language apps and run checks for your translations.

How to find missing translations

To find missing translation keys, simply run the following command:

php artisan locale:diff

This command will fail if you have any missing key in any of your locale definitions, furthermore, it will tell you exactly which key and the path is missing along with the locale.

Include locale diff in you CI pipeline

As this command returns a failure status when a difference is found, you can add it to your CI pipeline and it will mark a failure while running your test, for example, using github action, you can add the following step:

 - name: Make sure all translations are defined
        run: php artisan locale:diff

You will be able to see your check fail in case you missed a translation:

If there are no missing translation, you will see your step pass:

Bonus

One of the most boring parts is creating the translation files for each locale, this is why, this plugin also includes a command to create your files for each locale.

php artisan locale:make orders

This will create a orders.php on each defined locale, ex: (es, en, it, de, etc…)


Andddd, thats it! This library is a WIP, expecting to add more cool features in the future, also, I’m open and happy to receive any collaboration.

Anddd youuu, yes! you who is reading this article: Happy coding, you rock!


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *