【问题标题】:I18n translation problemI18n 翻译问题
【发布时间】:2010-05-01 20:00:40
【问题描述】:

我即将把所有时区翻译成俄语,我已经做了这样的事情:

型号:

# lib/i18n_time_zone.rb
class I18nTimeZone < ActiveSupport::TimeZone
  def self.all
    super.map { |z| create(z.name, z.utc_offset) }
  end

  def to_s
    translated_name = I18n.t(name, :scope => :timezones, :default => name)
    "(GMT#{formatted_offset}) #{translated_name}"
  end
end

查看:

<%= time_zone_select :user, :time_zone, nil, :model => I18nTimeZone %>

语言环境文件(/config/locales/ru.yml):

ru:
  timezones:
    "Midway Island": "Мидуэй"
    "Samoa": "Самоа"
    ....

但有些情况下,原始字符串包含一些点(“.”),例如“St. Petersburg” I18n.t() 告诉我翻译丢失了。

如何避免?

【问题讨论】:

    标签: ruby-on-rails internationalization


    【解决方案1】:

    只需删除翻译键的点即可。

    def to_s
      translated_name = I18n.t(key, :scope => :timezones, :default => name)
      "(GMT#{formatted_offset}) #{translated_name}"
    end
    
    def key
      @key ||= name.gsub(/\./, "")
    end
    
    
    ru:
      timezones:
        "Midway Island": "Мидуэй"
        "Samoa": "Самоа"
        "St Petersburg" : "some one translate this"
    

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 1970-01-01
      • 2013-06-08
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多