I18n西班牙语翻译的本地化时间格式 [英] I18n localization time format for spanish translation

查看:271
本文介绍了I18n西班牙语翻译的本地化时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用I18n来对Rails应用程序进行本地化,并且遇到了涉及使用I18n进行时间格式的情况.

I am using I18n for localizing a rails application, and i came across a situation which involves time format using I18n.

显示的日期和时间格式如下:"Tuesday, July 11, 2017"表示时间:2017-07-11 12:30:00 +0530

the date and time format displaying is as follows: "Tuesday, July 11, 2017" for time : 2017-07-11 12:30:00 +0530

用于本地化,我使用两种时间格式的en.ymles.yml,如下所示:

for localizing i am using en.yml and es.yml with both time formats as shown below:

 en:
  time:
   formats:
     long: '%A, %B %d, %Y'
     short: '%b %d, %Y'

,并且在模型中,我使用的是I18n.l(raw_date.to_time, format: :long),对于英语,结果为"Tuesday, July 11, 2017",效果很好,但对于西班牙语,返回结果如下:"a, t 11, 2017"

and in model i am using I18n.l(raw_date.to_time, format: :long), this working fine for english with result "Tuesday, July 11, 2017", but for spanish its returning like this: "a, t 11, 2017"

西班牙语获得与英语相同的结果的日期时间格式是什么.任何帮助将不胜感激:)

what is the datetime format for spanish to get the same result as english. any help would be appreciated :)

推荐答案

查看 rails-i18n西班牙文文件,我已经将其中的一些翻译拉了过来,而且一切似乎都按预期进行(在添加这些翻译之前,我看到了同样的问题).

Looking at the rails-i18n spanish file, I've pulled a couple of their translations over and everything seems to be working as expected (I saw the same issue until I added these translations).

config/locales/es.yml

es:
  date:
    day_names:
      - domingo
      - lunes
      - martes
      - miércoles
      - jueves
      - viernes
      - sábado
    month_names:
      -
      - enero
      - febrero
      - marzo
      - abril
      - mayo
      - junio
      - julio
      - agosto
      - septiembre
      - octubre
      - noviembre
      - diciembre
  time:
    formats:
      long: '%A, %B %d, %Y'
      short: '%b %d, %Y'

,然后在控制台中:

I18n.locale = :es
I18n.l(Date.today.to_time, format: :long) # => "viernes, julio 21, 2017"

如果您要使用内置的rails进行大量翻译,我建议您查看文件的其余部分(甚至提取整个内容).

I recommend taking a look at the rest of their file (or even pulling in the entire thing) if you're doing a lot of translations with rails built in stuff.

注意:

  • 我不会说西班牙语,所以我假设他们的文件没问题
  • 如果您使用其他格式,可能还需要大量其他日期翻译

这篇关于I18n西班牙语翻译的本地化时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆