Module: Translatable
- Defined in:
- lib/translatable/version.rb,
lib/translatable/translatable.rb
Defined Under Namespace
Modules: VERSION
Constant Summary collapse
- @@language =
Active language symbol.
:en- @@translations =
Hash of translations loaded.
{}
- @@bypass_english_translations =
Wither or not english string translation lookup should be bypassed for performance enhancements.
true
Class Method Summary collapse
-
.allow_english_translations ⇒ Object
Allow overriding of english strings, this can be used to make alterations in situations such as a CMS where you may not want to alter core.
-
.disallow_english_translations ⇒ Object
Contrast of #allow_english_translations.
- .english_translations_allowed? ⇒ Boolean
-
.language(lang = nil) ⇒ Object
Set or return lanf code symbol.
-
.translate(lang, translations) ⇒ Object
Translate one or more strings for lang.
-
.translations ⇒ Object
Return translation hash.
Class Method Details
.allow_english_translations ⇒ Object
Allow overriding of english strings, this can be used to make alterations in situations such as a CMS where you may not want to alter core. However since most instances will be using english we typically bypass the translation process when #language is set to :en
33 34 35 |
# File 'lib/translatable/translatable.rb', line 33 def allow_english_translations @@bypass_english_translations = false end |
.disallow_english_translations ⇒ Object
Contrast of #allow_english_translations.
40 41 42 |
# File 'lib/translatable/translatable.rb', line 40 def disallow_english_translations @@bypass_english_translations = true end |
.english_translations_allowed? ⇒ Boolean
22 23 24 |
# File 'lib/translatable/translatable.rb', line 22 def english_translations_allowed? !@@bypass_english_translations end |
.language(lang = nil) ⇒ Object
Set or return lanf code symbol. Default is :en
47 48 49 50 |
# File 'lib/translatable/translatable.rb', line 47 def language lang = nil @@language = lang.to_sym unless lang.nil? @@language end |
.translate(lang, translations) ⇒ Object
Translate one or more strings for lang.
Where lang is a symbol representation of the language such as :en, :fr, and translations is a hash of one or more key / value pairs containing the original / translated string.
Examples:
translate :fr, 'I like cookies' => 'J'aime des biscuits'
OR
translate :fr,
'I like cookies' => 'J'aime des biscuits'
'I like ruby' => '...'
'I like ferrets' => '...'
71 72 73 |
# File 'lib/translatable/translatable.rb', line 71 def translate lang, translations @@translations[lang] = (@@translations[lang] || {}).merge translations end |
.translations ⇒ Object
Return translation hash.
78 79 80 |
# File 'lib/translatable/translatable.rb', line 78 def translations @@translations end |