UserScript Translation Engine

Translate strings by given translations

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/7081/28938/UserScript%20Translation%20Engine.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Autore
Jixun.Moe
Versione
1.0
Creato il
20/12/2014
Aggiornato il
20/12/2014
Dimensione
4,65 KB
Licenza
Non disponibile

方便使用的翻译函数库。

代码演示

var Translator = new Translation (Translation.getLang(lang));

addEventListener ('DOMContentLoaded', function () {
    Translator.run ();
}, false);

其中,lang 为一个包含有所有可选语言的对象,如 { 'zh-CN': { ... }, zh: { ... }, ... }

每个语言的格式如下 (中间可随意消失,如 node.tag.SPAN.text 节点写到 node.tag.text 也是合法的):

node: {
    str: {
        '翻译前': '翻译后',

        regex: [
            [ /abc(\d)/, '$1' ]
        ]
    },

    tag: {
        SPAN: {
            '翻译前': '翻译后',

            regex: [ ... ]
        },
    }

    regex: [ ... ]
},

attr: {
    str: {
        '翻译前': '翻译后',

        regex: [ ... ]
    },

    attr: {
        tag: {
            TD: {
                title: {
                    regex: [ ... ]
                }
            }
        }
    }

    regex: [
        [ ... ]
    ]
}

所以说如果语言文件没有归类好就会很乱啦…