Class | Mack::Localization::Translator |
In: |
lib/mack-localization/translator.rb
|
Parent: | Object |
# File lib/mack-localization/translator.rb, line 41 41: def getimg(view_sym, key, lang) 42: raise Mack::Localization::Errors::UnsupportedFeature.new("getimg") 43: end
Get the localized string for the specified language using the given key in the view_sym namespace. The view symbol is how the system knows where to locate the content file. By default the localization of the file is in [app_directory]/lang/views/[view_sym]/content_[lang].yml
params:
view_sym -- which view is the key located in? key -- the lookup key lang -- the language
returns:
the multibyte version of the string
raise:
UnsupportedLanguage if the specified language is not defined in the 'supported_languages' array UnknownStringKey if the key specified is not defined in the content file
see also:
l10n_gets in view_helpers
# File lib/mack-localization/translator.rb, line 26 26: def gets(view_sym, key, lang) 27: view_name = view_sym.to_s 28: base_lang = l10n_config.base_language 29: base_lang = lang.to_s if !lang.nil? 30: 31: raise Mack::Localization::Errors::UnsupportedLanguage.new(base_lang) if !l10n_config.supported_languages.include?(base_lang) 32: 33: cache_key = "#{view_sym}_#{base_lang}_content" 34: path = File.join(l10n_config.base_directory, "views", "#{view_name}", "content_#{base_lang}.yml") 35: content_hash = load_content_hash(cache_key, base_lang, path) 36: 37: raise Mack::Localization::Errors::UnknownStringKey.new(key) if content_hash[key] == nil 38: return u(content_hash[key]) 39: end
# File lib/mack-localization/translator.rb, line 50 50: def irregular(key, lang, num) 51: return u(inflect(key, lang, num, :irregular)) 52: end