Using localization for client side

4 years ago
Most of the code that's there on client side includes hard coded messages in English language. For localization purposes, they should be moved to a separate javascript object through a view and then that object should be used inside scripts.


That I believe is a nice way to avoid hardcoding any English literals in the script files.

For example in public.onepagecheckout.js on line 333 we see something like this

validate: function () {
        var methods = document.getElementsByName('paymentmethod');
        if (methods.length == 0) {
            alert('Your order cannot be completed at this time as there is no payment methods available for it.');
            return false;
        }


This can easily be replaced by

validate: function () {
        var methods = document.getElementsByName('paymentmethod');
        if (methods.length == 0) {
            alert(localized_data.NoPaymentMethodsError);
            return false;
        }


where localized_data is a javascript object parameter that'll be passed from the view itself.
4 years ago
Hi Anshul,

Thanks a lot for suggestion. I've just created a work item
4 months ago
Done. Please see this commit.