Class: Xcrowdin::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xcrowdin/client.rb

Constant Summary collapse

TEMP =
Dir.tmpdir()

Instance Method Summary collapse

Constructor Details

#initialize(api_key, project_id, crowdin_path, xcode_project, langs) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/xcrowdin/client.rb', line 9

def initialize(api_key, project_id, crowdin_path, xcode_project, langs)
  @api_key = api_key
  @project_id = project_id
  @crowdin_path = crowdin_path
  @xcode_project = xcode_project
  @langs = langs
  @crowdin = CrowdinClient.new(@api_key, @project_id, @crowdin_path)
end

Instance Method Details

#import_to_xcodeObject



34
35
36
37
38
39
40
41
42
# File 'lib/xcrowdin/client.rb', line 34

def import_to_xcode
  xcode = XcodeClient.new(@xcode_project)
  @langs.each do |lang|
    p "-- start unzip translations #{lang}"
    unzip_file("#{TEMP}/#{lang}.zip", "#{TEMP}/#{lang}/")
    p "-- start import xliff translations #{lang}"
    xcode.import_xliff("#{TEMP}/#{lang}/#{@crowdin_path}")
  end
end

#to_crowdinObject



18
19
20
21
22
23
24
25
26
# File 'lib/xcrowdin/client.rb', line 18

def to_crowdin
  path = "#{TEMP}/xliff"
  lang_code = "en"
  xcode = XcodeClient.new(@xcode_project)
  p "-- start export xliff"
  expoted_path = xcode.export_xliff(lang_code, path)
  p "-- start update_file"
  @crowdin.update_file(expoted_path)
end

#to_xcodeObject



28
29
30
31
32
# File 'lib/xcrowdin/client.rb', line 28

def to_xcode
  @crowdin.export
  @crowdin.download
  import_to_xcode
end

#unzip_file(file, dest) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/xcrowdin/client.rb', line 44

def unzip_file(file, dest)
  FileUtils.mkdir_p(dest)
  Zip::File.open(file) do |zip|
    zip.each do |entry|
      zip.extract(entry, dest + entry.name) { true }
    end
  end
end