UserScript Translation Engine

Translate strings by given translations

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @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!)

ავტორი
Jixun.Moe
ვერსია
1.0
შექმნილია
20.12.2014
განახლებულია
20.12.2014
Size
4,65 KB
ლიცენზია
პ/გ

方便使用的翻译函数库。

代码演示

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

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