kkomelin / laravel-translatable-string-exporter

Translatable String Exporter for Laravel
MIT License
306 stars 40 forks source link

string with variable gets exported as well #42

Closed ctf0 closed 4 years ago

ctf0 commented 4 years ago

ex.

__("Hello $someVar")

$someVar == "one,two,three" which we already have a key per each

"Hello one": "Hello one",
"Hello two": "Hello two",
"Hello three": "Hello three",

atm we will also get

"Hello $someVar": "Hello $someVar",

is there a way to ignore such a case ?

andreich1980 commented 4 years ago

@ctf0 maybe you should use a placeholder like this

__("Hello :variable", ['variable' => $var])

This way it should extract


"Hello :variable": "Hello :variable"
ctf0 commented 4 years ago

i dont think json supports placeholders https://laravel.com/docs/6.x/localization#replacing-parameters-in-translation-strings

andreich1980 commented 4 years ago

i dont think json supports placeholders https://laravel.com/docs/6.x/localization#replacing-parameters-in-translation-strings

It does https://laravel-news.com/json-based-translations

ctf0 commented 4 years ago

great, thanx, will try it then

kkomelin commented 4 years ago

Hi @ctf0, Thanks for your question.

As @andreich1980 suggested, it's better to use placeholders instead of inline variables.

If it doesn't work for you, you may try persistent strings https://github.com/kkomelin/laravel-translatable-string-exporter#persistent-strings

Hope it helps.

ctf0 commented 4 years ago

perfect, thanx again for your support