diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cb34700f1..f67205684 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -71,6 +71,7 @@ class ApplicationController < ActionController::Base else locale = request.preferred_language_from AVAILABLE_LANGUAGE_CODES locale ||= request.compatible_language_from AVAILABLE_LANGUAGE_CODES + locale ||= DEFAULT_LANGUAGE I18n.locale = locale end end diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index ea1d22de0..6f976b5a2 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -26,6 +26,6 @@ module LanguageHelper end def rtl? - @rtl ||= RTL_LANGUAGES.include? I18n.locale + @rtl ||= RTL_LANGUAGES.include? I18n.locale.to_s end end diff --git a/config/environment.rb b/config/environment.rb index 94af3cec7..7bd05b16f 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -16,21 +16,6 @@ require File.expand_path('../application', __FILE__) Haml::Template.options[:format] = :html5 Haml::Template.options[:escape_html] = true -if File.exists?(File.expand_path("./config/locale_settings.yml")) - locale_settings = YAML::load(File.open(File.expand_path("./config/locale_settings.yml"))) - AVAILABLE_LANGUAGES = (locale_settings['available'].length > 0) ? locale_settings['available'] : { :en => 'English' } - DEFAULT_LANGUAGE = (AVAILABLE_LANGUAGES.include?(locale_settings['default'])) ? locale_settings['default'] : AVAILABLE_LANGUAGES.keys[0].to_s - AVAILABLE_LANGUAGE_CODES = locale_settings['available'].keys.map { |v| v.to_s } - LANGUAGE_CODES_MAP = locale_settings['fallbacks'] - RTL_LANGUAGES = locale_settings['rtl'] -else - AVAILABLE_LANGUAGES = { :en => 'English' } - DEFAULT_LANGUAGE = 'en' - AVAILABLE_LANGUAGE_CODES = ['en'] - LANGUAGE_CODES_MAP = {} - RTL_LANGUAGES = [] -end - # Blacklist of usernames USERNAME_BLACKLIST = ['admin', 'administrator', 'hostmaster', 'info', 'postmaster', 'root', 'ssladmin', 'ssladministrator', 'sslwebmaster', 'sysadmin', 'webmaster', 'support', 'contact', 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo'] diff --git a/config/environments/production.rb b/config/environments/production.rb index d52461370..b96fa6252 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -46,9 +46,6 @@ Diaspora::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) - config.i18n.fallbacks = true config.threadsafe! end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index a6e1e49e5..e49d26a40 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -43,9 +43,6 @@ Diaspora::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) - config.i18n.fallbacks = true config.threadsafe! end diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index c96e5be0e..015dc6d8c 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -3,31 +3,36 @@ # the COPYRIGHT file. require 'i18n_interpolation_fallbacks' +require "i18n/backend/fallbacks" + + +if File.exists?(File.expand_path("./config/locale_settings.yml")) + locale_settings = YAML::load(File.open(File.expand_path("./config/locale_settings.yml"))) + AVAILABLE_LANGUAGES = (locale_settings['available'].length > 0) ? locale_settings['available'] : { "en" => 'English' } + AVAILABLE_LANGUAGE_CODES = locale_settings['available'].keys + DEFAULT_LANGUAGE = (AVAILABLE_LANGUAGE_CODES.include?(locale_settings['default'].to_s)) ? locale_settings['default'].to_s : "en" + LANGUAGE_CODES_MAP = locale_settings['fallbacks'] + RTL_LANGUAGES = locale_settings['rtl'] +else + AVAILABLE_LANGUAGES = { "en" => 'English' } + DEFAULT_LANGUAGE = "en" + AVAILABLE_LANGUAGE_CODES = ["en"] + LANGUAGE_CODES_MAP = {} + RTL_LANGUAGES = [] +end + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] I18n.default_locale = DEFAULT_LANGUAGE I18n::Backend::Simple.send(:include, I18n::Backend::InterpolationFallbacks) - I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) -AVAILABLE_LANGUAGE_CODES.each do |c| - if LANGUAGE_CODES_MAP.key?(c) - I18n.fallbacks[c.to_sym] = LANGUAGE_CODES_MAP[c] - I18n.fallbacks[c.to_sym].concat([c.to_sym, DEFAULT_LANGUAGE.to_sym, :en]) - else - I18n.fallbacks[c.to_sym] = [c.to_sym, DEFAULT_LANGUAGE.to_sym, :en] - end -end -# There's almost certainly a better way to do this. -# Maybe by loading our paths in the initializer hooks, they'll end up after the gem paths? -class I18n::Railtie - class << self - def initialize_i18n_with_path_cleanup *args - initialize_i18n_without_path_cleanup *args - I18n.load_path.reject!{|path| path.match(/devise_invitable/) } - end - alias_method_chain :initialize_i18n, :path_cleanup +AVAILABLE_LANGUAGE_CODES.each do |c| + I18n.fallbacks[c] = [c] + if LANGUAGE_CODES_MAP.key?(c) + I18n.fallbacks[c].concat(LANGUAGE_CODES_MAP[c]) end + I18n.fallbacks[c].concat([DEFAULT_LANGUAGE, "en"]) end diff --git a/config/locale_settings.yml b/config/locale_settings.yml index 860685d72..472a06769 100644 --- a/config/locale_settings.yml +++ b/config/locale_settings.yml @@ -62,45 +62,45 @@ available: fallbacks: en-GB: - - :en + - "en" en-US: - - :en + - "en" en_shaw: - - :en - - :en-GB - - :en-US + - "en" + - "en-GB" + - "en-US" en_pirate: - - :en - - :en-GB - - :en-US + - "en" + - "en-GB" + - "en-US" en_1337: - - :en - - :en-GB - - :en-US + - "en" + - "en-GB" + - "en-US" sv: - - :sv-SE + - "sv-SE" he: - - :he-IL + - "he-IL" es-AR: - - :es + - "es" es-CL: - - :es + - "es" es-MX: - - :es + - "es" gl: - - :gl-ES + - "gl-ES" zh: - - :zh-CN - - :zh-TW + - "zh-CN" + - "zh-TW" ur-PK: - - :ur + - "ur" de_formal: - - :de + - "de" rtl: - - :ar - - :he - - :ur - - :ur-PK - - :ms + - "ar" + - "he" + - "ur" + - "ur-PK" + - "ms"