Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong behaviour when using replacements with same starting name #70

Open
sebsobseb opened this issue Feb 26, 2020 · 3 comments
Open

wrong behaviour when using replacements with same starting name #70

sebsobseb opened this issue Feb 26, 2020 · 3 comments
Labels

Comments

@sebsobseb
Copy link

sebsobseb commented Feb 26, 2020

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

@andywer andywer added the bug label Feb 27, 2020
@sebsobseb
Copy link
Author

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

@bytestream
Copy link
Contributor

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

@sebsobseb
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants