Module: I18n::Backend::Tml::Implementation
Instance Method Summary collapse
- #application ⇒ Object
- #available_locales ⇒ Object
- #convert_to_tml(str) ⇒ Object
- #lookup(locale, key, scope = [], options = {}) ⇒ Object
- #translate(locale, key, options = {}) ⇒ Object
Instance Method Details
#application ⇒ Object
43 44 45 |
# File 'lib/i18n/backend/tml.rb', line 43 def application ::Tml.session.application end |
#available_locales ⇒ Object
47 48 49 |
# File 'lib/i18n/backend/tml.rb', line 47 def available_locales application.locales end |
#convert_to_tml(str) ⇒ Object
56 57 58 |
# File 'lib/i18n/backend/tml.rb', line 56 def convert_to_tml(str) str.gsub('%{', '{') end |
#lookup(locale, key, scope = [], options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/i18n/backend/tml.rb', line 60 def lookup(locale, key, scope = [], = {}) # pp [locale, key, scope, options] if key.to_s.match(/^(support|i18n|number|human|distance)/) return super(locale, key, scope, ) end # if language is not available, return default value target_language = application.language(locale.to_s) target_language ||= application.language(application.default_locale) unless target_language return super(locale, key, scope, ) end default_key = super(application.default_locale, key, scope, ) default_key ||= key.to_s.split('.').last.gsub('_', ' ').capitalize if default_key.is_a?(String) translated_key = target_language.translate(convert_to_tml(default_key), , ) elsif default_key.is_a?(Hash) translated_key = {} default_key.each do |key, value| if value.is_a?(String) value = target_language.translate(convert_to_tml(value), , ) end translated_key[key] = value end end translated_key end |
#translate(locale, key, options = {}) ⇒ Object
51 52 53 54 |
# File 'lib/i18n/backend/tml.rb', line 51 def translate(locale, key, = {}) translation = super(locale, key, ) translation.is_a?(String) ? translation.html_safe : translation end |