问题描述
我们知道法语数字与英语相比使用,"作为小数点分隔符.
As we know french numbers use "," as decimal separators as compared to english.
例如:英语:10.25%是 法语:10,25%
eg: English : 10.25% is French : 10,25%
我能够成功将英语数字翻译成法语:
I am able to successfully translate english numbers to french:
number_with_precision(121.45, locale: :fr)
#=> 121,45
但是我无法将法语数字翻译成英语:
But I am not able to translate french numbers to english:
number = number_with_precision(121.45, locale: :fr)
number #=> 121,45
number = number_with_precision(number, locale: :en)
number #=> 121,45
该数字仍保留在法国语言环境中.
The number remains in french locale.
这是我的en.yml:
This is my en.yml:
en:
number:
format:
delimiter: ! ','
separator: '.'
significant: false
strip_insignificant_zeros: false
这是我的fr.yml:
this is my fr.yml:
fr:
number:
format:
delimiter: ! ','
separator: ','
significant: false
strip_insignificant_zeros: false
我的翻译文件中是否有错误导致该错误?
Is there a mistake in my translation file which is causing this?
推荐答案
您正在做的英语到法语"不是来自英语". 121.45
是Ruby数字文字,并且既不是英文也不是法语(尽管文字本身使用下划线表示分隔符,但英语本身也不像英文表示法那样使用小数点.)
What you are doing with what you consider as "English to French" is not "from English". 121.45
is a Ruby numeric literal, and is neither English nor French (although the literal itself uses a period for decimals like in the English notation although it uses underscore for delimiter, unlike English, which uses the comma).
在您所说的法语到英语"中,您正在传递法语格式的字符串.这就是为什么它不起作用的原因. number_with_precision
应该如何知道所传递的字符串是用法语表示的?
In what you called "French to English", you are passing a string in French format. That is why it does not work. How is number_with_precision
supposed to know that the string passed is written in French notation?
这篇关于数字的本地化(从法语语言环境到英语语言环境)在rails中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!