aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/languages.rb5
-rw-r--r--lib/routing_filters.rb17
-rw-r--r--lib/tasks/gettext.rake4
3 files changed, 24 insertions, 2 deletions
diff --git a/lib/languages.rb b/lib/languages.rb
index 474c0e0cb..42231ef56 100644
--- a/lib/languages.rb
+++ b/lib/languages.rb
@@ -187,8 +187,9 @@ class LanguageNames
'za' => 'Saɯ cueŋƅ',
'zu' => 'isiZulu'
}
-
- return language_names[locale]
+ locale = locale.sub("_", "-") # normalize
+ main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0]
+ return language_names[main_part]
end
end
diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb
index cdb58e7c1..32dafc651 100644
--- a/lib/routing_filters.rb
+++ b/lib/routing_filters.rb
@@ -5,5 +5,22 @@ module RoutingFilter
def prepend_locale?(locale)
locale && I18n.available_locales.length > 1 && (self.class.include_default_locale? || !default_locale?(locale))
end
+ # And override the generation logic to use FastGettext.locale
+ # rather than I18n.locale (the latter is what rails uses
+ # internally and may look like `en_US`, whereas the latter is
+ # was FastGettext and other POSIX-based systems use, and will
+ # look like `en_US`
+ def around_generate(*args, &block)
+ params = args.extract_options! # this is because we might get a call like forum_topics_path(forum, topic, :locale => :en)
+
+ locale = params.delete(:locale) # extract the passed :locale option
+ locale = FastGettext.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false)
+ locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid
+ args << params
+
+ yield.tap do |result|
+ prepend_segment!(result, locale) if prepend_locale?(locale)
+ end
+ end
end
end
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index 56e9f6df6..787b4029f 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -1,3 +1,7 @@
+# Rails won't automatically load rakefiles from gems - see
+# http://stackoverflow.com/questions/1878640/including-rake-tasks-in-gems
+Dir["#{Gem.searcher.find('gettext_i18n_rails').full_gem_path}/lib/tasks/**/*.rake"].each { |ext| load ext }
+
namespace :gettext do
desc "Update pot file only, without fuzzy guesses (these are done by Transifex)"