aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2012-06-13 14:07:58 +0100
committerSeb Bacon <seb.bacon@gmail.com>2012-06-13 14:07:58 +0100
commit8f0b7b6f86dc60a51d4ffab2a5fd627fa3499b8a (patch)
tree76bdde02413edcf9bc578195ef530576c44a2cd1
parent50eb7689c7d6339f8a28350d9ed3776e2626924a (diff)
Fix it so we can correctly use and display locales that contain an underscore (e.g. `hu_HU`):
* Use the latest version of `gettext_i18n_rails` (including fix to make it work in Railes 2.x) * Use a backend that falls back to, for example, `hu` from `hu_HU` (so we can use any underlying Rails l10n) * Normalize the underscore to a hyphen when working out which languages to display in the language switcher Fixes #503 (and see there for more discussion)
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock8
-rw-r--r--config/initializers/fast_gettext.rb4
-rw-r--r--lib/languages.rb2
4 files changed, 14 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index 542970145..e744caf7c 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,6 +11,7 @@ gem 'rails', '2.3.14'
gem 'pg'
gem 'fast_gettext', '>= 0.6.0'
+gem 'gettext_i18n_rails', '>= 0.6.0', :git => "git@github.com:sebbacon/gettext_i18n_rails.git"
gem 'gettext', '>= 1.9.3'
gem 'json', '~> 1.5.1'
gem 'mahoro'
diff --git a/Gemfile.lock b/Gemfile.lock
index e7c089a4a..e271f8572 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,3 +1,10 @@
+GIT
+ remote: git@github.com:sebbacon/gettext_i18n_rails.git
+ revision: 7b62102bf355a564eeca2e0dcd05f73f073935b0
+ specs:
+ gettext_i18n_rails (0.6.1)
+ fast_gettext
+
GEM
remote: http://rubygems.org/
specs:
@@ -67,6 +74,7 @@ DEPENDENCIES
fakeweb
fast_gettext (>= 0.6.0)
gettext (>= 1.9.3)
+ gettext_i18n_rails (>= 0.6.0)!
json (~> 1.5.1)
locale (>= 2.0.5)
mahoro
diff --git a/config/initializers/fast_gettext.rb b/config/initializers/fast_gettext.rb
index 9049fd8ed..721c49cd0 100644
--- a/config/initializers/fast_gettext.rb
+++ b/config/initializers/fast_gettext.rb
@@ -1,3 +1,7 @@
Encoding.default_external = 'UTF-8' if RUBY_VERSION.to_f >= 1.9
FastGettext.add_text_domain 'app', :path => File.join(Rails.root, 'locale'), :type => :po
FastGettext.default_text_domain = 'app'
+
+I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
+
+
diff --git a/lib/languages.rb b/lib/languages.rb
index 4d355ab59..42231ef56 100644
--- a/lib/languages.rb
+++ b/lib/languages.rb
@@ -187,7 +187,7 @@ class LanguageNames
'za' => 'Saɯ cueŋƅ',
'zu' => 'isiZulu'
}
- locale = locale.sub("_", "-")
+ locale = locale.sub("_", "-") # normalize
main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0]
return language_names[main_part]
end