terrestrial-cli 0.6.1 → 0.6.2
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.rb +3 -0
- data/lib/terrestrial/cli/android_xml_formatter.rb +1 -1
- data/lib/terrestrial/cli/detects_project_type.rb +2 -0
- data/lib/terrestrial/cli/editor.rb +1 -1
- data/lib/terrestrial/cli/editor/android_xml.rb +1 -1
- data/lib/terrestrial/cli/editor/{printer.rb → custom_printer.rb} +11 -11
- data/lib/terrestrial/cli/editor/storyboard.rb +35 -17
- data/lib/terrestrial/cli/flight.rb +1 -6
- data/lib/terrestrial/cli/init.rb +3 -1
- data/lib/terrestrial/cli/language_name.rb +64 -0
- data/lib/terrestrial/cli/pull.rb +9 -0
- data/lib/terrestrial/cli/pull/processes_translations.rb +6 -0
- data/lib/terrestrial/cli/string_registry.rb +2 -0
- data/lib/terrestrial/cli/unity_formatter.rb +20 -0
- data/lib/terrestrial/cli/unity_parser.rb +17 -0
- data/lib/terrestrial/cli/version.rb +1 -1
- metadata +6 -4
- data/lib/terrestrial/creates_terrestrial_yml.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec8435d8164544f6ad8189497150081967d15eeb
|
4
|
+
data.tar.gz: 6d009683f9fa3f714afba2565251a0f595528167
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebe46a52b38c1b783d9dcce80a59c96ea7aca70e1d9f46f08b92eb4b27b7004f465270492e01f6e860462d8dfdb8983076ee7e9b6b14fd280a6441db996c3aa8
|
7
|
+
data.tar.gz: 2ae0304f7b6ff1eac841e28d6845cba14a8ccaf65ca3c0dd2351e98d7c9181690dfc8363f440cbdac9d331a9bda96523c68c9f3bf7817d3d50461254c846a14c
|
data/lib/terrestrial/cli.rb
CHANGED
@@ -10,6 +10,7 @@ require "terrestrial/cli/version_checker"
|
|
10
10
|
require "terrestrial/cli/version"
|
11
11
|
require "terrestrial/cli/variable_normalizer"
|
12
12
|
require "terrestrial/cli/terminal_ui"
|
13
|
+
require "terrestrial/cli/language_name"
|
13
14
|
require "terrestrial/cli/entry_collection_differ"
|
14
15
|
require "terrestrial/cli/detects_project_type"
|
15
16
|
require "terrestrial/cli/file_picker"
|
@@ -20,6 +21,8 @@ require "terrestrial/cli/android_xml_parser"
|
|
20
21
|
require "terrestrial/cli/android_xml_formatter"
|
21
22
|
require "terrestrial/cli/dot_strings_parser"
|
22
23
|
require "terrestrial/cli/dot_strings_formatter"
|
24
|
+
require "terrestrial/cli/unity_parser"
|
25
|
+
require "terrestrial/cli/unity_formatter"
|
23
26
|
require "terrestrial/cli/parser"
|
24
27
|
require "terrestrial/cli/editor"
|
25
28
|
require "terrestrial/cli/engine_mapper"
|
@@ -28,7 +28,7 @@ module Terrestrial
|
|
28
28
|
%Q[#@expanded_name="#{to_s().gsub(/"/, '"')}"]
|
29
29
|
end
|
30
30
|
^)
|
31
|
-
formatter =
|
31
|
+
formatter = CustomPrinter.new(4) # See editor/printer
|
32
32
|
formatter.compact = true
|
33
33
|
formatter.write(document,"") + "\n"
|
34
34
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Common fixes for editors that use
|
2
2
|
# REXML
|
3
|
-
class
|
3
|
+
class CustomPrinter < REXML::Formatters::Pretty
|
4
4
|
# The point of this little thing is to keep
|
5
5
|
# the order of attributes when we flush the
|
6
6
|
# storyboard back to disk.
|
@@ -14,17 +14,17 @@ class Printer < REXML::Formatters::Pretty
|
|
14
14
|
# fmt = OrderedAttributes.new
|
15
15
|
# fmt.write(xmldoc, $stdout)
|
16
16
|
#
|
17
|
-
def write_element(elm, out)
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
# def write_element(elm, out)
|
18
|
+
# att = elm.attributes
|
19
|
+
# class <<att
|
20
|
+
# alias _each_attribute each_attribute
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
22
|
+
# def each_attribute(&b)
|
23
|
+
# to_enum(:_each_attribute).sort_by {|x| x.name}.each(&b)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# super(elm, out)
|
27
|
+
# end
|
28
28
|
|
29
29
|
# This genious is here to stop the damn thing from wrapping
|
30
30
|
# lines over 80 chars long >.<
|
@@ -24,63 +24,81 @@ module Terrestrial
|
|
24
24
|
|
25
25
|
def initialize(entry)
|
26
26
|
@path = entry.file
|
27
|
+
@document = REXML::Document.new(File.new(@path))
|
28
|
+
|
27
29
|
@type = entry.type
|
28
30
|
@string = entry.string
|
29
31
|
@storyboard_id = entry.metadata["storyboard_element_id"]
|
30
32
|
@identifier = entry.identifier
|
31
33
|
|
32
|
-
|
34
|
+
set_document_to_double_quotes
|
33
35
|
end
|
34
36
|
|
35
37
|
def self.insert_runtime_attribute(entry)
|
36
|
-
self.new(entry)
|
38
|
+
editor = self.new(entry)
|
39
|
+
editor.insert_attribute
|
40
|
+
editor.save_document
|
37
41
|
end
|
38
42
|
|
39
43
|
def insert_attribute
|
40
|
-
node = find_node
|
44
|
+
node = find_node(@storyboard_id, @type)
|
41
45
|
|
42
46
|
# TODO, There was a case when "node" was nil in this point, after
|
43
47
|
# trying to find it by type + ID.
|
44
48
|
#
|
45
49
|
# Keep an eye out for it to see if reproducible
|
46
50
|
|
47
|
-
node.
|
51
|
+
if node.nil?
|
52
|
+
puts "Warning: Was not able to find #{@type} with string '#{@string}' and ID '#{@storyboard_id}' in #{@path}."
|
53
|
+
puts "It will not be added to your Localizable.strings file automatically."
|
54
|
+
else
|
55
|
+
node.add(create_element)
|
56
|
+
end
|
48
57
|
refresh_document(node)
|
49
|
-
save_document
|
50
58
|
end
|
51
59
|
|
52
|
-
|
60
|
+
def find_node(id, type)
|
61
|
+
REXML::XPath.first(@document, query_for(type, storyboard_id: id))
|
62
|
+
end
|
53
63
|
|
54
|
-
def
|
55
|
-
|
64
|
+
def save_document
|
65
|
+
File.open(@path, "w") do |f|
|
66
|
+
f.write format_document
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def format_document
|
71
|
+
printer = CustomPrinter.new(4)
|
72
|
+
printer.width = 1000
|
73
|
+
printer.compact = true
|
74
|
+
printer.write(@document.root, "")
|
56
75
|
end
|
57
76
|
|
77
|
+
private
|
78
|
+
|
58
79
|
def refresh_document(node)
|
59
80
|
# This is a bit ridiculous, but necessary because
|
60
81
|
# &*£(*$)£@*$!£ REXML
|
61
82
|
|
62
83
|
@document = REXML::Document.new(node.document.to_s)
|
63
|
-
|
64
|
-
|
65
|
-
def save_document
|
66
|
-
File.open(@path, "w") do |f|
|
67
|
-
printer = Printer.new(2)
|
68
|
-
printer.width = 1000
|
69
|
-
printer.write(@document, f)
|
70
|
-
end
|
84
|
+
set_document_to_double_quotes
|
71
85
|
end
|
72
86
|
|
73
87
|
def query_for(type, storyboard_id: "")
|
74
88
|
# Find element of said type, with the ID, that does not
|
75
89
|
# have a userDefinedRuntimeAttribute as a child
|
76
90
|
|
77
|
-
QUERIES[type] + "[@id=\"#{storyboard_id}\" and not(userDefinedRuntimeAttributes)]
|
91
|
+
QUERIES[type] + "[@id=\"#{storyboard_id}\" and not(userDefinedRuntimeAttributes[@Terrestrial])]"
|
78
92
|
end
|
79
93
|
|
80
94
|
def text_attribute(type)
|
81
95
|
Parser::Storyboard::Engine::TEXT_ATTRIBUTE[type]
|
82
96
|
end
|
83
97
|
|
98
|
+
def set_document_to_double_quotes
|
99
|
+
@document.context[:attribute_quote] = :quote
|
100
|
+
end
|
101
|
+
|
84
102
|
def create_element
|
85
103
|
REXML::Element.new("userDefinedRuntimeAttributes")
|
86
104
|
.add_element("userDefinedRuntimeAttribute",
|
@@ -68,12 +68,7 @@ module Terrestrial
|
|
68
68
|
if Config[:platform] == "ios"
|
69
69
|
puts "Looks like you already have Localizable.strings files."
|
70
70
|
puts "'flight' scans your source code for human readable strings that have not been translated"
|
71
|
-
puts "and helps you quickstart your internaionalization process."
|
72
|
-
puts ""
|
73
|
-
puts "If you want to new strings into your .strings file, run 'terrestrial gen'. It will:"
|
74
|
-
puts " 1. Scan your source code for .translated and NSLocalizedString calls."
|
75
|
-
puts " 2. Determine if the strings already exist in Localizable.strings."
|
76
|
-
puts " 3. Append any new strings to your base Localizable.strings."
|
71
|
+
puts "and helps you quickstart your internaionalization process and is works with unlocalized projects only."
|
77
72
|
puts ""
|
78
73
|
puts "For more information, visit http://docs.terrestrial.io/, or jump on our Slack via https://terrestrial-slack.herokuapp.com/"
|
79
74
|
abort
|
data/lib/terrestrial/cli/init.rb
CHANGED
@@ -50,7 +50,7 @@ module Terrestrial
|
|
50
50
|
puts "For more information, see http://docs.terrestrial.io or jump on Slack at https://terrestrial-slack.herokuapp.com/ if you have any questions."
|
51
51
|
else
|
52
52
|
puts "Oh snap. There was an error initializing your project."
|
53
|
-
puts response.body.inspect
|
53
|
+
puts @response.body.inspect
|
54
54
|
abort
|
55
55
|
end
|
56
56
|
end
|
@@ -79,6 +79,8 @@ module Terrestrial
|
|
79
79
|
Dir[Config[:directory] + "/**/*.strings"].map {|f| relative_path(f) }
|
80
80
|
elsif @platform == "android"
|
81
81
|
Dir[Config[:directory] + "/**/*/res/values/strings.xml"].map {|f| relative_path(f) }
|
82
|
+
elsif @platform == "unity"
|
83
|
+
[] # Not tracking files now
|
82
84
|
else
|
83
85
|
raise "Unknown platform #{@platform}"
|
84
86
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Terrestrial
|
2
|
+
module Cli
|
3
|
+
module LanguageName
|
4
|
+
|
5
|
+
LANGUAGES = {
|
6
|
+
"af" => "Afrikaans",
|
7
|
+
"ar" => "Arabic",
|
8
|
+
"eu" => "Basque",
|
9
|
+
"be" => "Belarusian",
|
10
|
+
"bg" => "Bulgarian",
|
11
|
+
"ca" => "Catalan",
|
12
|
+
"cs" => "Czech",
|
13
|
+
"da" => "Danish",
|
14
|
+
"nl" => "Dutch",
|
15
|
+
"en" => "English",
|
16
|
+
"et" => "Estonian",
|
17
|
+
"fo" => "Faroese",
|
18
|
+
"fi" => "Finnish",
|
19
|
+
"fr" => "French",
|
20
|
+
"de" => "German",
|
21
|
+
"el" => "Greek",
|
22
|
+
"he" => "Hebrew",
|
23
|
+
"is" => "Icelandic",
|
24
|
+
"id" => "Indonesian",
|
25
|
+
"it" => "Italian",
|
26
|
+
"ja" => "Japanese",
|
27
|
+
"ko" => "Korean",
|
28
|
+
"lv" => "Latvian",
|
29
|
+
"lt" => "Lithuanian",
|
30
|
+
"no" => "Norwegian",
|
31
|
+
"pl" => "Polish",
|
32
|
+
"pt" => "Portuguese",
|
33
|
+
"ro" => "Romanian",
|
34
|
+
"ru" => "Russian",
|
35
|
+
"sr" => "SerboCroatian",
|
36
|
+
"sk" => "Slovak",
|
37
|
+
"sl" => "Slovenian",
|
38
|
+
"es" => "Spanish",
|
39
|
+
"sv" => "Swedish",
|
40
|
+
"th" => "Thai",
|
41
|
+
"tr" => "Turkish",
|
42
|
+
"uk" => "Ukrainian",
|
43
|
+
"vi" => "Vietnamese",
|
44
|
+
"zh" => "ChineseSimplified",
|
45
|
+
"zh-tw" => "ChineseTraditional",
|
46
|
+
"hu" => "Hungarian"
|
47
|
+
}
|
48
|
+
|
49
|
+
def initialize(language_code)
|
50
|
+
@code = language_code
|
51
|
+
end
|
52
|
+
|
53
|
+
def human_readable_name
|
54
|
+
LANGUAGES.fetch(code) { abort "Unkown language '#{code}' encountered." }
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def code
|
60
|
+
@code
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/terrestrial/cli/pull.rb
CHANGED
@@ -41,6 +41,8 @@ module Terrestrial
|
|
41
41
|
ios_translation_file_path(language)
|
42
42
|
elsif Config[:platform] == "android"
|
43
43
|
android_translation_file_path(language)
|
44
|
+
elsif Config[:platform] == "unity"
|
45
|
+
Config[:directory] + "/Assets/Terrestrial/" + human_readable_language_name(language) + ".xml"
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -72,6 +74,9 @@ module Terrestrial
|
|
72
74
|
elsif Config[:platform] == "android"
|
73
75
|
f.write "<!-- Updated by Terrestrial #{Time.now.to_s} -->\n\n"
|
74
76
|
f.write AndroidXmlFormatter.new(translations).format_foreign_translation
|
77
|
+
elsif Config[:platform] == "unity"
|
78
|
+
f.write "<!-- Updated by Terrestrial #{Time.now.to_s} -->\n\n"
|
79
|
+
f.write UnityFormatter.new(translations).format_foreign_translation
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
@@ -86,6 +91,10 @@ module Terrestrial
|
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
94
|
+
def human_readable_language_name(language_code)
|
95
|
+
LanguageName.new(language_code).human_readable_name
|
96
|
+
end
|
97
|
+
|
89
98
|
def fetch_translations
|
90
99
|
@response = web_client.get_translations(Config[:project_id], Config[:app_id])
|
91
100
|
end
|
@@ -18,11 +18,17 @@ module Terrestrial
|
|
18
18
|
process_ios
|
19
19
|
when "android"
|
20
20
|
process_android
|
21
|
+
when "unity"
|
22
|
+
process_unity
|
21
23
|
else
|
22
24
|
raise "Unknown platform"
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
28
|
+
def process_unity
|
29
|
+
process_android
|
30
|
+
end
|
31
|
+
|
26
32
|
def process_android
|
27
33
|
translations
|
28
34
|
.reject {|entry| entry["translation"].nil? || entry["translation"].empty? }
|
@@ -9,6 +9,8 @@ module Terrestrial
|
|
9
9
|
DotStringsParser.parse_file(Config[:directory] + "/#{file}")
|
10
10
|
elsif Config[:platform] == "android"
|
11
11
|
AndroidXmlParser.parse_file(Config[:directory] + "/#{file}")
|
12
|
+
elsif Config[:platform] == "unity"
|
13
|
+
UnityParser.parse_file(Config[:directory] + "/#{file}")
|
12
14
|
end
|
13
15
|
rescue Errno::ENOENT
|
14
16
|
abort "Could not find #{file}. If the file is no longer in your project, remove it from your tracked files in terrestrial.yml."
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Terrestrial
|
2
|
+
module Cli
|
3
|
+
class UnityFormatter
|
4
|
+
|
5
|
+
def initialize(entries)
|
6
|
+
@formatter = AndroidXmlFormatter.new(entries)
|
7
|
+
end
|
8
|
+
|
9
|
+
def format_foreign_translation
|
10
|
+
formatter.format_foreign_translation
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def formatter
|
16
|
+
@formatter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Terrestrial
|
2
|
+
module Cli
|
3
|
+
class UnityParser
|
4
|
+
|
5
|
+
def self.parse_file(file)
|
6
|
+
# Same file format as Android, so we delegate directly.
|
7
|
+
result = AndroidXmlParser.parse_file(file)
|
8
|
+
|
9
|
+
# Map over the results to change the types
|
10
|
+
# to be unity instead of the Android default.
|
11
|
+
result.map do |entry|
|
12
|
+
entry["type"] = "unity"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
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.6.
|
4
|
+
version: 0.6.2
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -126,8 +126,8 @@ files:
|
|
126
126
|
- lib/terrestrial/cli/editor.rb
|
127
127
|
- lib/terrestrial/cli/editor/android_xml.rb
|
128
128
|
- lib/terrestrial/cli/editor/base_editor.rb
|
129
|
+
- lib/terrestrial/cli/editor/custom_printer.rb
|
129
130
|
- lib/terrestrial/cli/editor/objc.rb
|
130
|
-
- lib/terrestrial/cli/editor/printer.rb
|
131
131
|
- lib/terrestrial/cli/editor/storyboard.rb
|
132
132
|
- lib/terrestrial/cli/editor/swift.rb
|
133
133
|
- lib/terrestrial/cli/engine_mapper.rb
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/terrestrial/cli/flight/table_workflow.rb
|
140
140
|
- lib/terrestrial/cli/ignite.rb
|
141
141
|
- lib/terrestrial/cli/init.rb
|
142
|
+
- lib/terrestrial/cli/language_name.rb
|
142
143
|
- lib/terrestrial/cli/mixpanel_client.rb
|
143
144
|
- lib/terrestrial/cli/parser.rb
|
144
145
|
- lib/terrestrial/cli/parser/android_xml.rb
|
@@ -154,11 +155,12 @@ files:
|
|
154
155
|
- lib/terrestrial/cli/scan.rb
|
155
156
|
- lib/terrestrial/cli/string_registry.rb
|
156
157
|
- lib/terrestrial/cli/terminal_ui.rb
|
158
|
+
- lib/terrestrial/cli/unity_formatter.rb
|
159
|
+
- lib/terrestrial/cli/unity_parser.rb
|
157
160
|
- lib/terrestrial/cli/variable_normalizer.rb
|
158
161
|
- lib/terrestrial/cli/version.rb
|
159
162
|
- lib/terrestrial/cli/version_checker.rb
|
160
163
|
- lib/terrestrial/config.rb
|
161
|
-
- lib/terrestrial/creates_terrestrial_yml.rb
|
162
164
|
- lib/terrestrial/web.rb
|
163
165
|
- lib/terrestrial/web/response.rb
|
164
166
|
- lib/terrestrial/yaml_helper.rb
|