andywer / laravel-js-localization

Simple, ease-to-use and flexible package for the Laravel web framework. Allows you to use localized messages of the Laravel webapp (see `resources/lang` directory) in your Javascript code.
MIT License
143 stars 51 forks source link

wrong behaviour when using replacements with same starting name #70

Open sebsobseb opened 4 years ago

sebsobseb commented 4 years ago

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 commented 4 years ago

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

bytestream commented 4 years ago

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

sebsobseb commented 4 years ago

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