Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing Laravel system translations #1

Closed
kasperhartwich opened this issue Dec 5, 2019 · 22 comments
Closed

Importing Laravel system translations #1

kasperhartwich opened this issue Dec 5, 2019 · 22 comments

Comments

@kasperhartwich
Copy link

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

@eldor
Copy link
Contributor

eldor commented Dec 5, 2019

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
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

eldor commented Dec 5, 2019

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
Copy link
Author

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

@eldor
Copy link
Contributor

eldor commented Dec 5, 2019

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
Copy link
Author

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
Copy link
Contributor

eldor commented Dec 5, 2019

Good idea, will look into that.

@kasperhartwich
Copy link
Author

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
Copy link
Contributor

eldor commented Dec 5, 2019

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
Copy link
Author

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
Copy link
Contributor

eldor commented Dec 5, 2019

Try release 1.0.4 it have a merge option on scan command

@kasperhartwich
Copy link
Author

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
Copy link
Contributor

eldor commented Dec 5, 2019

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

@kasperhartwich
Copy link
Author

  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
Copy link
Contributor

eldor commented Dec 5, 2019

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
Copy link
Author

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
Copy link
Contributor

eldor commented Dec 5, 2019

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

@kasperhartwich
Copy link
Author

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

@eldor
Copy link
Contributor

eldor commented Dec 6, 2019

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

@eldor
Copy link
Contributor

eldor commented Dec 12, 2019

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

@danijelk
Copy link
Contributor

Feel free to reopen if there is anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants