diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aa8edccd..76d8467d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -57,7 +57,7 @@ class ApplicationController < ActionController::Base end def valid_locale?(locale) - locale && I18n.available_locales.include?(locale.to_sym) + locale && I18n.usable_locales.include?(locale.to_sym) end end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index d4d8dd11..db3183e1 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -100,7 +100,7 @@ class ItemsController < ApplicationController raise ActiveRecord::RecordNotFound, 'Pet type not found' end - @items = @pet_type.needed_items.with_translations(I18n.locale). + @items = @pet_type.needed_items.with_translations. alphabetize_by_translations assign_closeted! diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e0299e56..8275720f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -103,9 +103,18 @@ module ApplicationHelper end def locale_options - I18n.available_locales.map do |available_locale| + current_locale_is_public = false + options = I18n.public_locales.map do |available_locale| + current_locale_is_public = true if I18n.locale == available_locale [translate('locale_name', :locale => available_locale), available_locale] end + + unless current_locale_is_public + name = translate('locale_name', :locale => I18n.locale) + ' (alpha)' + options << [name, I18n.locale] + end + + options end def localized_cache(key={}, &block) diff --git a/app/models/item.rb b/app/models/item.rb index bedc6d5c..06dfba6c 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -267,8 +267,9 @@ class Item < ActiveRecord::Base end def needed_translations + translatable_locales = Set.new(I18n.locales_with_neopets_language_code) translated_locales = Set.new(translations.map(&:locale)) - I18n.available_locales.reject { |locale| translated_locales.include?(locale) } + translatable_locales - translated_locales end def self.all_by_ids_or_children(ids, swf_assets) diff --git a/app/models/pet.rb b/app/models/pet.rb index 780342e0..cc653d4f 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -25,7 +25,7 @@ class Pet < ActiveRecord::Base require 'ostruct' begin - neopets_language_code = I18n.translate('neopets_language_code') + neopets_language_code = I18n.neopets_language_code_for(options[:locale]) envelope = PET_VIEWER.request([name, 0]).post( :timeout => 2, :headers => { @@ -105,10 +105,11 @@ class Pet < ActiveRecord::Base last_pet_loaded = nil reloaded_pets = Parallel.map(candidates.keys, :in_threads => 8) do |locale| Rails.logger.info "Reloading #{name} in #{locale}" - last_pet_loaded = Pet.load(name, :item_scope => Item.with_translations, - :locale => locale) + reloaded_pet = Pet.load(name, :item_scope => Item.with_translations, + :locale => locale) + Pet.connection_pool.with_connection { reloaded_pet.save! } + last_pet_loaded = reloaded_pet end - reloaded_pets.map(&:save!) previous_candidates = candidates candidates = last_pet_loaded.item_translation_candidates diff --git a/config/initializers/locale_meta.rb b/config/initializers/locale_meta.rb new file mode 100644 index 00000000..bb87965e --- /dev/null +++ b/config/initializers/locale_meta.rb @@ -0,0 +1,51 @@ +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 + +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.neopets_language_code_for(locale) + LocaleMeta::NEOPETS_LANGUAGE_CODES_BY_LOCALE[locale] + end +end diff --git a/config/locale_meta.yml b/config/locale_meta.yml new file mode 100644 index 00000000..82889814 --- /dev/null +++ b/config/locale_meta.yml @@ -0,0 +1,47 @@ +en: + visibility: public + neopets_language_code: en + +en-MEEP: + visibility: public + compatible_with: en + +pt: + visibility: private + neopets_language_code: pt + +es: + visibility: none + 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index c56d4081..196c670a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,7 +5,6 @@ en: infinite_closet: Infinite Closet modeling_hub: Modeling Hub locale_name: English - neopets_language_code: en activerecord: attributes: diff --git a/config/locales/pt.yml b/config/locales/pt.yml index cd052a0e..da15ca9d 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -1,6 +1,5 @@ pt: locale_name: Portuguese - neopets_language_code: pt - # This is a placeholder Portuguese locale, so that we can look up items. - # Everything else will fall back to English. + # This is a placeholder Portuguese locale, so that we can test things + # involving its presence.