【问题标题】:Rails i18n: Translation missing problem, locale not definedRails i18n:翻译缺失问题,未定义语言环境
【发布时间】:2011-01-25 16:52:05
【问题描述】:

我的 Rails 2.3.8 应用程序有问题。我正在使用 rails i18n 来制作不同语言的网站。一切都完美无缺,除了一个地方。

注册成功后,我会这样做:

flash[:notice] = t 'path.to.locale.key'

就像我在其他地方所做的那样。

但这会呈现以下内容:

translation missing: 'locale.path.to.locale.key' not found

它似乎没有加载当前的语言环境(否则它会说“en”或“es”,或者其他什么而不是“语言环境”)。

有什么可能导致这种情况的想法吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails internationalization locale


    【解决方案1】:

    也许你在那个 yml 文件的某个地方覆盖它。也许你做了太多的嵌套。也许那个键有子键。

    从该 locale.yml 中删除所有内容并仅放置该消息并查看它是否有效。

    你遇到的问题时不时地发生在我身上,而且总是我在 yml 文件中搞砸了。

    【讨论】:

      【解决方案2】:

      尝试在 ApplicationController 中设置默认语言环境,例如使用 before_filter:

      I18n.locale = params[:locale] || 'en'
      

      【讨论】:

        【解决方案3】:

        嗯,这发生在我升级到 Rails 4.1 后的邮件类中。它在 Rails 3 上正常工作,并且 yml 文件没有变化。不知何故 i18n 没有看到默认的语言环境。 所以我在邮件类中添加了这一行来修复。

         I18n.locale = I18n.default_locale
        
        class ProviderMailer < ActionMailer::Base
          include Resque::Mailer
          default from: APP_CONFIG.mailer.from
        
          def registration_email(provider)
            @provider = provider
            I18n.locale = I18n.default_locale
            @provider_url  = "#{APP_CONFIG.base_url}/hizmetsgl/#{provider['_id']}"
            @howto_url  = "#{APP_CONFIG.base_url}/hizmetverenler"
            mail(to: provider["business_email"], subject: t('provider_mailer.registration_email.subject')) 
          end
        
        end
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-03-25
          • 1970-01-01
          • 1970-01-01
          • 2021-08-15
          • 1970-01-01
          • 1970-01-01
          • 2022-10-03
          • 2023-04-07
          相关资源
          最近更新 更多