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

From Tardis Wiki, the free Doctor Who reference
m
keep options in obj instead of vars
(undo last changes - you can use [https://url text] for links (parse() isn't meant to have full wikitext support, just basics))
m (keep options in obj instead of vars)
Line 680: Line 680:
     * @param name The name of the script the messages are for.
     * @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 options Options set by the loading script.
     *
     *
     * @return The resulting i18n object.
     * @return The resulting i18n object.
     */
     */
     function parseMessagesToObject(name, res, cacheVersion) {
     function parseMessagesToObject(name, res, options) {
         var json = {},
         var json = {},
             obj,
             obj,
Line 708: Line 708:
         cache[name] = obj;
         cache[name] = obj;


         if (typeof cacheVersion === 'number') {
         if (typeof options.cacheVersion === 'number') {
             saveToCache(name, json, cacheVersion);
             saveToCache(name, json, options.cacheVersion);
         }
         }


Line 743: Line 743:
     *    used to get messages from
     *    used to get messages from
     *    https://dev.fandom.com/wiki/MediaWiki:Custom-name/i18n.json.
     *    https://dev.fandom.com/wiki/MediaWiki:Custom-name/i18n.json.
     * @param options Options that can be set by the loading script:
     * @param options Options set by the loading script:
     *    cacheVersion: Minimum cache version requested by the loading script.
     *    cacheVersion: Minimum cache version requested by the loading script.
     *    noCache: Never load i18n from cache (not recommended for general use).
     *    noCache: Never load i18n from cache (not recommended for general use).
Line 750: Line 750:
     */
     */
     function loadMessages(name, options) {
     function loadMessages(name, options) {
        options = options || {};
         var deferred = $.Deferred(),
         var deferred = $.Deferred(),
            useCache = (options.noCache || conf.debug) !== true,
            cacheVersion = Number(options.cacheVersion) || 0,
             customSource = name.match(/^u:(?:([a-z-]+)\.)?([a-z0-9-]+):/),
             customSource = name.match(/^u:(?:([a-z-]+)\.)?([a-z0-9-]+):/),
             apiEndpoint = 'https://dev.fandom.com/api.php',
             apiEndpoint = 'https://dev.fandom.com/api.php',
             page = 'MediaWiki:Custom-' + name + '/i18n.json',
             page = 'MediaWiki:Custom-' + name + '/i18n.json',
             params;
             params;
        options = options || {};
        options.cacheVersion = Number(options.cacheVersion) || 0;
        options.useCache = (options.noCache || conf.debug) !== true;


         // if using the special 'qqx' language code, there's no need to load
         // if using the special 'qqx' language code, there's no need to load
Line 766: Line 766:
         }
         }


         if (useCache) {
         if (options.useCache) {
             loadFromCache(name, cacheVersion);
             loadFromCache(name, options.cacheVersion);


             if (cache[name]) {
             if (cache[name]) {
Line 814: Line 814:
                 }
                 }


                 deferred.resolve(parseMessagesToObject(name, res, cacheVersion));
                 deferred.resolve(parseMessagesToObject(name, res, options));
             });
             });
         });
         });
Cookies help us deliver our services. By using our services, you agree to our use of cookies.