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

Use toString() in localization.js? #52

Closed UpwardProcess closed 6 years ago

UpwardProcess commented 6 years ago

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

https://github.com/andywer/laravel-js-localization/commit/2ca47feb8c341bbaae5280fdc8aa16e8232627b2#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.

andywer commented 6 years ago

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

Would you mind opening a PR?

UpwardProcess commented 6 years ago

Hi @andywer.

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

Here is the PR: #53