laravel-langman icon indicating copy to clipboard operation
laravel-langman copied to clipboard

Command to synchronize languages (not from views, just between languages)

Open vpratfr opened this issue 8 years ago • 7 comments

Say we have for instance the following language files and keys:

lang/en/users.php   [ 'name' => 'Name' ]
lang/en/address.php [ 'city' => 'City', 'zip' => 'Zip code' ]

lang/fr/users.php   [ 'name' => 'Nom' ]
lang/fr/address.php [ 'city' => 'Ville' ]

lang/de/users.php   [ 'name' => 'Name' ]

We need a command which would synchronize all languages with the same keys.

A translator will not have access to php artisan, so the command missing will not really help in this case.

That command in that example would:

  • create the file lang/de/address.php with all keys,
  • add the key zip to the file lang/fr/address.php

Of course, that command needs to know which language is our reference (in this example, en is the reference language), that could be a setting in config for instance and/or could be overridden in the command line.

vpratfr avatar Apr 13 '16 17:04 vpratfr

I think the sync command can include the search for keys that exist in a language bas not in another, currently the missing command does this job.

So you run langman:sync and it looks into your application files to check for keys that doesn't exist in your language files, and also look into you language files and make sure all keys that exist in a language exists in the other. What do you think?

themsaid avatar Apr 13 '16 17:04 themsaid

I think that should be independent. For example, some dynamic keys are not grabbed by the sync command (like my example with enums in another issue). So those keys are not synchronized accross languages.

Additionally, the missing command will prompt me for each message. What if I have 200 messages? I just want to create all files for that new language and send them to the translators who will use a text editor.

Better than empty strings, it would be more useful to have the default language for new keys.

vpratfr avatar Apr 13 '16 18:04 vpratfr

Actually I'm saying that I can move the functionality of syncing keys across language files to the sync command, the sync command won't prompt for translations, that way The translation files will have all the needed keys after the langman:sync command so that you don't have to run langman:missing if you don't want.

themsaid avatar Apr 13 '16 18:04 themsaid

That would be useful yes.

vpratfr avatar Apr 13 '16 19:04 vpratfr

That new step should include:

  • Creating missing keys in all language files
  • Make sure the vendor lang folders get synced too
  • Creating missing files (even if that file does not contain any message from the views, see example with enums)

That extra step is not connected at all to finding keys in views/app. So I guess you could take my example above as a test case.

vpratfr avatar Apr 13 '16 19:04 vpratfr

Any update about this?

uyab avatar May 25 '16 02:05 uyab

This is now implemented on the master branch, if someone can test and confirm before making a new release I'll be very grateful.

themsaid avatar May 28 '16 11:05 themsaid