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

Unnecessary backslashes added before apostrophes in translation when using JSON output #67

Open q-- opened 1 year ago

q-- commented 1 year ago

For values where the translation contains an apostrophe ('), a double escape character is added (\\); this will create a backslash in front of the apostrophe when rendered in the web page.

For example (from base locale en to target locale it, no overwrite existing translations, verbose on, json instead of PHP output):

"Export course": "Corso sull\\'esportazione",

This should be: "Export course": "Corso sull'esportazione",

The cause of this is the call to addslashes() in this line: https://github.com/tanmuhittin/laravel-google-translate/blob/80e3e408d02283ff000832e672a9bcebda194902/src/TranslationFileTranslators/JsonArrayFileTranslator.php#L39

This is unnecessary, as json_encode, which is called on line 48, already takes care of the necessary escaping.