coderifous / jquery-localize

a jQuery plugin that makes it easy to internationalize your web site.
465 stars 142 forks source link

two bugs when loading from specific culture (e.g. zh-CN) #23

Closed SongChen closed 11 years ago

SongChen commented 11 years ago
  1. line 72: $.parseJSON(xhr.responseText) it tries to load xx-zh.json first, but it cannot find it at the first place, so the xhr.responseText will be empty. This causes jquery to throw error and stop.
  2. func: localizeInputElement should have a shortcut for null value otherwise, again, in the first try to find xx-zh.json, since it cannot find it, it will set remove existing placeholders and set its value instead.
artofbi commented 11 years ago

SongChen and Coderifous,

I have the same concern along those lines, so let's turn that into a question to see if we can get a response.

What is the easiest way to set the plugin so that it goes after the base locale only? I see one of the options is called "options.loadBase". This would call the full locale and country specific language passing the base locale file if this is set to false. However, it will call both if set to true.

How can we set a loadBaseOnly option in the code?

Any help is appreciated.

axis3d commented 11 years ago

Similar to Artofbi, is there a way to just load the locale without the country? I'm loading languages offline and I only have xx-en.json. It's just annoying on the debugger that it's still trying to load xx-en-US.json, when in fact I'm very aware that it's non-existent ? Thanks...

coderifous commented 11 years ago

The plugin tries to load everything that the language setting implies might be available. If you don't ever want the plugin to look for the region-specific language packs, then just truncate the region specifier from the language setting. For example, reduce "en-US" to just "en".

The plugin does some basic default language detection/setting and, for better or worse, makes that available via $.defaultLanguage. You should be able to avoid generating requests for the region-specific language packs by doing something like $(...).localize("foo", { language: $.defaultLanguage.substr(0,2) });