From 0a5d369735c14fce12f7adb418a5c252c84447f1 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 13 Sep 2024 20:55:09 -0700 Subject: [PATCH] Remove i18n locale config complexity we don't use anymore I forget what this was for, I think part of it was for managing item names in different languages, and the "private" locale thing was probably for WIP locales? But yeah, not used, delete! --- app/controllers/application_controller.rb | 4 +- app/helpers/application_helper.rb | 2 +- config/application.rb | 2 + config/initializers/locale_meta.rb | 61 ----------------------- config/locale_meta.yml | 47 ----------------- 5 files changed, 5 insertions(+), 111 deletions(-) delete mode 100644 config/initializers/locale_meta.rb delete mode 100644 config/locale_meta.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 68ad72f3..2d383695 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,7 +50,7 @@ class ApplicationController < ActionController::Base return params[:locale] if valid_locale?(params[:locale]) return cookies[:locale] if valid_locale?(cookies[:locale]) Rails.logger.debug "Preferred languages: #{http_accept_language.user_preferred_languages}" - http_accept_language.language_region_compatible_from(I18n.public_locales.map(&:to_s)) || + http_accept_language.language_region_compatible_from(I18n.available_locales.map(&:to_s)) || I18n.default_locale end @@ -76,7 +76,7 @@ class ApplicationController < ActionController::Base end def valid_locale?(locale) - locale && I18n.usable_locales.include?(locale.to_sym) + locale && I18n.available_locales.include?(locale.to_sym) end def configure_permitted_parameters diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 510f1269..41676204 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -161,7 +161,7 @@ module ApplicationHelper def locale_options current_locale_is_public = false - options = I18n.public_locales.map do |available_locale| + options = I18n.available_locales.map do |available_locale| current_locale_is_public = true if I18n.locale == available_locale # Include fallbacks data on the tag. Right now it's used in blog # localization, but may conceivably be used for something else later. diff --git a/config/application.rb b/config/application.rb index 81d27eee..2ca3bd5d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -47,6 +47,8 @@ module OpenneoImpressItems config.time_zone = "Pacific Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") + config.i18n.available_locales = [:en, :es, :pt, :"en-MEEP"] + config.i18n.default_locale = :en config.i18n.fallbacks = true Mime::Type.register "image/gif", :gif diff --git a/config/initializers/locale_meta.rb b/config/initializers/locale_meta.rb deleted file mode 100644 index c4f8022d..00000000 --- a/config/initializers/locale_meta.rb +++ /dev/null @@ -1,61 +0,0 @@ -module LocaleMeta - PUBLIC_LOCALES = [] - USABLE_LOCALES = [] - NEOPETS_LANGUAGE_CODES_BY_LOCALE = {} - LOCALES_WITH_NEOPETS_LANGUAGE_CODE = [] - COMPATIBLE_LOCALES = {} -end - -config = YAML.load_file(Rails.root.join('config', 'locale_meta.yml')) - -config.each do |locale_str, locale_meta| - locale = locale_str.to_sym - - visibility = locale_meta['visibility'] - if visibility == 'public' - LocaleMeta::PUBLIC_LOCALES << locale - LocaleMeta::USABLE_LOCALES << locale - elsif visibility == 'private' - LocaleMeta::USABLE_LOCALES << locale - end - - if locale_meta.has_key?('neopets_language_code') - neopets_language_code = locale_meta['neopets_language_code'] - LocaleMeta::NEOPETS_LANGUAGE_CODES_BY_LOCALE[locale] = neopets_language_code - LocaleMeta::LOCALES_WITH_NEOPETS_LANGUAGE_CODE << locale - elsif locale_meta.has_key?('compatible_with') - compatible_locale = locale_meta['compatible_with'].to_sym - LocaleMeta::COMPATIBLE_LOCALES[locale] = compatible_locale - else - raise "locale #{locale} must either have a neopets_language_code or " + - "be compatible_with a locale that does" - end -end - -LocaleMeta::USABLE_LOCALES_WITH_NEOPETS_LANGUAGE_CODE = LocaleMeta::USABLE_LOCALES & - LocaleMeta::LOCALES_WITH_NEOPETS_LANGUAGE_CODE - -module I18n - def self.public_locales - LocaleMeta::PUBLIC_LOCALES - end - - def self.usable_locales - LocaleMeta::USABLE_LOCALES - end - - def self.locales_with_neopets_language_code - LocaleMeta::LOCALES_WITH_NEOPETS_LANGUAGE_CODE - end - - def self.usable_locales_with_neopets_language_code - LocaleMeta::USABLE_LOCALES_WITH_NEOPETS_LANGUAGE_CODE - end - - def self.compatible_neopets_language_code_for(locale) - LocaleMeta::NEOPETS_LANGUAGE_CODES_BY_LOCALE[locale] || - LocaleMeta::NEOPETS_LANGUAGE_CODES_BY_LOCALE[LocaleMeta::COMPATIBLE_LOCALES[locale]] - end -end - -Rails.configuration.i18n.available_locales = I18n.usable_locales diff --git a/config/locale_meta.yml b/config/locale_meta.yml deleted file mode 100644 index 44e6df09..00000000 --- a/config/locale_meta.yml +++ /dev/null @@ -1,47 +0,0 @@ -en: - visibility: public - neopets_language_code: en - -en-MEEP: - visibility: public - compatible_with: en - -pt: - visibility: public - neopets_language_code: pt - -es: - visibility: public - neopets_language_code: es - -nl: - visibility: none - neopets_language_code: nl - -de: - visibility: none - neopets_language_code: de - -fr: - visibility: none - neopets_language_code: fr - -it: - visibility: none - neopets_language_code: it - -zh-CN: - visibility: none - neopets_language_code: ch - -zh-TW: - visibility: none - neopets_language_code: zh - -ja: - visibility: none - neopets_language_code: ja - -ko: - visibility: none - neopets_language_code: ko