lib/knj/locales.rb in knjrbfw-0.0.109 vs lib/knj/locales.rb in knjrbfw-0.0.110

- old
+ new

@@ -16,11 +16,14 @@ #Sometimes language can be 'en'. Convert that to 'en_GB' if that is so. locale_str = Knj::Locales::LANG_CONVERTIONS[locale_str] if Knj::Locales::LANG_CONVERTIONS.key?(locale_str) match = locale_str.match(/^([a-z]{2})_([A-Z]{2})/) - raise "Could not understand language: '#{locale_str}'." if !match + if !match + match = locale_str.match(/^[a-z]{2}$/) + raise "Could not understand language: '#{locale_str}'." unless match + end return { "first" => match[1], "second" => match[2], "full" => "#{match[1]}_#{match[2]}" @@ -80,9 +83,11 @@ #ignore. end if Thread.current[:locale] return Thread.current[:locale] + elsif ::Kernel.const_defined?(:I18n) && !I18n.locale.to_s.strip.empty? + return I18n.locale elsif ENV["LANGUAGE"] return ENV["LANGUAGE"] elsif ENV["LANG"] return ENV["LANG"] end \ No newline at end of file