0

我第一次使用 I18n gem。我正在使用两种语言(英语和孟加拉语)创建一个网站。所以我按照 I18n api 做了一切。现在一切正常,除了一个。我的默认操作(或者您可以说root :to => my_default_options)是翻译有一些问题。我的默认 i18n 语言是英语。但默认布局 ( application.html.erb) 中的文本在此操作中默认翻译成孟加拉语。我只重复默认布局中的部分。该操作的视图文件中的其他文本翻译得很好。另一方面,来自应用程序默认布局的文本在英语和孟加拉语中翻译得很好。该问题仅发生在我的默认操作中。

虽然这是一个复杂的问题,但我已经上传了我的应用程序的完整源代码。(警告:该应用程序不完整,所以一切可能无法正常工作)

我不确定哪些文件需要在这里发布。我在微博控制器中遇到了这个问题。在“新”行动中。这里是..

class MicroblogsController < ApplicationController
  before_filter :auth, :only => [:up, :down] 
  before_filter :set_locale

  def new
    @text = Microblog.new
    @all = all.paginate(:page => params[:page], :per_page => 5)
    @top = Microblog.top_rated.paginate(:page => params[:page], :per_page => 5)
  end

  def create
    @text = Microblog.new(params[:text])
    if Captcha::valid?(session,params)
      if @text.save
        flash[:notice] = "DONE!"
        redirect_to( @text)
      else
        #redirect_to(  :action => 'new' )
        render 'new'
      end
    else
      flash[:notice] = "Wrong Answer. Try Again!"
      redirect_to :back 
    end

  end

  def show
    @text = Microblog.find(params[:id])
    @com = @text.comments.sorted.paginate(:page => params[:page], :per_page => 5)
    @rating = (@text.up - @text.down)
  end


  def up
    @text = Microblog.find(params[:id])
    @text.update_attributes(params[@text.up += 1])
    @text.update_attributes(params[@text.rate += 1])

    @a.push(@text.id)

    session[:token] = @a
    if @a.size > 5
        @a.delete_at(0)
    end

    redirect_to( :action => 'show', :id => @text.id)
  end

  def down


    @text.update_attributes(params[@text.down += 1])
    @text.update_attributes(params[@text.rate -= 1])

    @a.push(@text.id)
    session[:token] = @a
    if @a.size > 5
        @a.delete_at(0)
    end
    redirect_to( :action => 'show', :id => @text.id)
  end


    private

      def auth
            @text = Microblog.find(params[:id])
            @a = session[:token].to_a

            if @a.include?(@text.id)
                redirect_to( :action => 'show', :id => @text.id)
                return false
            else
                return true
            end
      end



end

我在应用程序控制器中设置了 i18n 选项。

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

我来自 config.application.rb 的 i18n 配置

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
config.i18n.default_locale = :'en'

这是来自 view/layouts/application.html.erb 的行。这些是我遇到的问题

<li><%= link_to("#{ t :Home}", :action => 'new') %></li>
    <%= I18n.locale %> (to see the value of i18n)

此问题仅在渲染微博/新动作时出现。文本“:Home”总是翻译成孟加拉语,并显示 i18n 变量的值是 bn(孟加拉语)。但 /view/microblogs/new.html.erb 的其他部分翻译完美

4

0 回答 0