Config dimension myMojit - 1950195/simple-mojito GitHub Wiki

Mojito application 中的 dimensions.json 默认位置在 node_modules/mojito/lib/dimensions.json

我们可以根据自己的需要自定义 dimensions.json

项目根目录下创建文件并编辑: dimensions.json

[
    {
        "dimensions": [
            {
                "runtime": {
                    "common": {
                        "server": null
                    }
                }
            },
            {
                "environment": {
                    "development": {
                        "dev": null,
                        "test": null
                    },
                    "production": {
                        "stage": null,
                        "prod": null
                    }
                }
            },
            {
                "lang": {
                    "en": null,
                    "es": null,
                    "fr": null,
                    "zh": null
                }
            }
        ]
    }
]

在 mojits/myMojit/ 下创建 lang 目录,并创建以下文件并编辑: myMojit_en.js

YUI.add("lang/myMojit_en", function (Y) {
    Y.Intl.add(
        "myMojit",  // associated module
        "en",       // BCP 47 language tag
        // key-value pairs for this module and language
        {
            GREETING: "hello__",
            SAYS: "says",
            PREPOSITION: "at"
        }
    );
}, "3.1.0", {requires: ['intl']});

myMojit_es.js

YUI.add("lang/myMojit_es", function (Y) {
    Y.Intl.add(
        "myMojit",  // associated module
        "es",       // BCP 47 language tag
        // key-value pairs for this module and language
        {
            GREETING: "hola",
            SAYS: "dice",
            PREPOSITION: "en"
        }
    );
}, "3.1.0", {requires: ['intl']});

myMojit_fr.js

YUI.add("lang/myMojit_fr", function (Y) {
    Y.Intl.add(
        "myMojit",  // associated module
        "fr",       // BCP 47 language tag
        // key-value pairs for this module and language
        {
            GREETINGS: "salut",
            SAYS: "dit",
            PREPOSITION: "à"
        }
    );
}, "3.1.0", {requires: ['intl']});

myMojit_zh.js

YUI.add("lang/myMojit_zh", function (Y) {
    Y.Intl.add(
        "myMojit",  // associated module
        "zh",       // BCP 47 language tag
        // key-value pairs for this module and language
        {
            GREETING: "你好__",
            SAYS: "说",
            PREPOSITION: "在"
        }
    );
}, "3.1.0", {requires: ['intl']});

编辑 mojits/myMojit/views/index.hb.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>myMojit Index Page</title>
</head>
<body>
    <h3>{{name}} {{says}} {{greeting}} {{preposition}} {{today}}</h3>
</body>
</html>

启动 mojito

$ mojito start

打开浏览器,输入网址: http://localhost:8666/my

可以在url后加不同的语言参数:

?lang=en
?lang=es
?lang=fr
?lang=zh
⚠️ **GitHub.com Fallback** ⚠️