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

From Tardis Wiki, the free Doctor Who reference
m
add in*Lang support
mNo edit summary
m (add in*Lang support)
Line 4: Line 4:
  *
  *
  * @author Cqm <https://dev.wikia.com/User:Cqm>
  * @author Cqm <https://dev.wikia.com/User:Cqm>
  * @version 0.4.0
  * @version 0.4.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 383: Line 383:
     */
     */
     function parse(message) {
     function parse(message) {
             // [url some text here] -> [$1 $2]
             // [url text] -> [$1 $2]
         var urlRgx = /\[((?:https?:)?\/\/.+?) (.+?)\]/g,
         var urlRgx = /\[((?:https?:)?\/\/.+?) (.+?)\]/g,
             // [[pagename]] -> [[$1]]
             // [[pagename]] -> [[$1]]
Line 408: Line 408:
     /*
     /*
     * Parse markdown links into HTML. Also supports basic inline HTML tags.
     * Parse markdown links into HTML. Also supports basic inline HTML tags.
    *
    * Will process:
    * - [text](url)
    * - [page]
    * - [text](page)
     *
     *
     * @param The message to process.
     * @param The message to process.
Line 517: Line 522:
     function i18n(messages, page) {
     function i18n(messages, page) {
         var defaultLang = conf.wgUserLanguage,
         var defaultLang = conf.wgUserLanguage,
            tempLang = null,
             messageKey = null,
             messageKey = null,
             parts;
             parts;
Line 529: Line 535:
             * Set the default language.
             * Set the default language.
             *
             *
             * @param lang the language code to use by default.
             * @param lang The language code to use by default.
             */
             */
             useLang: function (lang) {
             useLang: function (lang) {
                 defaultLang = lang;
                 defaultLang = lang;
            },
            /*
            * Set the language for the next msg call.
            *
            * @param lang The language code to use for the next `msg` call.
            *
            * @return The current object for use in chaining.
            */
            inLang: function (lang) {
                tempLang = lang;
                return this;
             },
             },


Line 541: Line 559:
                 defaultLang = conf.wgContentLanguage;
                 defaultLang = conf.wgContentLanguage;
             },
             },
            /*
            * Set the language for the next `msg` call to the content language.
            *
            * @return The current object for use in chaining.
            */
            inContentLang: function () {
                tempLang = conf.wgContentLanguage;
                return this;
            },


             /*
             /*
Line 547: Line 576:
             useUserLang: function () {
             useUserLang: function () {
                 defaultLang = conf.wgUserLanguage;
                 defaultLang = conf.wgUserLanguage;
            },
            /*
            * Set the language for the next msg call to the user's language.
            *
            * @return The current object for use in chaining.
            */
            inUserLang: function () {
                tempLang = conf.wgUserLanguage;
                return this;
             },
             },


Line 553: Line 592:
             */
             */
             msg: function () {
             msg: function () {
                 var args = Array.prototype.slice.call(arguments);
                 var args = Array.prototype.slice.call(arguments),
                    lang;
 
                if (tempLang !== null) {
                    lang = tempLang;
                    tempLang = null;
 
                    return message(messages, lang, args, messageKey);
                }
               
                 return message(messages, defaultLang, args, messageKey);
                 return message(messages, defaultLang, args, messageKey);
             },
             },
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.