MediaWiki:Gadget-I18n-js.js: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
m
add support for user-defined overrides
m (Use getUrl instead of deprecated wikiGetlink) |
m (add support for user-defined overrides) |
||
Line 4: | Line 4: | ||
* | * | ||
* @author Cqm <https://dev.wikia.com/User:Cqm> | * @author Cqm <https://dev.wikia.com/User:Cqm> | ||
* @version 0.3. | * @version 0.3.4 | ||
* | * | ||
* @notes Also used by VSTF wiki for their reporting forms (with a non-dev | * @notes Also used by VSTF wiki for their reporting forms (with a non-dev i18n.json page) | ||
*/ | */ | ||
Line 41: | Line 41: | ||
*/ | */ | ||
cache = {}, | cache = {}, | ||
/* | |||
* | |||
*/ | |||
overrides = {}, | |||
/* | /* | ||
Line 229: | Line 234: | ||
*/ | */ | ||
function getMsg(messages, name, lang) { | function getMsg(messages, name, lang) { | ||
// if the message has been overriden, use that without checking the language | |||
if (overrides[name]) { | |||
return overrides[name]; | |||
} | |||
if (messages[lang] && messages[lang][name]) { | if (messages[lang] && messages[lang][name]) { | ||
return messages[lang][name]; | return messages[lang][name]; | ||
Line 491: | Line 501: | ||
// expose under the dev global | // expose under the dev global | ||
window.dev.i18n = { | window.dev.i18n = window.dev.i18n || {}; | ||
window.dev.i18n = $.extend(window.dev.i18n, { | |||
loadMessages: loadMessages, | loadMessages: loadMessages, | ||
Line 500: | Line 511: | ||
_parse: parse, | _parse: parse, | ||
_fallbacks: fallbacks | _fallbacks: fallbacks | ||
}; | }); | ||
// initialise overrides object | |||
window.dev.i18n.overrides = {} | |||
overrides = window.dev.i18n.overrides; | |||
// fire an event on load | // fire an event on load |