UserScript Translation Engine

Translate strings by given translations

Dette scriptet burde ikke installeres direkte. Det er et bibliotek for andre script å inkludere med det nye metadirektivet // @require https://update.greasyfork.org/scripts/7081/28938/UserScript%20Translation%20Engine.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Forfatter
Jixun.Moe
Versjon
1.0
Lagd
20.12.2014
Oppdatert
20.12.2014
Size
4,7 kB
Lisens
I/T

方便使用的翻译函数库。

代码演示

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: [
        [ ... ]
    ]
}

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