laravel-js-localization
laravel-js-localization copied to clipboard
wrong behaviour when using replacements with same starting name
I have a translation message like this:
'items_from_to' => ':from - :to of :total'
When translating...
Lang.get('items_from_to', {
from: 1,
to: 10,
total: 34
})
I see: 1 - 10 of 10tal
instead of 1 - 10 of 100
A solution would be to use \b in the regex:
new RegExp(':' + replacementName + '\\b', 'g'),
Laravel sorts by length before doing the replacements - https://github.com/laravel/framework/blob/v7.0.0/src/Illuminate/Translation/Translator.php#L217
Laravel sorts by length before doing the replacements - https://github.com/laravel/framework/blob/v7.0.0/src/Illuminate/Translation/Translator.php#L217
That's even better