Class: Mack::Localization::Translator
- Includes:
- Singleton
- Defined in:
- lib/mack-localization/translator.rb
Instance Method Summary collapse
- #getimg(view_sym, key, lang) ⇒ Object
-
#gets(view_sym, key, lang) ⇒ Object
Get the localized string for the specified language using the given key in the view_sym namespace.
- #irregular(key, lang, num) ⇒ Object
-
#pluralize(key, lang, num) ⇒ Object
REVIEW: inflection…
Instance Method Details
#getimg(view_sym, key, lang) ⇒ Object
41 42 43 |
# File 'lib/mack-localization/translator.rb', line 41 def getimg(view_sym, key, lang) raise Mack::Localization::Errors::UnsupportedFeature.new("getimg") end |
#gets(view_sym, key, lang) ⇒ Object
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//content_.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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mack-localization/translator.rb', line 26 def gets(view_sym, key, lang) view_name = view_sym.to_s base_lang = l10n_config.base_language base_lang = lang.to_s if !lang.nil? raise Mack::Localization::Errors::UnsupportedLanguage.new(base_lang) if !l10n_config.supported_languages.include?(base_lang) cache_key = "#{view_sym}_#{base_lang}_content" path = File.join("views", "#{view_name}", "content_#{base_lang}.yml") content_hash = load_content_hash(cache_key, base_lang, path) raise Mack::Localization::Errors::UnknownStringKey.new(key) if content_hash[key] == nil return u(content_hash[key]) end |
#irregular(key, lang, num) ⇒ Object
50 51 52 |
# File 'lib/mack-localization/translator.rb', line 50 def irregular(key, lang, num) return u(inflect(key, lang, num, :irregular)) end |
#pluralize(key, lang, num) ⇒ Object
REVIEW: inflection… should localized inflection use the same inflection engine as the english counterpart?
46 47 48 |
# File 'lib/mack-localization/translator.rb', line 46 def pluralize(key, lang, num) return u(inflect(key, lang, num, :plural)) end |