tanmuhittin / laravel-google-translate

Translate translation files to other languages using google translate or another translation api
MIT License
424 stars 71 forks source link

[Small] Fixes possible translation issues in strings containing ":" and "|". #40

Closed Varanloo closed 3 years ago

tanmuhittin commented 3 years ago

The PR is not explaining the reason behind. Could you share a real translation issue you encountered to be clear

Varanloo commented 3 years ago

Yes, of course, I write here some examples that I had issue in translation. (please translate the Norwegian to English).

'Log_changed_old_to_new' => 'Endret ":old" til ":new".', 'click_here_to_send_to_support' => 'Klikk her for å sende mail til support: :link', 'ambulance_stations' => 'Ambulansestasjon|Ambulansestasjoner', 'Report_response_column_bigger_than_mins' => '>:minutes min.'

tanmuhittin commented 3 years ago

Hi @Varanloo

This package makes replacement in the original text before sending it to translation services. This replacement prevents variables to be translated. To detect these variables we use a regex defined in

https://github.com/tanmuhittin/laravel-google-translate/blob/2f2d97b7cf0a1296b92a1aeb8cb965bac683c118/src/Translators/ApiTranslateWithAttribute.php#L41

When I debug your text, I found that your variables are not detected with this method so it is sent to the translation services as it is.

Looks like this regex won't exactly match the behavior of the Laravel translate method ( __() ) Regex can be improved to match the relevant behavior of the Laravel translate method. I believe in this way your translations would also be translated very well.

I will reject this PR because it is not a proper approach. I would appreciate another PR with this proposed solution.