jquery/globalize 自定义格式化程序问题
jquery/globalize custom formatter issue
尝试格式化有效的 ICU 消息时
'Your open ticket count is {n, number}'
jquery/globalize 抛出异常:fmt 未定义(…)
使用 globalize-compiler 编译该消息没有错误,但在运行时失败。
使用 jquery/globalize 1.0.0 和 1.1.1
问题类似于:github.com/jquery/globalize/issues/563
更改 jquery/globalize ... globalize/message.js 源文件(添加单词 customFormatters)可消除错误...但更改第三方源文件在项目中是不可接受的。
Globalize.messageFormatter =
Globalize.prototype.messageFormatter = function( path, customFormatters ) {
...
formatter = new MessageFormat( cldr.locale, pluralGenerator, customFormatters ).compile( message )
下面的 npm 包也按预期处理消息格式。
https://www.npmjs.com/package/format-message
(我已经私信了 jquery/globalize 的 Rafael,他要求我 post 这里的问题)
题目:
有其他人遇到过这个问题吗?您的解决方法是什么?
是否有人将 jquery/globalize 用于基础 number/date/unit/etc 格式化程序,并使用其他库(如 'format-message' 进行消息格式化?
它将用于的项目是基于 nodejs 和浏览器的 (spa)。
切换到 Intl 和 polyfill 是一个有效的选择。 (需要 Safari 支持 http://caniuse.com/#search=intl )
是否有测试来评估通过 PR 添加 'customFormatters' 到源的性能成本。
使用变量 replacement instead,例如 'Your open ticket count is {n}'
和 Globalize.formatMessage('<message>', {n: Globalize.formatNumber(n)})
。
使用 Globalize,您可以使用各自的格式化程序格式化数字、日期、相对时间、单位等,而不是将其作为变量替换传递给消息。每个格式化程序都有自己的一组选项,因此您可以按照需要的方式自定义输出
因此,不同之处在于,您将能够在代码中定义格式,而不是在消息本身中。对所有这些格式化程序和消息格式化程序使用 Globalize 的一大优势是您可以使用 globalize-compiler to statically parse your code and generate very efficient precompiled code (small and fast code) to run on production. See also our app demo using webpack.
请注意,Intl(由今天的 ecma-402 定义)仅定义数字和日期格式化程序。它没有定义消息格式化程序、复数(很快将成为规范的一部分)、相对格式化程序等。因此您可能只找到前两个的 polyfil。
这部分还是很粗糙,但是一定要看全球化performance section。
PS:我已经更新了 https://github.com/jquery/globalize/issues/563 谢谢。
尝试格式化有效的 ICU 消息时
'Your open ticket count is {n, number}'
jquery/globalize 抛出异常:fmt 未定义(…)
使用 globalize-compiler 编译该消息没有错误,但在运行时失败。
使用 jquery/globalize 1.0.0 和 1.1.1
问题类似于:github.com/jquery/globalize/issues/563
更改 jquery/globalize ... globalize/message.js 源文件(添加单词 customFormatters)可消除错误...但更改第三方源文件在项目中是不可接受的。
Globalize.messageFormatter =
Globalize.prototype.messageFormatter = function( path, customFormatters ) {
...
formatter = new MessageFormat( cldr.locale, pluralGenerator, customFormatters ).compile( message )
下面的 npm 包也按预期处理消息格式。
https://www.npmjs.com/package/format-message
(我已经私信了 jquery/globalize 的 Rafael,他要求我 post 这里的问题)
题目:
有其他人遇到过这个问题吗?您的解决方法是什么?
是否有人将 jquery/globalize 用于基础 number/date/unit/etc 格式化程序,并使用其他库(如 'format-message' 进行消息格式化?
它将用于的项目是基于 nodejs 和浏览器的 (spa)。 切换到 Intl 和 polyfill 是一个有效的选择。 (需要 Safari 支持 http://caniuse.com/#search=intl )
是否有测试来评估通过 PR 添加 'customFormatters' 到源的性能成本。
使用变量 replacement instead,例如
'Your open ticket count is {n}'
和Globalize.formatMessage('<message>', {n: Globalize.formatNumber(n)})
。使用 Globalize,您可以使用各自的格式化程序格式化数字、日期、相对时间、单位等,而不是将其作为变量替换传递给消息。每个格式化程序都有自己的一组选项,因此您可以按照需要的方式自定义输出 因此,不同之处在于,您将能够在代码中定义格式,而不是在消息本身中。对所有这些格式化程序和消息格式化程序使用 Globalize 的一大优势是您可以使用 globalize-compiler to statically parse your code and generate very efficient precompiled code (small and fast code) to run on production. See also our app demo using webpack.
请注意,Intl(由今天的 ecma-402 定义)仅定义数字和日期格式化程序。它没有定义消息格式化程序、复数(很快将成为规范的一部分)、相对格式化程序等。因此您可能只找到前两个的 polyfil。
这部分还是很粗糙,但是一定要看全球化performance section。
PS:我已经更新了 https://github.com/jquery/globalize/issues/563 谢谢。