terrestrial-cli 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/terrestrial/cli/bootstrapper.rb +51 -7
- data/lib/terrestrial/cli/flight/ios_workflow.rb +3 -5
- data/lib/terrestrial/cli/flight/table_workflow.rb +2 -3
- data/lib/terrestrial/cli/flight.rb +6 -15
- data/lib/terrestrial/cli/init.rb +6 -6
- data/lib/terrestrial/cli/parser/objc.rb +2 -0
- data/lib/terrestrial/cli/parser/swift.rb +3 -0
- data/lib/terrestrial/cli/push.rb +9 -3
- data/lib/terrestrial/cli/scan.rb +6 -6
- data/lib/terrestrial/cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff2d2337528b5b9713b26919a393b2b145f6d2c
|
4
|
+
data.tar.gz: 1c12b3c56e54a0e81832ca9807ecb1ff8ba35a0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05e9799ac90e76144055d2ad37efeffbb7416e4edfe6647fa07470a41dd0912f3b89ebdb19dfc20d3f0b1c22cce35026becaecc11570bfb2e8684a331964d2a
|
7
|
+
data.tar.gz: b759606eef9ea8b17bb48e993331bf9053057ba65d0e96f8da0fe34d89e40cef6c98416aa5b5a77cae15db27e1cda0fade66d020bd9173a367faa267ad455f24
|
@@ -81,7 +81,6 @@ module Terrestrial
|
|
81
81
|
|
82
82
|
class Bootstrapper
|
83
83
|
class Entry
|
84
|
-
MAX_IDENTIFIER_LENGTH = 10 # words
|
85
84
|
|
86
85
|
def initialize(string, occurences = [])
|
87
86
|
@string = string
|
@@ -104,12 +103,7 @@ module Terrestrial
|
|
104
103
|
end
|
105
104
|
|
106
105
|
def identifier
|
107
|
-
formatted_string
|
108
|
-
.gsub(/%\d\$@/, '')
|
109
|
-
.gsub(/[^0-9a-z ]/i, '')
|
110
|
-
.split(" ")[0..(MAX_IDENTIFIER_LENGTH - 1)]
|
111
|
-
.join("_")
|
112
|
-
.upcase
|
106
|
+
@identifier ||= IdGenerator.generate(formatted_string)
|
113
107
|
end
|
114
108
|
|
115
109
|
def string
|
@@ -179,6 +173,56 @@ module Terrestrial
|
|
179
173
|
end
|
180
174
|
end
|
181
175
|
end
|
176
|
+
|
177
|
+
class IdGenerator
|
178
|
+
MAX_IDENTIFIER_LENGTH = 10 # words
|
179
|
+
|
180
|
+
class << self
|
181
|
+
def generate(string)
|
182
|
+
id = do_generate_id(string)
|
183
|
+
|
184
|
+
attempt = 1
|
185
|
+
while id_already_exists?(id)
|
186
|
+
id = increment_id(id, attempt)
|
187
|
+
attempt += 1
|
188
|
+
end
|
189
|
+
id_history << id
|
190
|
+
id
|
191
|
+
end
|
192
|
+
|
193
|
+
def reset!
|
194
|
+
@history = []
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
|
199
|
+
def increment_id(id, attempt)
|
200
|
+
if id[-1] == (attempt).to_s
|
201
|
+
id[-1] = (attempt + 1).to_s
|
202
|
+
id
|
203
|
+
else
|
204
|
+
id << "_#{attempt + 1}"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def do_generate_id(string)
|
209
|
+
string
|
210
|
+
.gsub(/%\d\$@/, '')
|
211
|
+
.gsub(/[^0-9a-z ]/i, '')
|
212
|
+
.split(" ")[0..(MAX_IDENTIFIER_LENGTH - 1)]
|
213
|
+
.join("_")
|
214
|
+
.upcase
|
215
|
+
end
|
216
|
+
|
217
|
+
def id_already_exists?(id)
|
218
|
+
id_history.any? {|previous| previous == id }
|
219
|
+
end
|
220
|
+
|
221
|
+
def id_history
|
222
|
+
@history ||= []
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
182
226
|
end
|
183
227
|
end
|
184
228
|
end
|
@@ -57,19 +57,17 @@ module Terrestrial
|
|
57
57
|
puts "------------------------------------"
|
58
58
|
puts "-- Done!"
|
59
59
|
puts "- Created Base.lproj in #{lproj_folder}."
|
60
|
+
puts "- All strings in source substituted with IDs."
|
60
61
|
puts "- Remember to include the new localization files in your project!"
|
61
62
|
end
|
62
63
|
|
63
64
|
def print_instructions
|
64
|
-
puts "- Terrestrial will add #{results.length} strings to your base Localizable.strings."
|
65
|
-
puts ""
|
66
65
|
puts "------------------------------------"
|
67
66
|
puts "-- Source Code"
|
68
|
-
puts "-
|
69
|
-
puts "- source code to call .translated?"
|
67
|
+
puts "- Next Terrestrial will modify your source code to reference all the selected strings via IDs."
|
70
68
|
puts "- e.g. \"This is my string\" => \"This is my string\".translated"
|
71
69
|
puts ""
|
72
|
-
puts "y/n?"
|
70
|
+
puts "Continue? y/n?"
|
73
71
|
end
|
74
72
|
|
75
73
|
def results
|
@@ -12,8 +12,6 @@ module Terrestrial
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def run
|
15
|
-
print_instructions
|
16
|
-
|
17
15
|
exclusions = []
|
18
16
|
i = 0
|
19
17
|
|
@@ -56,8 +54,9 @@ module Terrestrial
|
|
56
54
|
puts "-- Instructions --"
|
57
55
|
puts "- To exclude any strings from translation, type the index of each string."
|
58
56
|
puts "- e.g. 1,2,4"
|
57
|
+
puts "- Press return to continue, or 'q' to quit at any time."
|
59
58
|
puts "------------------"
|
60
|
-
puts "Any Exclusions?
|
59
|
+
puts "Any Exclusions?"
|
61
60
|
end
|
62
61
|
|
63
62
|
def file_name_with_line_number(string)
|
@@ -31,28 +31,21 @@ module Terrestrial
|
|
31
31
|
end
|
32
32
|
|
33
33
|
puts "------------------------------------"
|
34
|
-
puts "- Found #{strings.count} strings"
|
34
|
+
puts "- Found #{strings.all_occurences.count} strings"
|
35
35
|
puts ""
|
36
36
|
exclusions = TableWorkflow.new(strings).run
|
37
|
+
strings.exclude_occurences(exclusions)
|
38
|
+
|
37
39
|
puts "------------------------------------"
|
38
40
|
puts "- Done!"
|
41
|
+
puts "- Terrestrial will add #{strings.all_occurences.count} strings to your base Localizable.strings."
|
42
|
+
puts ""
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
if Config[:platform] == "ios"
|
43
|
-
IosWorkflow.new(strings).run
|
44
|
-
elsif Config[:platform] == 'android'
|
45
|
-
android_workflow
|
46
|
-
end
|
44
|
+
IosWorkflow.new(strings).run
|
47
45
|
end
|
48
46
|
|
49
47
|
private
|
50
48
|
|
51
|
-
def android_workflow
|
52
|
-
puts "- Terrestrial will annotate the selected strings in your strings.xml file:"
|
53
|
-
puts "- e.g. <string name='my_name'>My string!</string> => <string terrestrial='true' name='my_name'>My string</string>"
|
54
|
-
end
|
55
|
-
|
56
49
|
def find_new_strings
|
57
50
|
@strings = Bootstrapper.find_new_strings(Config[:directory])
|
58
51
|
end
|
@@ -84,8 +77,6 @@ module Terrestrial
|
|
84
77
|
puts ""
|
85
78
|
puts "For more information, visit http://docs.terrestrial.io/, or jump on our Slack via https://terrestrial-slack.herokuapp.com/"
|
86
79
|
abort
|
87
|
-
else
|
88
|
-
# TODO
|
89
80
|
end
|
90
81
|
end
|
91
82
|
end
|
data/lib/terrestrial/cli/init.rb
CHANGED
@@ -57,16 +57,16 @@ module Terrestrial
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def select_translation_files
|
60
|
-
@
|
60
|
+
@translation_files = []
|
61
61
|
|
62
62
|
files = find_platform_translation_files
|
63
63
|
if files.any?
|
64
|
-
@
|
64
|
+
@translation_files = FilePicker.run(files, @platform)
|
65
65
|
|
66
|
-
if @
|
67
|
-
puts "Tracking #{@
|
66
|
+
if @translation_files.count == 1
|
67
|
+
puts "Tracking #{@translation_files.count} file!"
|
68
68
|
else
|
69
|
-
puts "Tracking #{@
|
69
|
+
puts "Tracking #{@translation_files.count} files!"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -87,7 +87,7 @@ module Terrestrial
|
|
87
87
|
project_id: @project_id,
|
88
88
|
platform: @platform,
|
89
89
|
api_key: @api_key,
|
90
|
-
translation_files: @
|
90
|
+
translation_files: @translation_files
|
91
91
|
})
|
92
92
|
|
93
93
|
Terrestrial::Config.update_global_config
|
@@ -102,6 +102,8 @@ module Terrestrial
|
|
102
102
|
without_strings.include?("DLog") ||
|
103
103
|
without_strings.include?("NSLog") ||
|
104
104
|
without_strings.include?("NSAssert") ||
|
105
|
+
without_strings.downcase.include?(".translated") ||
|
106
|
+
without_strings.downcase.include?("nslocalizedstring") ||
|
105
107
|
without_strings.downcase.include?("uistoryboard") ||
|
106
108
|
without_strings.downcase.include?("instantiateviewcontrollerwithidentifier") ||
|
107
109
|
without_strings.downcase.include?("uiimage") ||
|
@@ -79,9 +79,12 @@ module Terrestrial
|
|
79
79
|
def self.looks_suspicious(line)
|
80
80
|
without_strings = line.gsub(STRING_REGEX, "")
|
81
81
|
without_strings.include?("_LOG") ||
|
82
|
+
without_strings.include?("_LOG") ||
|
82
83
|
without_strings.include?("DLog") ||
|
83
84
|
without_strings.include?("NSLog") ||
|
84
85
|
without_strings.include?("NSAssert") ||
|
86
|
+
without_strings.downcase.include?(".translated") ||
|
87
|
+
without_strings.downcase.include?("nslocalizedstring") ||
|
85
88
|
without_strings.downcase.include?("uistoryboard") ||
|
86
89
|
without_strings.downcase.include?("instantiateviewcontrollerwithidentifier") ||
|
87
90
|
without_strings.downcase.include?("uiimage") ||
|
data/lib/terrestrial/cli/push.rb
CHANGED
@@ -7,9 +7,15 @@ module Terrestrial
|
|
7
7
|
MixpanelClient.track("cli-push-command")
|
8
8
|
load_string_registry
|
9
9
|
|
10
|
-
web_client.push(Config[:project_id], Config[:app_id], format_entries)
|
11
|
-
|
12
|
-
|
10
|
+
response = web_client.push(Config[:project_id], Config[:app_id], format_entries)
|
11
|
+
|
12
|
+
if response.success?
|
13
|
+
puts "Strings uploaded!"
|
14
|
+
else
|
15
|
+
puts "There was an error uploading your translations:"
|
16
|
+
puts response.inspect
|
17
|
+
puts "If the problem persists, contact us at team@terrestrial.io, or on Slack at https://terrestrial-slack.herokuapp.com/"
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
private
|
data/lib/terrestrial/cli/scan.rb
CHANGED
@@ -34,14 +34,14 @@ module Terrestrial
|
|
34
34
|
def print_diff
|
35
35
|
puts "--- Diff"
|
36
36
|
puts "- New Strings"
|
37
|
-
|
37
|
+
puts create_table(new_strings)
|
38
38
|
puts ""
|
39
39
|
puts "- Removed Strings"
|
40
|
-
|
40
|
+
puts create_table(removed_strings)
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
43
|
+
def create_table(strings)
|
44
|
+
Terminal::Table.new(headings: ['Identifier', 'String', 'Comment']) do |t|
|
45
45
|
size = strings.count
|
46
46
|
strings.each_with_index do |string, i|
|
47
47
|
t.add_row([string["identifier"], string["string"], string["context"]])
|
@@ -60,8 +60,8 @@ module Terrestrial
|
|
60
60
|
|
61
61
|
def fetch_current_strings_from_web
|
62
62
|
web_client
|
63
|
-
|
64
|
-
|
63
|
+
.get_app_strings(Config[:project_id], Config[:app_id])
|
64
|
+
.body["data"]["strings"]
|
65
65
|
end
|
66
66
|
|
67
67
|
def web_client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terrestrial-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niklas Begley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|