Sha256: bbc0ba545427dd2b83dfd4ef8b30efea38eee0e7edaed2df9a5eda0cdb705041

Contents?: true

Size: 1.42 KB

Versions: 28

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

def create_translations
  %w[en fr].each do |local|
    locale_file = "config/locales/bo.#{local}.yml"
    unless File.exist?(locale_file)
      File.write(locale_file, {
        local => {
          'bo' => {
            'filters' => find_existing_translation('filters', local),
            'record' => {
            'created' => find_existing_translation('created', local),
            'updated' => find_existing_translation('updated', local),
            'destroyed' => find_existing_translation('destroyed', local)
          }
         }
        }
      }.to_yaml)
    end

    yaml_string = File.open locale_file
    data = YAML.load yaml_string
    data[local]['bo'][file_name.underscore.to_s] = {
      'one' => find_existing_translation(bo_model.to_s.downcase, local),
      'others' => find_existing_translation(bo_model.to_s.pluralize.downcase, local),
      'subtitle' => find_existing_translation("list of #{bo_model.to_s.pluralize.downcase}", local),
      'attributes' => model_attributes(local)
    }
    output = YAML.dump data
    File.write(locale_file, output)
  end
end

def model_attributes(local)
  hash = {}
  model_columns.each do |col|
    hash[col.to_s] = find_existing_translation(col, local)
  end
  hash
end

def find_existing_translation(col, local)
  return col.to_s.humanize.downcase if local == 'en'

  json = JSON.parse(File.read("#{__dir__}/files/#{local}.json"))
  json[col.to_s]
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
tybo-0.0.32 lib/generators/bo/utils/translations.rb
tybo-0.0.31 lib/generators/bo/utils/translations.rb
tybo-0.0.30 lib/generators/bo/utils/translations.rb
tybo-0.0.29 lib/generators/bo/utils/translations.rb
tybo-0.0.28 lib/generators/bo/utils/translations.rb
tybo-0.0.27 lib/generators/bo/utils/translations.rb
tybo-0.0.26 lib/generators/bo/utils/translations.rb
tybo-0.0.24 lib/generators/bo/utils/translations.rb
tybo-0.0.23 lib/generators/bo/utils/translations.rb
tybo-0.0.22 lib/generators/bo/utils/translations.rb
tybo-0.0.21 lib/generators/bo/utils/translations.rb
tybo-0.0.20 lib/generators/bo/utils/translations.rb
tybo-0.0.19 lib/generators/bo/utils/translations.rb
tybo-0.0.18 lib/generators/bo/utils/translations.rb
tybo-0.0.17 lib/generators/bo/utils/translations.rb
tybo-0.0.16 lib/generators/bo/utils/translations.rb
tybo-0.0.15 lib/generators/bo/utils/translations.rb
tybo-0.0.14 lib/generators/bo/utils/translations.rb
tybo-0.0.13 lib/generators/bo/utils/translations.rb
tybo-0.0.12 lib/generators/bo/utils/translations.rb