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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f02546d21647512c846dc00c5bef7517f032193
4
- data.tar.gz: 09ef62adc956cad318d07aa365fa61c7f2441508
3
+ metadata.gz: ec8435d8164544f6ad8189497150081967d15eeb
4
+ data.tar.gz: 6d009683f9fa3f714afba2565251a0f595528167
5
5
  SHA512:
6
- metadata.gz: 08e4cc56f181d6de9c2991647c42480055c82c2a721e296762ca10462b561bdc5508268606be2175550d983084346fbad96d128946c7c69fa7afa83432b11e86
7
- data.tar.gz: 1b60b92d14d21cab1b01259ccd721b4ace5c330f68e2a6a64cada40c1cfbcf7c9c8a9044e7511f7acbd9687b9be655b44c7a92b8f60e0f99d77ea34f01da6fc9
6
+ metadata.gz: ebe46a52b38c1b783d9dcce80a59c96ea7aca70e1d9f46f08b92eb4b27b7004f465270492e01f6e860462d8dfdb8983076ee7e9b6b14fd280a6441db996c3aa8
7
+ data.tar.gz: 2ae0304f7b6ff1eac841e28d6845cba14a8ccaf65ca3c0dd2351e98d7c9181690dfc8363f440cbdac9d331a9bda96523c68c9f3bf7817d3d50461254c846a14c
@@ -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 = Printer.new(4) # See editor/printer
31
+ formatter = CustomPrinter.new(4) # See editor/printer
32
32
  formatter.compact = true
33
33
  formatter.write(document,"") + "\n"
34
34
  end
@@ -7,6 +7,8 @@ module Terrestrial
7
7
 
8
8
  if files.any? {|f| f.end_with?(".xcodeproj") || f.end_with?(".xcworkspace")}
9
9
  "ios"
10
+ elsif files.any? {|f| f.end_with?(".csproj") || f.end_with?(".unity") || f.end_with?(".unityproj")}
11
+ "unity"
10
12
  else
11
13
  "android"
12
14
  end
@@ -1,4 +1,4 @@
1
- require 'terrestrial/cli/editor/printer'
1
+ require 'terrestrial/cli/editor/custom_printer'
2
2
  require 'terrestrial/cli/editor/base_editor'
3
3
  require 'terrestrial/cli/editor/objc'
4
4
  require 'terrestrial/cli/editor/swift'
@@ -52,7 +52,7 @@ module Terrestrial
52
52
  end
53
53
  ^)
54
54
  File.open(@path, "w") do |f|
55
- printer = Printer.new(2)
55
+ printer = CustomPrinter.new(2)
56
56
  printer.compact = true
57
57
  printer.width = 1000000
58
58
  printer.write(@document, f)
@@ -1,6 +1,6 @@
1
1
  # Common fixes for editors that use
2
2
  # REXML
3
- class Printer < REXML::Formatters::Pretty
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
- att = elm.attributes
19
- class <<att
20
- alias _each_attribute each_attribute
17
+ # def write_element(elm, out)
18
+ # att = elm.attributes
19
+ # class <<att
20
+ # alias _each_attribute each_attribute
21
21
 
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
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
- @document = REXML::Document.new(File.new(@path))
34
+ set_document_to_double_quotes
33
35
  end
34
36
 
35
37
  def self.insert_runtime_attribute(entry)
36
- self.new(entry).insert_attribute
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.add(create_element)
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
- private
60
+ def find_node(id, type)
61
+ REXML::XPath.first(@document, query_for(type, storyboard_id: id))
62
+ end
53
63
 
54
- def find_node
55
- REXML::XPath.first(@document, query_for(@type, storyboard_id: @storyboard_id))
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
- end
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
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Terrestrial
2
2
  module Cli
3
- VERSION = "0.6.1"
3
+ VERSION = "0.6.2"
4
4
  end
5
5
  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.1
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-12 00:00:00.000000000 Z
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
@@ -1,9 +0,0 @@
1
- module Terrestrial
2
- module Cli
3
- class CreatesTerrestrialYml
4
-
5
- def self.run(project_id, app_id, project_type)
6
- end
7
- end
8
- end
9
- end