I18n翻译仅供管理员使用

时间:2012-03-15 23:24:47

标签: ruby-on-rails-3 internationalization

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

我为我的语言(希腊语)制作了我的el.yml,我的Gemfile有gem'trail-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

一切都很好,我的用户用希腊语查看时间。但是来自Users的前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(继承)?

1 个答案:

答案 0 :(得分:0)

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

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 =&gt;:short)一切都用希腊语。

相关问题