问题标签 [ecmascript-intl]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
343 浏览

javascript - 对于具有多个“字母顺序”的语言,我如何确定浏览器支持 Intl.Collat​​or 的哪些排序规则变体?

JavaScript ES6/Harmony 现在具有特定于语言的排序/整理。

现在浏览器的支持有所不同,所以我在 Chrome 中找到了一些我使用的语言,而另一些则没有。

但我遇到的问题是芬兰语、日语、西班牙语和瑞典语等语言,它们有不止一种排序文本的方式,找到浏览器支持的方式?

0 投票
1 回答
1176 浏览

javascript - Javascript Intl DatetimeFormatter 作为 (ISO_8601|custom) 输出模式

我想使用Intl.DateTimeFormat但使用自定义模式进行输出。我将此方法用于 ICU 日期格式的 php 版本,并且效果很好。

我如何将模式设置为 Intl.DateTimeFormat 中的 ICU 文档,例如 ICU 日期时间格式化程序的 php 版本。

我的 JavaScript 代码

如何在我的 javascript 格式模式中使用 iset ISO_8601 模式,例如EEEE d MMMM yyyy HH:mmorMM yy dd或等?

ISO_8601

PHP IntlDateFormatter::格式

ICU日期格式化程序

ICU 日期格式

0 投票
1 回答
259 浏览

javascript - Formatting Number and dates dilemma

My app is using :

  • ASP.NET Http Handler for the back-end in order to read the data from MySql database and return them in JSON format
  • React.js app for the front-end to display the data in the browsers. The app is built by using webpack.

Several pages of the app display Dates and Numbers and I would like to format them according to the browser's preferred language. I found that the cutting edge for this feature is ECMAScript Internationalization API and its polyfill Intl.js : https://github.com/andyearnshaw/Intl.js. I added it in my app's dependencies and used for formatting, for example:

So far so good, but then I found that the size of the minified bundle.js increases significantly after adding Intl.js in dependencies : 300Kb raised to 900kb! I understand that it happens because locale-data folder(https://github.com/andyearnshaw/Intl.js/tree/master/locale-data) is automatically added at runtime and it is really needed, but I still can't accept that fact that the size of app's script raised 3 times just because it needs to display formatted dates and numbers... So, I am thinking about delegating the formatting to the server side so that it returns Dates and Numbers as formatted strings within the Json response. That's quite easy to implement and I can see a couple of perks of this approach:

  • Preserving the small size of app
  • Possible performance improvements

but I don't see any obvious shortcomings and that's suspicious. So, my question is - what are the disadvantages of formatting dates and numbers on server side and sending them as formatted strings within the Json response?

0 投票
2 回答
2454 浏览

javascript - 节点:无法替换 Intl 以使用 IntlPolyfill

我正在尝试将 Intl 与 pt-BR 语言环境一起使用,但无法使其与 Node 0.12 一起使用。

代码:

此代码输出:

May, 2015

我希望那是:'Maio,2015'。

然后,如果我决定创建一个新变量,一切正常:

工作代码:

这将打印出期望值。问题:为什么 Intl 全局变量没有被替换?

0 投票
5 回答
7090 浏览

javascript - 如何使用 Intl 获取工作日名称?

我想在我的 i18n-ed 应用程序中显示 7 个工作日的列表:

我依靠Intl 全局对象来格式化日期/时间,但我找不到一种获取工作日名称的简单方法。

我想我可以在 EPOCH 时间上增加几天,以达到一周的第一天,但​​我找不到仅在工作日打印的格式化程序。

输出:

期望的输出:

我也想有一个较短的版本,例如Sun, Mon, Tue....

或者,有没有办法从 获取工作日字符串Intl?我试图通过控制台探索该对象,但找不到它们。

0 投票
1 回答
3794 浏览

javascript - Where does Intl API get it's time zone list?

I'm relying on Intl to determine user's time zone.

I also want to give users a way to pick their timezone. I have a list of time zones -- some subset of Olson database.

I wanna make sure Intl won't give me some weird time zone I don't have in my list.

Where does Intl API get it's time zone list? Is there a way to list all of them or does it trust the browser?

0 投票
2 回答
306 浏览

javascript - 将 `new Intl.NumberFormat("es-ES").format(3500)` 格式化为 `3 500` 时,Firefox 41 是否存在错误?

在尝试熟悉不同浏览器对数字格式的支持时,我发现 Firefox 41 格式new Intl.NumberFormat("es-ES").format(3500)3 500(以空格作为组分隔符),而 IE 11、Edge 和 Google Chrome 给了我3.500(以点.作为组分隔符) .

我想知道,这是Firefox中的错误吗?还是西班牙允许的数字格式不明确?

0 投票
1 回答
1398 浏览

javascript - String.toLocaleUpperCase():在 Node.js 上设置语言环境

JavaScript StringtoLocaleUpperCase()方法应该考虑不同语言环境的大小写映射,例如土耳其语(i 不是映射到无点 I,而是映射到土耳其语中的点 İ)。

但是,似乎仅从操作系统捕获了区域设置:我看不到设置区域设置的方法。因此,如果我使用的是 en-US 操作系统并且想要toLocaleUpperCase()在“tr”中使用土耳其语字符串,它将返回 en-US 版本(无点 I,而不是点 İ)。

假设我使用的是用 INTL ( https://github.com/nodejs/node/wiki/Intl ) 编译的 Node.js,我该如何定义语言环境toLocaleUpperCase()

0 投票
2 回答
2821 浏览

javascript - 如何查看给定 Node.js 版本支持的语言环境以及如何启用缺少的语言环境?

我在 Windows 8.1 上的 Node.js 版本是:

但它似乎不支持语言环境识别和协商。我的意思是ECMAScript Internationalization API的支持。仅en支持语言环境。这是浏览器和 Node.js 中的示例。在浏览器中,可以很好地识别语言环境:

但是在 Node.js 中它不起作用。Node.js 对和都返回相同的en格式:enru

有没有办法查看给定的 Node.js 支持哪些语言环境以及如何启用所需的语言环境?

0 投票
1 回答
329 浏览

javascript - 使用 Webpack 进行 Intl polyfill 的代码拆分

我正在尝试为intlpolyfill 创建一个包,以便仅为需要它的浏览器加载它。

使用以下代码,它在我的输出文件夹中创建包

我注意到的第一件事是文件的大小很大,它包含所有语言,有没有办法定义我想要的语言?

另一个问题是,当浏览器尝试下载文件时,它会从我的应用程序的根文件夹中尝试。所以不是下载http://mydomain/js/1.intl-bundle.js,而是尝试获取http://mydomain/1.intl-bundle.js

有没有办法设置从哪里下载文件?

我的webpack.config.js输出如下所示:

最后一个问题,我可以删除1.文件名开头的intl-bundle.js吗?

谢谢