Method: AnnoTranslate::TranslationsExporter#initialize

Defined in:
lib/import_export.rb

#initialize(file_prefix, export_to = nil) ⇒ TranslationsExporter

Returns a new instance of TranslationsExporter.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/import_export.rb', line 14

def initialize(file_prefix, export_to=nil)
  # Format pertinent paths for files
  here = File.expand_path(File.dirname(__FILE__))
  config = File.expand_path(File.join(here, "..", "..", "config"))
  @locales_folder = File.join(config, "locales")
  @base_yml_file = File.join(@locales_folder, "en.yml")
  @prefix = file_prefix
  @translations_support = File.join(config, "translations")
  @duplicates_file = File.join(@translations_support, "#{@prefix}_shared_strings.yml")
  @export_folder = export_to ? export_to : File.join(@translations_support, "export")

  @base_locale = YAML.load_file(@base_yml_file)
  @cache = YAML.load_file(@duplicates_file)

  FileUtils.rm_f Dir["#{@export_folder}/*.csv"]

  # Create supported foreign languages collection
  @foreign_languages = FOREIGN_LOCALES.keys.map do |code|
    source_yml = File.join(@locales_folder, "#{code}.yml")
    dest_csv = File.join(@export_folder, "#{@prefix}.#{code}.csv")
    {code: code, name: FOREIGN_LOCALES[code], yml: source_yml, csv: dest_csv}
  end
end