laravel-js-localization icon indicating copy to clipboard operation
laravel-js-localization copied to clipboard

wrong behaviour when using replacements with same starting name

Open sebsobseb opened this issue 5 years ago • 3 comments

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

sebsobseb avatar Feb 26 '20 22:02 sebsobseb

A solution would be to use \b in the regex: new RegExp(':' + replacementName + '\\b', 'g'),

sebsobseb avatar Mar 03 '20 14:03 sebsobseb

Laravel sorts by length before doing the replacements - https://github.com/laravel/framework/blob/v7.0.0/src/Illuminate/Translation/Translator.php#L217

bytestream avatar May 03 '20 15:05 bytestream

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

sebsobseb avatar May 03 '20 16:05 sebsobseb