Skip to content

Commit

Permalink
match locales to ECHOcommunity
Browse files Browse the repository at this point in the history
  • Loading branch information
npflood committed Mar 28, 2017
1 parent 3cfdd6f commit b84fa8b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
en:
js:
site_title: "ECHOcommunity Forums"
site_title: "ECHOcommunity: Conversations"
2 changes: 1 addition & 1 deletion config/locales/client.es.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
es:
js:
site_title: "ECHOcommunity Foros de Discusión"
site_title: "ECHOcommunity: Conversaciones"
3 changes: 3 additions & 0 deletions config/locales/client.fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fr:
js:
site_title: "ECHOcommunity: Conversations"
3 changes: 3 additions & 0 deletions config/locales/client.id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id:
js:
site_title: "ECHOcommunity: Percakapan"
3 changes: 3 additions & 0 deletions config/locales/client.km.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
km:
js:
site_title: "ECHOcommunity: ការសន្ទនា"
3 changes: 3 additions & 0 deletions config/locales/client.zh_CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zh_CN:
js:
site_title: "ECHOcommunity: 对话"
23 changes: 21 additions & 2 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,35 @@
gem "http_accept_language", "2.0.5"

after_initialize do
# match the supported locales to the main site.
LocaleSiteSetting.class_eval do
def self.supported_locales
%w(en es fr my vi th zh zh_CN sw id km)
end
end

ApplicationController.class_eval do
def set_locale
begin
I18n.locale = params[:locale] || http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale
begin
detected_locale = params[:locale] || http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale
I18n.locale = map_locale(detected_locale)
rescue I18n::InvalidLocale
I18n.locale = I18n.default_locale
end
I18n.ensure_all_loaded!
end

def map_locale(locale)
case locale.to_s
when "en", "es", "fr", "vi", "id"
locale
when "zh"
"zh_CN"
when "my", "th", "sw", "km"
"en"
end
end

def default_url_options(options={})
{ locale: I18n.locale }
end
Expand Down

0 comments on commit b84fa8b

Please sign in to comment.