mirror of
https://github.com/moodle/moodle.git
synced 2025-07-05 22:46:33 +02:00
This is the same problem that we had in MDL-52486. When the language pack with multiple underscores (such as "en_us_k12") is selected, the html root element's "lang" attribute is set to <html lang="en-us-12" ...> which we then map back to the Moodle lang code using the JS function replace(). What was missed in MDL-52486 was that when replacing a value (and not a regular expression), only the first instance of the value is replaced. So the value "en_us-k12" was sent as the lang parameter for the core_string, which is invalid PARAM_LANG value and the exception was thrown. In case of the user_date.js, there was no actual problem experienced and probably there is none as the language code is used as a cache key rather than a PARAM_LANG parameter. But we are changing it too for consistency.
1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
define(["jquery","core/ajax","core/localstorage"],function(a,b,c){var d=[];return{get_string:function(a,b,c,d){var e=this.get_strings([{key:a,component:b,param:c,lang:d}]);return e.then(function(a){return a[0]})},get_strings:function(e){var f,g=a.Deferred(),h=[],i=0,j=!1;for(i=0;i<e.length;i++)if(f=e[i],"undefined"==typeof f.lang&&(f.lang=a("html").attr("lang").replace(/-/g,"_")),f.cacheKey="core_str/"+f.key+"/"+f.component+"/"+f.lang,"undefined"==typeof M.str[f.component]||"undefined"==typeof M.str[f.component][f.key]){var k=c.get(f.cacheKey);k?("undefined"==typeof M.str[f.component]&&(M.str[f.component]=[]),M.str[f.component][f.key]=k):j=!0}if(j){var l=[],m=[],n=function(a){this.resolve(a)},o=function(a){this.reject(a)};for(i=0;i<e.length;i++)if(f=e[i],"undefined"!=typeof d[f.cacheKey])m.push(d[f.cacheKey]);else{var p=a.Deferred();l.push({methodname:"core_get_string",args:{stringid:f.key,component:f.component,lang:f.lang,stringparams:[]},done:n.bind(p),fail:o.bind(p)}),d[f.cacheKey]=p.promise(),m.push(d[f.cacheKey])}l.length>0&&b.call(l,!0,!1),a.when.apply(null,m).done(function(){var a=0;for(a=0;a<arguments.length;a++)f=e[a],"undefined"==typeof M.str[f.component]&&(M.str[f.component]=[]),M.str[f.component][f.key]=arguments[a],c.set("core_str/"+f.key+"/"+f.component+"/"+f.lang,arguments[a]),h[a]=M.util.get_string(f.key,f.component,f.param).trim();g.resolve(h)}).fail(function(a){g.reject(a)})}else{for(i=0;i<e.length;i++)f=e[i],h[i]=M.util.get_string(f.key,f.component,f.param);g.resolve(h)}return g.promise()}}}); |