module ZendeskAppsSupport::BuildTranslation
Constants
- I18N_KEYS
- I18N_TITLE_KEY
- I18N_VALUE_KEY
Public Instance Methods
remove_zendesk_keys(scope, translations = {})
click to toggle source
# File lib/zendesk_apps_support/build_translation.rb, line 24 def remove_zendesk_keys(scope, translations = {}) scope.each_key do |key| context = scope[key] if context.is_a?(Hash) if translation_hash?(context) translations[key] = context[I18N_VALUE_KEY] else translations[key] ||= {} translations[key] = remove_zendesk_keys(context, translations[key]) end else translations[key] = context end end translations end
to_flattened_namespaced_hash(hash, target_key = nil, prefix = nil)
click to toggle source
# File lib/zendesk_apps_support/build_translation.rb, line 9 def to_flattened_namespaced_hash(hash, target_key = nil, prefix = nil) hash.each_with_object({}) do |(key, value), result| key = [prefix, key].compact.join('.') if value.is_a?(Hash) if target_key && translation_hash?(value) result[key] = value[target_key] else result.update(to_flattened_namespaced_hash(value, target_key, key)) end else result[key] = value end end end
Private Instance Methods
translation_hash?(hash)
click to toggle source
# File lib/zendesk_apps_support/build_translation.rb, line 47 def translation_hash?(hash) hash.keys.sort == I18N_KEYS end