ios_localizer 0.0.1.1 → 0.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/ios_localizer CHANGED
@@ -5,30 +5,63 @@ require 'optparse'
5
5
 
6
6
  # Initialise default constants
7
7
 
8
- key = nil
9
- proj_dir = Dir.pwd
10
- source = "en"
11
- skip = []
8
+ options = {}
12
9
 
10
+ options[:source] = "en"
11
+ options[:skip] = []
13
12
  # Get command line variables
14
13
 
15
- OptionParser.new do |opts|
16
- opts.banner = "Usage: your_app [options]"
14
+ optparse = OptionParser.new do |opts|
15
+ opts.banner = "Usage: ios_localizer"
16
+
17
+ opts.separator ""
18
+ opts.separator "Specific options:"
19
+
17
20
  opts.on('-k [ARG]', '--key [ARG]', "Mandatory Google Translate key") do |v|
18
- key = v
21
+ options[:key] = v
19
22
  end
20
23
  opts.on('-s [ARG]', '--source [ARG]', "Specify the source language") do |v|
21
- source = v
24
+ options[:source] = v
25
+ end
26
+ opts.on('-n [ARG]', '--nolang [ARG]', "Specify languages added to project but should be avoided during translation") do |v|
27
+ options[:skip] << v
28
+ end
29
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
30
+ opts.verbose = v
31
+ end
32
+
33
+ opts.separator ""
34
+ opts.separator "Common options:"
35
+
36
+
37
+ opts.on_tail("-h", "--help", "Show help message") do
38
+ puts opts
39
+ exit
22
40
  end
23
- opts.on('-n [ARG]', '--nolang [ARG]', "Specify the languages gem should avoid converting") do |v|
24
- skip << v
41
+ opts.on_tail("--version", "Show gem version") do
42
+ puts IosLocalizer::VERSION
43
+ exit
25
44
  end
26
45
  end.parse!
27
46
 
28
47
  # Raise appropriate exceptions
29
48
 
30
- raise OptionParser::MissingArgument if key.nil?
49
+ begin
50
+ optparse.parse!
51
+ mandatory = [:key]
52
+ missing = mandatory.select{ |param| options[param].nil? }
53
+ if not missing.empty?
54
+ puts "Missing options: #{missing.join(', ')}"
55
+ puts optparse
56
+ exit
57
+ end
58
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
59
+ puts $!.to_s
60
+ puts optparse
61
+ exit
62
+ end
31
63
 
64
+ puts "Performing task with options: #{options.inspect}"
32
65
  # Pass parameter to script
33
66
 
34
- IosLocalizer.localize(key, proj_dir, source, skip)
67
+ IosLocalizer.localize(options [:key], Dir.pwd, options [:source], options [:skip])
data/lib/ios_localizer.rb CHANGED
@@ -41,7 +41,7 @@ module IosLocalizer
41
41
  def IosLocalizer.localize(key, proj_dir, source, skip)
42
42
 
43
43
  h = HelperMethods.new
44
-
44
+
45
45
  source_strings_file = proj_dir + "/" + source + ".lproj/Localizable.strings"
46
46
 
47
47
  #Get languages
@@ -50,8 +50,19 @@ module IosLocalizer
50
50
 
51
51
  ldata = h.getDataFromURL (lurl)
52
52
 
53
- if ldata.has_key? 'Error'
54
- raise "web service error"
53
+ if ldata.has_key? "error"
54
+ if ldata["error"]["errors"][0]["reason"] == "keyInvalid"
55
+ puts "ERROR: Invalid API Key"
56
+ exit
57
+ else
58
+ puts "ERROR: web service error"
59
+ exit
60
+ end
61
+ end
62
+
63
+ if ldata.count == 0
64
+ puts "Invalid API key"
65
+ exit (1)
55
66
  end
56
67
 
57
68
  languages = Array.new
@@ -1,3 +1,3 @@
1
1
  module IosLocalizer
2
- VERSION = "0.0.1.1"
2
+ VERSION = "0.0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ios_localizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.1
4
+ version: 0.0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-10 00:00:00.000000000 -04:00
13
+ date: 2012-09-16 00:00:00.000000000 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
18
- requirement: &70328367060260 !ruby/object:Gem::Requirement
18
+ requirement: &70272343747100 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70328367060260
26
+ version_requirements: *70272343747100
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: htmlentities
29
- requirement: &70328367059800 !ruby/object:Gem::Requirement
29
+ requirement: &70272343746680 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70328367059800
37
+ version_requirements: *70272343746680
38
38
  description: Uses Google Translate's REST API to properly translate the source Localizable.strings
39
39
  file to each of the specified languages
40
40
  email: