Javascript text strings
While adding "more and more" ajax/javascript things, we will have an increasing need to use localised strings in javascript, for the moment we are "throwing" them somehow at random into variables loaded around in the scripts, it may be worth starting consider some "long-term" solution to avoid conflicts, duplicates, and so on.
I'm not sure what's the "best" practice.
Re: Javascript text strings
Reply #1 –
The Wedge way is overkill right now for Elk. But since I've been caching and optimizing CSS and js for years now, Wess is very flexible when it comes to that and it rocks. Something to consider in the future I suppose. Of course, you'll have to maintain a cached js file per file per language.
Re: Javascript text strings
Reply #2 –
Especially since you have a cache/optimize solution now, use a Javascript language file. If it becomes too big (>100KB I would say), split it up.
Javascript localization
Reply #6 –
The more we use javascript, the more ugly arrays, objects or bunches of random variables are sent out to the client via the php files.
To me this doesn't seem very organized.
Honestly I'm not sure what's the best here, so I'm posting to hear if you have any experience and/or any idea.
At the moment, the only kind-of-organized thing we do, is have an action that builds a js file for the localization of the editor.
It's nice, but it doesn't feel "good" either (at least to me).
One possibility I was thinking about, is use one or more javascript/json/txt/whatever files that would be requested by the client.
Of course it's not a perfect solution either: it would potentially mean duplication of some strings and it may not allow "easy" adding of strings (I mean by mods). If it is one file, it also would mean the client has to download it and load it in memory (and I mean that for each page you'd have a file with potentially tons of unused strings just because you need one. On the other hand, multiple files would mean more requests.
Another possibility would be to keep the language strings in php and have an action that generates the strings, at the price of parsing more stuff through php at each page load.
Soo.... Comments? Opinions? Ideas? Previous experiences that may help?
Re: Javascript localization
Reply #8 –
I think two or three files would cover everything from regular user, moderator, and administrator. You could even combine moderator and administrator because they'll probably overlap.
Re: Javascript text strings
Reply #10 –
I think the first thing to do is compile all of the strings in a single Javascript file. Then break it apart based on what is needed. I think dozens of files is going to be a huge pain to maintain (rhymes hehe).