Sha256: e58286c69d16840478432d1d012c810a6790f21b8725bde3324fcd93ebb36c69

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Pwb
  class Export::TranslationsController < ApplicationApiController
    # http://localhost:3000/export/translations/all
    def all
      # render plain: I18n::Backend::ActiveRecord::Translation.to_csv
      # send_data text: I18n::Backend::ActiveRecord::Translation.to_csv
      # above results in below message in chrome:
      # Resource interpreted as Document but transferred with MIME type application/octet-stream

      translations = I18n::Backend::ActiveRecord::Translation.where(id: [1, 2, 3])
      @header_cols = ["translation-id", "key", "value", "locale"]
      @translation_fields = %i[id key value locale]
      @translations_array = []
      translations.each do |translation|
        translation_field_values = []
        @translation_fields.each do |field|
          # for each of the translation_fields
          # get its value for the current translation
          translation_field_values << (translation.send field)
          # translation[field] would work instead of "translation.send field" in most
          # cases but not for title_es and associated fields
        end
        @translations_array << translation_field_values
      end
      headers['Content-Disposition'] = "attachment; filename=\"pwb-translations.csv\""
      headers['Content-Type'] ||= 'text/csv'
      render "all.csv"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pwb-1.4.0 app/controllers/pwb/export/translations_controller.rb