Class: StringsUpdater

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

Direct Known Subclasses

AndroidStringsUpdater, IosStringsUpdater

Instance Method Summary collapse

Instance Method Details

#add_comment(comment) ⇒ Object



94
95
96
# File 'lib/strings_updater.rb', line 94

def add_comment(comment)

end

#add_translation(key, to) ⇒ Object



90
91
92
# File 'lib/strings_updater.rb', line 90

def add_translation(key, to)

end

#begin_documentObject

callbacks



82
83
84
# File 'lib/strings_updater.rb', line 82

def begin_document

end

#end_documentObject



86
87
88
# File 'lib/strings_updater.rb', line 86

def end_document

end

#get_document_id(document_id, col) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/strings_updater.rb', line 17

def get_document_id(document_id, col)

  read_settings

  session = GoogleDrive.(@user_name, @user_password)
  @ws = session.spreadsheet_by_key(document_id).worksheets[0]

  @document = ""
  begin_document

  i = 2
  while true


    break if @ws[i, 1] == "."

    add_comment @ws[i, 1] if @ws[i, 1] != ""

    if @ws[i, 2] != ""
      key =  @ws[i, 2].downcase.scan(/[a-z]+/)[0..2].join "_"

      add_translation key, @ws[i, col]
    end

    i += 1
  end

  end_document

  @document

end

#push_project(project_url, output_path, spread_id, branch_name, folder_name, col) ⇒ Object



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
# File 'lib/strings_updater.rb', line 50

def push_project(project_url,output_path,spread_id, branch_name, folder_name, col)
  Dir.chdir working_dictionary
  proj_path = working_dictionary + folder_name

  puts "updating..."
  if File.exist?  folder_name
    Dir.chdir folder_name
    `git pull origin #{branch_name}`
  else
    `git clone #{project_url} #{folder_name}`
    Dir.chdir folder_name
    # exit(-1) if $?.exitstatus != 0
  end

  `git checkout #{branch_name}`

  puts "downloading google document..."
  plist = get_document_id(spread_id, col)

  f = File.new(output_path, "w")
  f.write(plist)
  f.close

  puts "commitintg changes ...."
  `git commit -a -m "update translations"`
  `git push origin #{branch_name}`
  exit(-1) if $?.exitstatus != 0

  puts "DONE"
end

#read_settingsObject



10
11
12
13
14
15
# File 'lib/strings_updater.rb', line 10

def read_settings
  config = IniFile.load "#{Dir.home}/.aplist/cred.cfg", :parameter => ":", :comment => ';'

  @user_name = config["user"]["login"]
  @user_password = config["user"]["password"]
end

#working_dictionaryObject



6
7
8
# File 'lib/strings_updater.rb', line 6

def working_dictionary
  "./"
end