MediaWiki:Gadget-I18n-js.js: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
fix issues with not-existing messages when using "qqx" language
(optimise i18n cache by only keeping messages for the user and content languages)
(fix issues with not-existing messages when using "qqx" language)
Line 6: Line 6:
  * @author OneTwoThreeFall <https://dev.fandom.com/User:OneTwoThreeFall>
  * @author OneTwoThreeFall <https://dev.fandom.com/User:OneTwoThreeFall>
  *
  *
  * @version 0.6.0
  * @version 0.6.1
  *
  *
  * @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 456: Line 456:
         var msgName = args.shift(),
         var msgName = args.shift(),
             noMsg = '<' + msgName + '>',
             noMsg = '<' + msgName + '>',
             msg;
             msg = getMsg(messages, msgName, lang),
            msgExists = msg !== noMsg;


         if (conf.wgUserLanguage === 'qqx') {
         if (conf.wgUserLanguage === 'qqx' && msgExists) {
             // 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-' + name + '-' + msgName + ')';
             msg = '(i18njs-' + name + '-' + msgName + ')';
Line 464: Line 465:
             // 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[name][msgName];
             msg = overrides[name][msgName];
        } else {
            msg = getMsg(messages, msgName, lang);
         }
         }


Line 476: Line 475:
             * Boolean representing whether the message exists.
             * Boolean representing whether the message exists.
             */
             */
             exists: msg !== noMsg,
             exists: msgExists,


             /*
             /*
Line 844: Line 843:
         options.language = options.language || conf.wgUserLanguage;
         options.language = options.language || conf.wgUserLanguage;
         options.useCache = (options.noCache || conf.debug) !== true;
         options.useCache = (options.noCache || conf.debug) !== true;
        // if using the special 'qqx' language code, there's no need to load
        // the messages, so resolve with an empty i18n object and return early
        if (conf.wgUserLanguage === 'qqx') {
            return deferred.resolve(i18n({}, name, options));
        }


         if (options.useCache) {
         if (options.useCache) {
Cookies help us deliver our services. By using our services, you agree to our use of cookies.