module TripAdvisor class Translation # Returns a dictionary that specifies how locale identifiers map to BCP 47 Language Identifiers def self.locale_identifier_to_language_codes_mapping { "zh_TW" => "zh-Hant", "zh_CN"=> "zh-Hans", "zh_CN"=> "zh", "no"=> "nb", "in"=> "id", "en_UK"=> "en-GB" } end # Supports keyed lookup by locale identifier class LocalizationsArray < Array def [](locale_identifier) if locale_identifier.is_a?(String) self.detect { |localization| localization.locale_identifier == locale_identifier.to_s } else super end end end class Localization attr_accessor :locale_identifier, :language_name, :string, :status def initialize(attributes = {}) attributes.each { |k, v| self.send("#{k}=", v) } end def locale_identifier=(locale_identifier) @locale_identifier = (Translation.locale_identifier_to_language_codes_mapping[locale_identifier] || locale_identifier) end def string=(string) @string = string.strip end def to_s string end def active? status == 'Active' end end attr_accessor :id, :key, :note, :localizations def initialize(attributes = {}) @localizations = LocalizationsArray.new attributes.each { |k, v| self.send("#{k}=", v) } end def key=(key) @key = key.strip end def localizations=(localizations) @localizations.concat(localizations) end def [](locale_identifier) localizations[locale_identifier] end end end