我正在尝试全球化。以下是我目前的项目配置:
- 目前我没有使用 node 环境,特别是没有使用 npm 或 bower,而是使用 NuGet 作为包管理器。
- 模组系统:AMD
- 在应用程序启动时,
require.js
.config()
用于指定不同外部模块的路径。 - 在实际的应用程序(类型)脚本中,使用,
import {...} from "...";
来加载依赖项
只是想知道是否有一种方法可以在我的项目中使用Globalize
和cldr
避免 npm 和 bower?
编辑
所以这就是我最后的做法:
我需要 js 配置:
require.config({ baseUrl: baseUrl, paths: { /*requirejs plugins*/ 'json': baseUrl + "/Scripts/requirejs-plugins/json", 'text': baseUrl + "/Scripts/text", /*CLDR and Globalize*/ 'cldr': baseUrl + "/Scripts/cldr", 'cldr/event': baseUrl + "/Scripts/cldr/event", 'cldr/supplemental': baseUrl + "/Scripts/cldr/supplemental", 'cldr/unresolved': baseUrl + "/Scripts/cldr/unresolved", 'cldr-data': baseUrl + "/Content/cldr-data", 'Globalize': baseUrl + "/Scripts/globalize", 'Globalize.number': baseUrl + "/Scripts/globalize/number", 'Globalize.date': baseUrl + "/Scripts/globalize/date" }, shim: { 'cldr': { exports: "cldr" }, 'cldr/event': { deps: ["cldr"] }, 'cldr/supplement': { deps: ["cldr"] }, 'cldr/unresolved': { deps: ["cldr"] }, 'Globalize': { deps: [ "cldr", "json!cldr-data/supplemental/likelySubtags.json", "json!cldr-data/main/en/numbers.json", "json!cldr-data/main/en/ca-gregorian.json" ], exports: "Globalize" }, 'Globalize.number': { deps: [ "cldr", "Globalize", "cldr/event", "cldr/supplemental" ] }, 'Globalize.date': { deps: [ "cldr", "Globalize", "Globalize.number", "cldr/event", "cldr/supplemental" ] } } }); require(["cldr", "Globalize", "Globalize.number", "Globalize.date"], function() { });
显然我还需要更改
number.js
anddate.js
如下:number.js
:...// AMD define([ "cldr", //"../globalize", "Globalize", "cldr/event", "cldr/supplemental" ], factory );...
date.js
:...// AMD define([ "cldr", /*"../globalize", "./number",*/ "Globalize", "Globalize.number", "cldr/event", "cldr/supplemental" ], factory );...
最后像这样使用它:
const Globalize = require("Globalize"); //Following dependencies can also be loaded by seperate http call to server, such as $.ajax const likelySubtags = require("json!cldr-data/supplemental/likelySubtags.json"); const enNumbers = require("json!cldr-data/main/en/numbers.json"); const enGregorianCal = require("json!cldr-data/main/en/ca-gregorian.json"); ... Globalize.load(likelySubtags); Globalize.load(enNumbers); Globalize.load(enGregorianCal); var globEn = Globalize("en"); var numFormatter = globEn.numberFormatter({ maximumFractionDigits:2}); console.log(".numberFormatter()(Math.PI)->", numFormatter(Math.PI)); var dateFormatter = globEn.dateFormatter({ skeleton: "GyMMMdhms" }); console.log("dateFormatter(new Date())->", dateFormatter(new Date()));
仍然希望收到您的来信:)