简体   繁体   English

Moment.js:获取术语“天”,“小时”,“秒”和“分钟”的翻译文本

[英]Moment.js: getting translated text for the terms “day”, “hour”, “second” and “minute”

Using moments.js, it is easily possible to set a language and then get various date strings and "calendar style" text translated to the desired language. 使用moments.js,可以轻松地设置一种语言,然后将各种日期字符串和“日历样式”文本转换为所需的语言。

However I could not find a way to get a translation to the "date components" themselves. 但是我找不到一种方法来自己翻译“日期组件”。 For example, I would want to sue something like: 例如,我想提起类似的诉讼:

moment.lang('en'); // set english
moment.dateComponent.hour() // yields "hour"
moment.dateComponent.hours() // yields "hours"
moment.dateComponent.day() // yields "day"
moment.dateComponent.days() // yields "days"
moment.lang('nl'); // set dutch
moment.dateComponent.hour() // yields "uur"
moment.dateComponent.hours() // yields "uur"
moment.dateComponent.day() // yields "dag"
moment.dateComponent.days() // yields "dagen"

Does anyone know of such a way? 有谁知道这种方式?

Note: I rather avoid getting the translations by doing string splitting on other methods for which the purpose is not getting the date component translated name. 注意:我宁愿避免对其他方法进行字符串拆分来获取翻译,而其他方法的目的不是获取日期组件的翻译名称。

I don't know moments.js so far, but if you have a look at the source code (See http://momentjs.com/downloads/moment-with-langs.js ), you will find you desired information. 到目前为止,我还不知道moments.js,但是如果您查看源代码(请参阅http://momentjs.com/downloads/moment-with-langs.js ),则会找到所需的信息。

So you can access some information directly 这样您就可以直接访问一些信息

moment().lang('en')._lang._months --> ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

quite usefull ... but 很有用...但是

moment().lang('en')._lang._relativeTime.hh --> "%d hours"

does not store the information atomar. 不存储原子信息。 Since the languages are differently and can not be build this way! 由于语言不同,因此无法通过这种方式构建!

As you can see that this information is not accessible like you want. 如您所见,无法按需要访问此信息。 Use a translation javascript for your "words". 为您的“单词”使用翻译javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM