class TranslationCenter::AddLangGenerator

Public Class Methods

next_migration_number(path) click to toggle source
# File lib/generators/translation_center/add_lang/add_lang_generator.rb, line 8
def self.next_migration_number(path)
  @migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S%6N").to_i.to_s
end

Public Instance Methods

add_lang() click to toggle source
# File lib/generators/translation_center/add_lang/add_lang_generator.rb, line 12
def add_lang
  if langs.blank?
    puts 'Please provide a language to add to the translation center'
    return
  end

  langs.each do |lang|
    @lang = lang
    # check if language already supported
    if(TranslationCenter::TranslationKey.column_names.include? "#{lang.downcase.gsub("-","_")}_status")
      puts 'This language is already supported, just make sure it is listed in config/translation_center.yml'
      return
    end
    # Generate migration templates for the models needed
    migration_template 'migrations/add_lang_status_translation_keys.rb', "db/migrate/add_#{lang.downcase.gsub("-","_")}_status_translation_center_translation_keys.rb"
  end
  puts "Language(s) added, don't forget to add the language(s) to config/translation_center.yml"
end