简体   繁体   中英

Rails I18n.l wants a yaml file for every time zone…but why?

I just added a field time_zone to my user model and filled it with UTC + 01:00 and, on a second try, with 'Bern' just to test things.

Before I set this time zone thing, calls in a view like l @date, :format => :short were no problem because it took the format from my {locale}.yml file. But now, after adding time_zone, rails is looking for a {time_zone}.yml file for date conversion formats.

I don't see the real sense behind this. I know that different countries display dates and times in a different way than others. But is creating a file for each time zone the right solution, especially when a lot of time zones will have the same display format? I don't think this is DRY.

However, I need to work with time zones because dates are wrong displayed. How can I keep the behaviour of working with {locale}.yml files and... just define a time zone which converts dates displayed to the right value?

一种可能的解决方案是创建{time_zone} .yml文件作为指向{locale} .yml文件的链接,因此您只需维护一个文件,而不是两个文件(我假设{time_zone} .yml所需的字段在{locale} .yml中)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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