andywer/laravel-js-localization

Use toString() in localization.js?

UpwardProcess opened this issue · 2 comments

The applyReplacements function in resources/js/localization.js has some minor changes in the following commit:

2ca47fe#diff-a3095dfb9ac91acd2bb0a74831fa7c7d

These changes are using string functions like toUpperCase() without using toString() on the value first which results in passing numeric values as translation parameters to be broken.

For example, using the following code results in a TypeError: i.toUpperCase is not a function error:

Lang.get('general.number_of_rows', {number: 10})

I would suggest adding toString() before using any string functions to make the JS library backward compatible.

Hi @UpwardProcess. Good point!
String(value) would be even safer than value.toString().

Would you mind opening a PR?

Hi @andywer.

You are right! String(value) is even better.

Here is the PR: #53