Class: SetupConfiguration::Translation::Translator
- Inherits:
-
Object
- Object
- SetupConfiguration::Translation::Translator
- Includes:
- Encoder
- Defined in:
- lib/setup_configuration/translation.rb
Constant Summary collapse
- NAME =
:name.freeze
- COMMENT =
:comment.freeze
- EMPTY =
''
Class Method Summary collapse
-
.i18n_load_path(path) ⇒ Object
Adds a file with translations.
Instance Method Summary collapse
-
#translate(key, language) ⇒ Object
Returns name and description for the given parameter in the given language.
Methods included from Encoder
default_encoding, encoding, encoding_supported, #force_encoding
Class Method Details
.i18n_load_path(path) ⇒ Object
Adds a file with translations.
52 53 54 |
# File 'lib/setup_configuration/translation.rb', line 52 def self.i18n_load_path(path) I18n.load_path << path end |
Instance Method Details
#translate(key, language) ⇒ Object
Returns name and description for the given parameter in the given language.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/setup_configuration/translation.rb', line 57 def translate(key, language) name=I18n.translate(NAME, :scope => key, :default => key.to_s, :locale => language) description=I18n.translate(COMMENT, :scope => key, :default => EMPTY, :locale => language) # if an empty string is found as translation use key as name (not empty string) name = key.to_s if name.strip.empty? description = EMPTY if description.strip.empty? name = force_encoding(name) description = force_encoding(description) [name, description] end |