Class: Idioma::PhraseExtractor
- Inherits:
-
Object
- Object
- Idioma::PhraseExtractor
- Defined in:
- app/models/idioma/phrase_extractor.rb
Class Method Summary collapse
-
.extract ⇒ Hash
Find all of the translations that are in the locale yaml files and convert them into a hash of dotted hash notation key/values for each locale that is found.
-
.get_translations(backend = nil) ⇒ Hash
Get translations from the i18n backend.
-
.to_dotted_hash(source, accumulator = {}, namespace = nil) ⇒ Hash
Convert a nested Hash ({format: {long: “YYYY-MM-DD”}}) to a dotted hash => “YYYY-MM-DD”.
Class Method Details
.extract ⇒ Hash
Find all of the translations that are in the locale yaml files
and convert them into a hash of dotted hash notation key/values
for each locale that is found
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/idioma/phrase_extractor.rb', line 8 def self.extract phrase_hashes = self.get_translations phrase_dotted_hashes = {} # convert each locales translations to dotted hash phrase_hashes.each do |locale, phrase_hash| phrase_dotted_hashes[locale] = self.to_dotted_hash(phrase_hash) end phrase_dotted_hashes end |
.get_translations(backend = nil) ⇒ Hash
Get translations from the i18n backend
23 24 25 26 27 |
# File 'app/models/idioma/phrase_extractor.rb', line 23 def self.get_translations(backend = nil) backend = I18n::Backend::Simple.new if backend.nil? backend.send(:init_translations) backend.send(:translations) end |
.to_dotted_hash(source, accumulator = {}, namespace = nil) ⇒ Hash
Convert a nested Hash ({format: {long: “YYYY-MM-DD”}})
to a dotted hash {"date.format.long" => "YYYY-MM-DD"}
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/idioma/phrase_extractor.rb', line 35 def self.to_dotted_hash(source, accumulator = {}, namespace = nil) prefix = "#{namespace}." if namespace case source when Hash source.each do |key, value| to_dotted_hash(value, accumulator, "#{prefix}#{key}") end else accumulator[namespace] = source end accumulator end |