MediaWiki:Gadget-I18n-js.js: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
m
use consistent var names across different functions, for readability
(support overrides for non-dev i18n pages (no real reason to block that, imo)) |
m (use consistent var names across different functions, for readability) |
||
Line 249: | Line 249: | ||
* requested language. | * requested language. | ||
* | * | ||
* @param messages | * @param messages The message object to look translations up in. | ||
* @param | * @param msgName The name of the message to get. | ||
* @param lang The language to get the message in. | * @param lang The language to get the message in. | ||
* | * | ||
Line 256: | Line 256: | ||
* message could be found. | * message could be found. | ||
*/ | */ | ||
function getMsg(messages, | function getMsg(messages, msgName, lang) { | ||
if (messages[lang] && messages[lang][ | if (messages[lang] && messages[lang][msgName]) { | ||
return messages[lang][ | return messages[lang][msgName]; | ||
} | } | ||
if (lang === 'en') { | if (lang === 'en') { | ||
return '<' + | return '<' + msgName + '>'; | ||
} | } | ||
lang = fallbacks[lang] || 'en'; | lang = fallbacks[lang] || 'en'; | ||
return getMsg(messages, | return getMsg(messages, msgName, lang); | ||
} | } | ||
Line 329: | Line 329: | ||
* @param html | * @param html | ||
* | * | ||
* @return | * @return The sanitised HTML code. | ||
*/ | */ | ||
function sanitiseHtml(html) { | function sanitiseHtml(html) { | ||
Line 444: | Line 444: | ||
* Create a new Message instance. | * Create a new Message instance. | ||
* | * | ||
* @param | * @param messages The message object to look translations up in. | ||
* @param | * @param lang The language to get the message in. | ||
* @param args Any arguments to substitute into the message. | * @param args Any arguments to substitute into the message, [0] is message name. | ||
* @param | * @param name The name of the script the messages are for. | ||
*/ | */ | ||
function message(messages, | function message(messages, lang, args, name) { | ||
if (!args.length) { | if (!args.length) { | ||
return; | return; | ||
Line 460: | Line 460: | ||
if (conf.wgUserLanguage === 'qqx') { | if (conf.wgUserLanguage === 'qqx') { | ||
// https://www.mediawiki.org/wiki/Help:System_message#Finding_messages_and_documentation | // https://www.mediawiki.org/wiki/Help:System_message#Finding_messages_and_documentation | ||
msg = '(i18njs-' + | msg = '(i18njs-' + name + '-' + msgName + ')'; | ||
} else if (overrides[ | } else if (overrides[name] && overrides[name][msgName]) { | ||
// if the message has been overridden, use that without checking the language | // if the message has been overridden, use that without checking the language | ||
msg = overrides[ | msg = overrides[name][msgName]; | ||
} else { | } else { | ||
msg = getMsg(messages, msgName, | msg = getMsg(messages, msgName, lang); | ||
} | } | ||
Line 517: | Line 517: | ||
* | * | ||
* @param messages The message object to look translations up in. | * @param messages The message object to look translations up in. | ||
* @param name | * @param name The name of the script the messages are for. | ||
*/ | */ | ||
function i18n(messages, name) { | function i18n(messages, name) { | ||
Line 657: | Line 657: | ||
* Save messages string to local storage for caching. | * Save messages string to local storage for caching. | ||
* | * | ||
* @param name | * @param name The name of the script the messages are for. | ||
* @param json The JSON object. | * @param json The JSON object. | ||
* @param cacheVersion Cache version requested by the loading script. | * @param cacheVersion Cache version requested by the loading script. | ||
Line 679: | Line 679: | ||
* Parse JSON string loaded from page and create an i18n object. | * Parse JSON string loaded from page and create an i18n object. | ||
* | * | ||
* @param name | * @param name The name of the script the messages are for. | ||
* @param res The JSON string. | * @param res The JSON string. | ||
* @param cacheVersion Cache version requested by the loading script. | * @param cacheVersion Cache version requested by the loading script. | ||
Line 719: | Line 719: | ||
* Load messages string from local storage cache and add to cache object. | * Load messages string from local storage cache and add to cache object. | ||
* | * | ||
* @param name | * @param name The name of the script the messages are for. | ||
* @param minCacheVersion Minimum cache version requested by the loading script. | * @param minCacheVersion Minimum cache version requested by the loading script. | ||
*/ | */ |