Module: I18n::Backend::Weeler::Exporter::ClassMethods
- Defined in:
- lib/i18n/backend/weeler/exporter.rb
Instance Method Summary collapse
-
#as_xlsx_package ⇒ Object
Prepare xlsx package from current scope Stores all translations in translations worksheet.
- #title_row(locales) ⇒ Object
- #translation_row_by_key_and_locales(key, locales) ⇒ Object
Instance Method Details
#as_xlsx_package ⇒ Object
Prepare xlsx package from current scope Stores all translations in translations worksheet.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/i18n/backend/weeler/exporter.rb', line 31 def as_xlsx_package package = Axlsx::Package.new package.use_shared_strings = true sheet = package.workbook.add_worksheet(name: "translations") locales = I18n.available_locales sheet.add_row(Translation.title_row(locales)) types = [] (locales.size + 1).times { types << :string } included_keys = [] self.current_scope.each do |translation| unless included_keys.include? translation.key sheet.add_row(Translation.translation_row_by_key_and_locales(translation.key, locales), types: types) included_keys << translation.key end end return package end |
#title_row(locales) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/i18n/backend/weeler/exporter.rb', line 54 def title_row locales row = [ 'Key' ] locales.each do |locale| row.push(locale.capitalize) end row end |
#translation_row_by_key_and_locales(key, locales) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/i18n/backend/weeler/exporter.rb', line 62 def translation_row_by_key_and_locales key, locales row = [ key ] locales.each do |locale| result = Translation.locale(locale).lookup(key).load if result.first.present? row.push(result.first.value) else row.push("") end end row end |