vemcogroup / laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor
MIT License
131 stars 14 forks source link

Importing Laravel system translations #1

Closed kasperhartwich closed 4 years ago

kasperhartwich commented 4 years ago

When importing it perfectly scan the application, but it does not import the already existing translations in /resources/lang/en. Maybe it should?

eldor commented 4 years ago

Thx for your comment. The issue is there is no option at the moment to separate json translations from system translations in the poeditor interface. I have some options to try out, but if you have a suggestion you are more than welcome to discuss it here.

kasperhartwich commented 4 years ago

Maybe a seperate command to import the php files to the json files could be an idea. It should be possible to import the files by using laravels Loader.

kasperhartwich commented 4 years ago

Could easily be better structured, but i used this to get the translations:

Arr::dot(collect(\Illuminate\Support\Facades\File::files(base_path('resources/lang/en')))->mapWithKeys(function($file) {
  $group = str_replace('.php', '', $file->getFilename());
  return [
    $group => 
    (new \Illuminate\Translation\FileLoader(
      new Illuminate\Filesystem\Filesystem(),
            base_path('resources/lang')
    ))->load('en', $group)
  ];
})->toArray());
eldor commented 4 years ago

Yes, but the problem is not in the scan, it already scans those files, the problem is with POEditor and how to write it back in different folders and files.

The solution is to change your system translations in /resources/lang/en/auth.php from:

'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',

to:

'throttle' => __('too many login attempts. Please try again in :seconds seconds'),

Then it will on next scan it will add it to the translation sync and you are all good.

I'll update the README soon.

kasperhartwich commented 4 years ago

Ohh.. Is that why it removes the translations i imported, when doing a new scan?

eldor commented 4 years ago

Good question, do you mean in POEditor or in Laravel project? A new scan creates a new base_language file and that is was is getting uploaded.

kasperhartwich commented 4 years ago

Ohh. That's why. As it is primary uploading terms, wouldn't it be smarter to merge with current one and then upload? In that way you can create terms without using then in the application.

eldor commented 4 years ago

Good idea, will look into that.

kasperhartwich commented 4 years ago

Cool. I also often experience that code gets outcommented, removed or added from different branches, so they are sometimes there and then not. The result of that would be terms getting deleted and added all the time.

eldor commented 4 years ago

You always have to do a scan for translations then the file will always be updated. If I do a merge, old keys will be keept and never cleaned up. It will also fill up in POEditor. We only use translation scan on master branch before deploying.

kasperhartwich commented 4 years ago

But you can delete olds keys manually on POEditor? And if you wait to scan upon deployment, you could get translations in production that has not been translated.

eldor commented 4 years ago

Try release 1.0.4 it have a merge option on scan command

kasperhartwich commented 4 years ago

There is one slight problem. If the key exists, it overrides the translation. So if the translation has been changed at POEditor, it will be changed backed to default value in the json file.

eldor commented 4 years ago

Its expected behavior, POEditor always have priority, if you choose to do an upload/download. Otherwise im misunderstand ;)

kasperhartwich commented 4 years ago
  1. Scan and upload to POEditor
  2. Change string at POEditor.
  3. Download strings from POEditor.
  4. Scan and merge.

Then the translated string from POEditor is overwritten by the string from the code.

eldor commented 4 years ago

But why do you need the base_language strings translated in PoEditor? They are by default correct from the code? or are you using this format group.text instead of full strings like Your pasword is incorrect ?

kasperhartwich commented 4 years ago

First, they are only correct if the developer speaks correct english. Secondly, for this project; yes i am using keys and not sentences to pass to the POEditor, so here they are called f.ex 'auth.password.incorrect' like laravel default behaviour.

eldor commented 4 years ago

Ok, i see, then it makes sense. Will look into a solution to support this.

kasperhartwich commented 4 years ago

In general i don't see why new translations should ever overwrite the ones already in the translation files.

eldor commented 4 years ago

Try version 1.0.5 it only add new keys when using the --merge option

eldor commented 4 years ago

Hi @kasperhartwich have you looked at the new version and does it fix your merge issues?

danijelk commented 4 years ago

Feel free to reopen if there is anything else.