Class: Idioma::PhraseExporter
- Inherits:
-
Object
- Object
- Idioma::PhraseExporter
- Defined in:
- app/models/idioma/phrase_exporter.rb
Class Method Summary collapse
-
.to_csv(scope) ⇒ String
Produce a CSV string of Phrases based on a scope.
-
.to_yaml(scope) ⇒ String
Produce a YAML string of Phrases based on a scope.
Class Method Details
.to_csv(scope) ⇒ String
Produce a CSV string of Phrases based on a scope
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/idioma/phrase_exporter.rb', line 7 def self.to_csv(scope) require 'csv' CSV.generate do |csv_object| csv_object << [ I18n.t("idioma.locale"), I18n.t("idioma.key"), I18n.t("idioma.value"), I18n.t("idioma.translated") ] scope.find_each do |phrase| csv_object << [ phrase.locale, phrase.i18n_key, phrase.i18n_value, phrase.translated_at.present? ? I18n.t('idioma.ans_yes') : I18n.t('idioma.ans_no') ] end end end |
.to_yaml(scope) ⇒ String
Produce a YAML string of Phrases based on a scope
30 31 32 33 34 35 36 37 38 |
# File 'app/models/idioma/phrase_exporter.rb', line 30 def self.to_yaml(scope) phrases = scope.order(:locale, :i18n_key).pluck(:locale, :i18n_key, :i18n_value) phrase_hash = phrases.each_with_object({}) do |phrase, hsh| hsh["#{phrase[0]}.#{phrase[1]}"] = phrase[2] end to_nested_hash(phrase_hash).to_yaml end |