【问题标题】:Moment.js: only certain localizationsMoment.js:只有某些本地化
【发布时间】:2015-02-24 23:46:56
【问题描述】:

我正在寻找一种方法将momentjs 包含在本地化(在我的情况下为德语)中,但不包含在所有其他本地化(40kb 缩小版)中,以使其保持苗条。是否可以排除所有其他本地化,但一个特定的?

【问题讨论】:

    标签: javascript jquery html angularjs momentjs


    【解决方案1】:

    根据moment.js docs:在浏览器中加载语言环境只需要包含语言环境文件。

    <script src="moment.js"></script>
    <script src="locale/fr.js"></script>
    <script src="locale/pt.js"></script>
    <script>
       moment.locale('fr');  // Set the default/global locale
      // ...
    </script>
    

    此外,如果您愿意,您可以构建一个与您选择的语言环境捆绑在一起的缩小的 moment.js 版本。

    grunt embedLocales --embedLocales de
    

    更新:

    如 cmets 中所述并根据 contribution guide 运行此命令:

    grunt transpile:fr,ru
    

    将导致自定义语言环境包 moment-with-locales.custom.jslocales.custom.jsbuild/umd/min 内仅包含法语和俄语。

    【讨论】:

    • 也许自 12 月以来 grunt 文件发生了变化,但我不得不写 grunt release --embedLocales degrunt embedLocales ... 抛出错误。
    • documentationgrunt transpile:fr,ru 在 build/umd/min 中构建自定义语言环境包 moment-with-locales.custom.js 和 locales.custom.js,仅包含法语和俄语。跨度>
    猜你喜欢
    • 2017-05-26
    • 1970-01-01
    • 2016-09-27
    • 2014-06-14
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多