Class: TranslateClient::CLI::Main

Inherits:
Base
  • Object
show all
Defined in:
lib/translate_client/cli/main.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, start

Instance Method Details

#pullObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/translate_client/cli/main.rb', line 41

def pull
  config = ProjectConfig.new(
    project_id: options[:project],
    locale: options[:locale],
    format: options[:format],
    file: options[:out]
  )

  remote_locales = api.remote_locales(project_id: config.project_id)
  config.locales.each do |locale|
    if remote_locales.exclude?(locale)
      raise PresentableError.new("Requested locale \"#{locale}\" is not available in the project, use one of: #{remote_locales.join(", ")}")
    end
  end

  puts "Starting export of locales: #{config.locales.join(", ")}"

  export_ids = config.locales.index_with do |locale|
    export_id = api.create_export(
      project_id: config.project_id,
      locale:,
      format: config.format
    )

    puts "Export #{export_id} created for locale #{locale}"
    export_id
  end

  # poll each export until it's done
  export_ids.each do |locale, export_id|
    print "Pulling \"#{locale}\" ..."
    tmp_file = Helpers.poll_until do
      api.download_export(export_id:)
    end

    out = config.file(locale:)
    File.rename(tmp_file.path, out)
    puts "Pulled \"#{locale}\" to #{out}"
  end
end

#pushObject



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

def push
  config = ProjectConfig.new(
    project_id: options[:project],
    locale: options[:locale],
    format: options[:format],
    file: options[:in]
  )

  puts "Starting import of locales: #{config.locales.join(", ")}"

  config.locales.each do |locale|
    api.create_import(
      project_id: config.project_id,
      locale:,
      format: config.format,
      file: config.file(locale:)
    )

    puts "Import for locale #{locale} created"
  end
end