smartling_xcode 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a28e04a4e2341fca2af30b77383428cdec69c30
4
+ data.tar.gz: d779c2b54abb8997a8b1c70121752ca37668af11
5
+ SHA512:
6
+ metadata.gz: a62c2cda9df56c354e8508b0424b86df7027531c14c4b10402f3317112cd2cf0c1923b264344b9f57b827ca06dfa6f4f8cf4daf831992201dd09f3c539e45fde
7
+ data.tar.gz: ed1724e98b35eb5c8c9cccce40cc9ec903d843471f118ee74ea3b4310f4b2a9f3f4f8e3d42abac1a4d2ac7b69a7d22fdbcbc9b1bee0a6b1334393dd464598df1
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ /pkg/
3
+ Gemfile.lock
data/CONTRIBUTE.md ADDED
@@ -0,0 +1,23 @@
1
+ # SmartlingXcode
2
+
3
+ To experiment with the code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ $ gem install smartling_xcode
8
+
9
+ ## Development
10
+
11
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
12
+
13
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
14
+
15
+ ## Contributing
16
+
17
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Smartling/api-sdk-xcode.
18
+
19
+
20
+ ## License
21
+
22
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
23
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smartling_xcode.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Emilien Huet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ Smartling utility to extract strings from an Xcode project and add them to a Smartling project.
2
+
3
+ # Installation
4
+ ```
5
+ $ gem install smartling_xcode
6
+ ```
7
+
8
+ # Usage
9
+ ```
10
+ smartling_xcode command [project path]
11
+ smartling_xcode -h/--help
12
+ smartling_xcode -v/--version
13
+ ```
14
+
15
+ # Commands
16
+ * `init` Configure the current folder with Smartling project credentials to be able to push strings.
17
+ * `extract` Extract all strings from the Xcode project and print out the list of .strings files.
18
+ * `push` Extract all strings from the Xcode project and send them to your Smartling project.
19
+
20
+ # Options
21
+ `[project path]` Specify a path for the Xcode project. Uses the first .xcodeproj file in the current directory by default.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smartling_xcode"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "smartling_xcode"
4
+
5
+ # Parse options
6
+ USAGE = <<ENDUSAGE
7
+ Smartling utility to extract strings from an Xcode project and add them to a Smartling project.
8
+ Version #{SmartlingXcode::VERSION}
9
+
10
+ Usage:
11
+ smartling_xcode command [project path]
12
+ smartling_xcode -h/--help
13
+ smartling_xcode -v/--version
14
+
15
+ Commands:
16
+ init Configure the current folder with Smartling project credentials to be able to push strings.
17
+ extract Extract all strings from the Xcode project and print out the list of .strings files.
18
+ push Extract all strings from the Xcode project and send them to your Smartling project.
19
+
20
+ Options:
21
+ [project path] Specify a path for the Xcode project. Uses the first .xcodeproj file in the current directory by default.
22
+
23
+ ENDUSAGE
24
+
25
+ # Parse CLI arguments
26
+ project_path = nil
27
+ command = nil
28
+ ARGV.each do |arg|
29
+ case arg
30
+ # Flags
31
+ when '-v', '--version'
32
+ puts "smartling_xcode version #{SmartlingXcode::VERSION}"
33
+ Kernel.exit(0)
34
+ when '-h', '--help'
35
+ puts USAGE
36
+ Kernel.exit(0)
37
+
38
+ # Commands
39
+ when 'init', 'extract', 'push' then command = arg
40
+
41
+ else
42
+ if command.nil?
43
+ Kernel.abort(USAGE)
44
+ else
45
+ project_path = arg
46
+ end
47
+ end
48
+ end
49
+
50
+ result = SmartlingXcode.execute(command, project_path)
51
+ if result != 0
52
+ Kernel.abort(USAGE)
53
+ end
@@ -0,0 +1,86 @@
1
+ require 'smartling'
2
+ require 'json'
3
+
4
+ module SmartlingXcode
5
+ CREDFILE = './.smartling.json'
6
+
7
+ def self.requestCredentials
8
+ # Check for existing credentials
9
+ if File.exist?(CREDFILE)
10
+ puts "Credentials found in this directory. Overwrite? (y/N)"
11
+ confirm = STDIN.gets.chomp
12
+ case confirm
13
+ when 'y', 'Y'
14
+ # Continue
15
+ else
16
+ Kernel.abort("⚠️ Init cancelled")
17
+ end
18
+ end
19
+
20
+ # Prompt for credentials
21
+ puts "Smartling API Key:"
22
+ api_key = STDIN.gets.chomp
23
+
24
+ puts "Smartling Project ID:"
25
+ project_id = STDIN.gets.chomp
26
+
27
+ # Dummy request to validate creds
28
+ puts "Validating credentials..."
29
+ begin
30
+ sl = Smartling::File.new(:apiKey => api_key, :projectId => project_id)
31
+ res = sl.list
32
+ rescue
33
+ Kernel.abort("⚠️ Invalid credentials")
34
+ end
35
+
36
+ File.open(CREDFILE, "w") do |f|
37
+ f.write({api_key: api_key, project_id: project_id}.to_json)
38
+ puts "Credentials saved"
39
+ end
40
+ end
41
+
42
+ def self.loadCredentials
43
+ if File.exist?(CREDFILE)
44
+ file = File.read(CREDFILE)
45
+ creds = JSON.parse(file)
46
+ if creds['api_key'].nil? || creds['project_id'].nil?
47
+ Kernel.abort("⚠️ Invalid credentials")
48
+ else
49
+ return creds
50
+ end
51
+ else
52
+ Kernel.abort("⚠️ Credentials not found. Please run smartling_xcode init.")
53
+ end
54
+ end
55
+
56
+ def self.pushStringsFromFiles(files, creds)
57
+ sl = Smartling::File.new(:apiKey => creds['api_key'], :projectId => creds['project_id'])
58
+ files.each do |f|
59
+ # Check if file exists
60
+ if !File.exist?(f)
61
+ next
62
+ end
63
+
64
+ # Check if file contains at least one string
65
+ file = File.open(f)
66
+ line = file.read.scrub.tr("\000", '').gsub(/\s+/, "")
67
+ if !line.include?('=')
68
+ puts "No strings in #{f}"
69
+ next
70
+ end
71
+
72
+ # Upload
73
+ begin
74
+ res = sl.upload(f, f.split('/').last, "ios")
75
+ if res
76
+ puts "Uploaded #{res['stringCount']} strings from #{f}"
77
+ end
78
+ rescue Exception => e
79
+ puts "⚠️ Upload failed for #{f}"
80
+ if e.message
81
+ puts e.message
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module SmartlingXcode
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,57 @@
1
+ require 'xcodeproj'
2
+
3
+ module SmartlingXcode
4
+ def self.openProject(path)
5
+ # Get .xcodeproj path
6
+ if path.nil?
7
+ project_file = Dir.entries('./').select {|f| f.end_with?(".xcodeproj") }.first
8
+ path = "./#{project_file}"
9
+ end
10
+
11
+ if !path.nil? && File.exist?(path)
12
+ # Open project
13
+ begin
14
+ project = Xcodeproj::Project.open(path)
15
+ rescue
16
+ Kernel.abort("⚠️ Failed to open project file")
17
+ end
18
+
19
+ return project
20
+ else
21
+ Kernel.abort("⚠️ No .xcodeproj file found")
22
+ end
23
+ end
24
+
25
+ # Returns true if the file is from Base localization or unlocalized
26
+ def self.fromBase(path)
27
+ if path.include?('.lproj')
28
+ return path.include?('Base.lproj')
29
+ else
30
+ return true
31
+ end
32
+ end
33
+
34
+ def self.extract(project)
35
+ strings_files = []
36
+
37
+ # Loop on IB files from Base localization
38
+ project.files.select{|f|
39
+ f.path.end_with?(".xib", ".storyboard") && fromBase(f.path)
40
+ }.each do |f|
41
+ output_name = f.path.gsub(/[\/\.]/, '_')
42
+ output_path = "/tmp/#{output_name}.strings"
43
+ puts "Extracting strings from #{f.path} into #{output_path}"
44
+ Kernel.system("ibtool --generate-strings-file \"#{output_path}\" \"#{f.real_path}\"")
45
+ strings_files.push(output_path)
46
+ end
47
+
48
+ # Loop on .strings files
49
+ project.files.select{|f|
50
+ f.path.end_with?(".strings") && fromBase(f.path)
51
+ }.each do |f|
52
+ strings_files.push(f.real_path)
53
+ end
54
+
55
+ return strings_files
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ require "smartling_xcode/xcode"
2
+ require "smartling_xcode/backend"
3
+ require "smartling_xcode/version"
4
+
5
+ module SmartlingXcode
6
+ def self.execute(command, project_path)
7
+ # Execute commands
8
+ case command
9
+ when 'init'
10
+ requestCredentials
11
+ return 0
12
+ when 'extract'
13
+ files = extract openProject project_path
14
+ puts "\nOutput:"
15
+ puts files
16
+ return 0
17
+ when 'push'
18
+ creds = loadCredentials
19
+ files = extract openProject project_path
20
+ pushStringsFromFiles(files, creds)
21
+ puts "\nYour files are now available in the Files section of your Smartling project."
22
+ return 0
23
+ else
24
+ return 1
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smartling_xcode/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smartling_xcode"
8
+ spec.version = SmartlingXcode::VERSION
9
+ spec.authors = ["Emilien Huet"]
10
+ spec.email = ["ehuet@smartling.com"]
11
+
12
+ spec.summary = %q{Smartling utility to extract strings from an Xcode project and add them to a Smartling project.}
13
+ spec.homepage = "https://github.com/Smartling/api-sdk-xcode"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files`.split($\)
25
+ spec.bindir = "bin"
26
+ spec.executables = ["smartling_xcode"]
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "xcodeproj", ">= 1.1"
30
+ spec.add_dependency "json", ">= 1.8.1"
31
+ spec.add_dependency "smartling", ">= 1.0.1"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.11"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartling_xcode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Emilien Huet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xcodeproj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: smartling
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description:
98
+ email:
99
+ - ehuet@smartling.com
100
+ executables:
101
+ - smartling_xcode
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - CONTRIBUTE.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - bin/smartling_xcode
114
+ - lib/smartling_xcode.rb
115
+ - lib/smartling_xcode/backend.rb
116
+ - lib/smartling_xcode/version.rb
117
+ - lib/smartling_xcode/xcode.rb
118
+ - smartling_xcode.gemspec
119
+ homepage: https://github.com/Smartling/api-sdk-xcode
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Smartling utility to extract strings from an Xcode project and add them to
143
+ a Smartling project.
144
+ test_files: []