laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Synchronizing language files #43

Closed vpratfr closed 7 years ago

vpratfr commented 8 years ago

The usual workflow

The problem

In that process, there is a tedious manual step involved: synchronizing the language files

The translators should receive a file in their language that has all previously translated messages + all new messages which are not yet translated.

Currently, that can only be done manually and we can easily forget to add a message into one of the language files.

What is missing

Something rather simple, an artisan command such as php artisan lang:sync

That would take the default language as a parameter (by default 'en') and add/remove messages in other language files which are/are not in the en language.

Result is a consistent set of language files, with the same message keys. Missing messages could either be copied from the default language file OR set to be the message key (such as 'my-new-message' => 'messages.my-new-message')

PS: I am aware that there are a few packages out there dealing with that problem BUT they either offer something else (the one from Barryvdh has a full GUI) or they are not stable/production ready.

barryvdh commented 8 years ago

PS: I am aware that there are a few packages out there dealing with that problem BUT they either offer something else (the one from Barryvdh has a full GUI) or they are not stable/production ready.

https://github.com/themsaid/laravel-langman has php artisan langman:sync which is similar to what you describe, and is at v1.1?

vpratfr commented 8 years ago

There are lots of limitations with that package. And according to me, this feature is more or less required as soon as you are working with lang files on any project. This is why I felt it was something which could make its way into the framework.

themsaid commented 8 years ago

@vpratfr the package still doesn't support vendor language files and nested keys, however today I'm publishing a release with support for nested keys as well as fixing some bugs.

What other limitations do you think it has? I'm using the package myself for a project with 3 languages with 8 language files in each, and the first thought was to open a PR in the framework suggesting a couple of commands for synchronising language files, however I got the impression that Taylor prefers such additions to be in a package form first before considering having them into the core.

Anyway if such commands are to be integrated into the core I'll be glad to contribute.

a-h-abid commented 8 years ago

What if the language files are written on per line == per file basis, and on each file we return array with locales as keys and their value as the text message for that langauage?

<?php // file .. resources/lang/hello.php
return [
    'en' => 'Hello',
    'de' => 'Hallo',
];

Just a Thought..

vpratfr commented 8 years ago

@abdmaster according to me, this does not seem the right way to work with language files. At least not the one documented in Laravel.

@themsaid @barryvdh the laravel-langman package, as I said, is still very young. Again, it does much more than the basic need required by 90% of multi-lang projects : having the same keys and files between languages. This is why I though this is a need which is pretty essential to the developper workflow and eligible to be suggested as a core feature.

@themsaid your package is a nice addition, but still not ready for production. I just installed version 1.2.0 on an existing project and got an exception when trying to sync. Additionally, it will try to find keys from views and not from any other class in app which is incomplete (I got messages in controllersfor instance which will be ignored).