MediaWiki:Gadget-I18n-js.js: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
don't try to optimise messages loaded from cache (this prevented i18n-js realising its cache wasn't suitable when user/content language changed and a cache exists)
(use "i18njs-ScriptName-" prefix for messages that don't exist, for easier identification (note this may affect scripts that assumed <msgName> meant a msg didn't exist - instead, check the `exists` property); deduplicate msg code in `optimiseMessages`) |
(don't try to optimise messages loaded from cache (this prevented i18n-js realising its cache wasn't suitable when user/content language changed and a cache exists)) |
||
Line 6: | Line 6: | ||
* @author OneTwoThreeFall <https://dev.fandom.com/User:OneTwoThreeFall> | * @author OneTwoThreeFall <https://dev.fandom.com/User:OneTwoThreeFall> | ||
* | * | ||
* @version 0.6. | * @version 0.6.6 | ||
* | * | ||
* @notes Also used by VSTF wiki for their reporting forms (with a non-dev i18n.json page) | * @notes Also used by VSTF wiki for their reporting forms (with a non-dev i18n.json page) | ||
Line 843: | Line 843: | ||
} | } | ||
if (options.useCache && options.cacheAll !== true) { | if ( | ||
options.useCache && | |||
options.loadedFromCache === false && | |||
options.cacheAll !== true | |||
) { | |||
json = optimiseMessages(name, json, options); | json = optimiseMessages(name, json, options); | ||
} | } | ||
Line 852: | Line 856: | ||
cache[name] = obj; | cache[name] = obj; | ||
if ( | if (!options.loadedFromCache) { | ||
saveToCache(name, json, options.cacheVersion); | saveToCache(name, json, options.cacheVersion); | ||
} | } | ||
Line 877: | Line 881: | ||
// cache exists, and its version is greater than or equal to requested version | // cache exists, and its version is greater than or equal to requested version | ||
if (cacheContent && cacheVersion >= options.cacheVersion) { | if (cacheContent && cacheVersion >= options.cacheVersion) { | ||
options.loadedFromCache = true; | |||
parseMessagesToObject(name, cacheContent, options); | parseMessagesToObject(name, cacheContent, options); | ||
} | } | ||
Line 915: | Line 919: | ||
} | } | ||
} | } | ||
// cache isn't suitable - loading from server | |||
options.loadedFromCache = false; | |||
// allow custom i18n pages to be specified on other wikis | // allow custom i18n pages to be specified on other wikis |