0

我正在做一个多语言项目。我正在使用 I18n gem 进行本地化。在某些时候,我想传递一个空值,如下所示:

current_locale("")

current_locale()函数在哪里

def current_locale(locale)
    if locale.empty?
      translation = find_translation(locale)
    else 
      translation = find_translation( I18n.locale ) || find_translation( I18n.default_locale ) || translations.first
    end
    translation.locale  
  end

但是当current_locale()调用该函数时,它给了我以下错误:

undefined method `locale' for nil:NilClass

有谁知道如何解决这个错误?

谢谢

4

1 回答 1

0

更改前两行,它应该可以工作(只要您至少有translationin translations)。

def current_locale(locale = nil)
  if locale.blank?
    ...
于 2013-10-10T06:27:15.830 回答