【问题标题】:I18n translation missing only for admin仅管理员缺少 I18n 翻译
【发布时间】:2012-03-15 23:24:47
【问题描述】:

我尝试翻译我的网络应用程序并遵循本指南:Ruby on Rails Guides

我为我的语言(希腊语)制作了我的 el.yml,我的 Gemfile 有 gem 'rails-i18n' 并且我在 application_controller 中的代码有

 before_filter :set_locale

 def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
 end

def default_url_options(options={})
    logger.debug "default_url_options is passed options: #{options.inspect}\n"
{ :locale => I18n.locale }
end

在我的 application.html.erb 我使用

 <%= l(Time.now, :format => :short) %></p

一切正常,我的用户用希腊语查看时间。但是来自用户的前 5 个 id 是 admins 和 admins_controller 处理文章。当一个管理员看的时候采取这个错误:

I18n::MissingTranslationData in Admin#articles
Showing /home/panagiotis/projects/diplomatiki/app/views/layouts/application.html.erb where line #43 raised:
translation missing: el?state=4.time.formats.short

-

class AdminController < ApplicationController

class ApplicationController < ActionController::Base

都可以使用 ApplicationController 为什么不使用 AdminController(继承)?

【问题讨论】:

    标签: ruby-on-rails-3 internationalization


    【解决方案1】:

    我的问题的最终解决方案删除了​​以下代码

    before_filter :set_locale
    
    def set_locale
      I18n.locale = params[:locale] || I18n.default_locale
    end
    
    def default_url_options(options={})
      logger.debug "default_url_options is passed options: #{options.inspect}\n"
       { :locale => I18n.locale }
    end
    

    使用此代码,所有链接都具有 el 之类的扩展名?我的默认链接不起作用 现在我有了 l(Time.now, :format => :short) 希腊语的一切。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 2021-04-15
      • 1970-01-01
      • 2023-01-19
      • 2013-01-02
      • 1970-01-01
      • 2011-02-02
      相关资源
      最近更新 更多