locca 0.9.3 → 0.9.4

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: 59c4dfcb6f714c36e0e945658fde5705de3bb971
4
- data.tar.gz: ac9cdc3cf716780c68acabaa7a22fec331722501
3
+ metadata.gz: bb1bf664519519f97a3250a89d70ef348a0efa90
4
+ data.tar.gz: 8b82a46b329742f94474f86ee2d6d1c41b01da38
5
5
  SHA512:
6
- metadata.gz: 6dab801c6e1d3e582ce3285bbfffa1afcb8f5ca111f48a07dfe0d828115b995589a747ee9b87b5445afdc843bec8c145fea9c1057298deabbddbba8a11f66e58
7
- data.tar.gz: aaa95ea21cbf1c66ae5eec112753c27566d04a3bc19f0d69f8b17d93dd7485e468fe0b1249d3c0ba07c48b1b9dd79b71f092859de031d88a1d82eb9efdda4997
6
+ metadata.gz: d76dabd3da74919b09647e9ab6f0d5ce673d184d870ef656da73413c3f01b3bae7dba35690f4e027baca9d8366003584925c64e6f2255be6d853c4bd2861bb9a
7
+ data.tar.gz: ec1c116543af7a0ba1f2bddc62922efcc816b357437ac71e1d5d054a2326f1899fba753e3b84368973899252f3cd5af8b81dc90b8aab18b47b2f3befa9c7a037
data/bin/locca CHANGED
@@ -60,7 +60,7 @@ command :merge do |c|
60
60
  end
61
61
  end
62
62
 
63
- desc 'Sync translations with external translation service'
63
+ desc 'Sync (fetch, merge and upload new) translations with external translation service'
64
64
  command :sync do |c|
65
65
  c.action do |global_options, options, args|
66
66
  work_dir = global_options['work-dir'.to_sym]
@@ -72,6 +72,18 @@ command :sync do |c|
72
72
  end
73
73
  end
74
74
 
75
+ desc 'Fetch and merge translations from external translation service'
76
+ command :fetch do |c|
77
+ c.action do |global_options, options, args|
78
+ work_dir = global_options['work-dir'.to_sym]
79
+ if not work_dir
80
+ work_dir = Dir.getwd
81
+ end
82
+
83
+ $locca.fetch(project_in_dir(work_dir))
84
+ end
85
+ end
86
+
75
87
  desc 'Translate the untranslated'
76
88
  command :translate do |c|
77
89
  c.action do |global_options, options, args|
@@ -33,7 +33,7 @@ require 'locca/config_validator'
33
33
 
34
34
  require 'locca/actions/build_action'
35
35
  require 'locca/actions/merge_action'
36
- require 'locca/actions/sync_action'
36
+ require 'locca/actions/onesky_sync_action'
37
37
  require 'locca/actions/translate_action'
38
38
 
39
39
  require 'locca/sync/onesky'
@@ -57,12 +57,7 @@ module Locca
57
57
  raise 'Can\'t initialize Locca with nil project'
58
58
  end
59
59
 
60
- genstrings = Genstrings.new()
61
- collection_builder = collection_builder()
62
- collections_generator = CollectionsGenerator.new(genstrings, collection_builder)
63
-
64
- action = BuildAction.new(project, collection_builder, collection_writer(), collections_generator, collection_merger())
65
- action.execute()
60
+ build_action(project).execute()
66
61
  end
67
62
 
68
63
  def merge(src_file, dst_file)
@@ -75,14 +70,15 @@ module Locca
75
70
  raise 'Can\'t initialize Locca with nil project'
76
71
  end
77
72
 
78
- genstrings = Genstrings.new()
79
- collection_builder = collection_builder()
80
- collections_generator = CollectionsGenerator.new(genstrings, collection_builder)
81
-
82
- onesky = Onesky.new(project.config_value_for_key('onesky_project_id'), project.config_value_for_key('onesky_public_key'), project.config_value_for_key('onesky_secret_key'))
73
+ one_sky_action(project).sync()
74
+ end
83
75
 
84
- action = SyncAction.new(project, collection_builder, collection_writer(), collections_generator, collection_merger(), onesky)
85
- action.execute()
76
+ def fetch(project)
77
+ if not project
78
+ raise 'Can\'t initialize Locca with nil project'
79
+ end
80
+
81
+ one_sky_action(project).fetch()
86
82
  end
87
83
 
88
84
  def translate(project, lang = nil)
@@ -99,6 +95,24 @@ module Locca
99
95
  action.execute()
100
96
  end
101
97
 
98
+ def build_action(project)
99
+ genstrings = Genstrings.new()
100
+ collection_builder = collection_builder()
101
+ collections_generator = CollectionsGenerator.new(genstrings, collection_builder)
102
+
103
+ return BuildAction.new(project, collection_builder, collection_writer(), collections_generator, collection_merger())
104
+ end
105
+
106
+ def one_sky_action(project)
107
+ genstrings = Genstrings.new()
108
+ collection_builder = collection_builder()
109
+ collections_generator = CollectionsGenerator.new(genstrings, collection_builder)
110
+
111
+ onesky = Onesky.new(project.config_value_for_key('onesky_project_id'), project.config_value_for_key('onesky_public_key'), project.config_value_for_key('onesky_secret_key'))
112
+
113
+ return OneskySyncAction.new(project, onesky, collection_builder(), collection_writer(), collections_generator, collection_merger())
114
+ end
115
+
102
116
  def collection_builder()
103
117
  parser = Babelyoda::StringsParser.new(Babelyoda::StringsLexer.new())
104
118
  return CollectionBuilder.new(File, parser)
@@ -30,24 +30,24 @@
30
30
  require 'locca/collection_merger'
31
31
 
32
32
  module Locca
33
- class SyncAction
34
- def initialize(project, collection_builder, collection_writer, collections_generator, collection_merger, onesky)
33
+ class OneskySyncAction
34
+ def initialize(project, onesky, collection_builder, collection_writer, collections_generator, collection_merger)
35
35
  @project = project
36
36
  @collections_generator = collections_generator
37
37
  @collection_merger = collection_merger
38
38
  @collection_builder = collection_builder
39
39
  @collection_writer = collection_writer
40
40
  @onesky = onesky
41
- end
42
41
 
43
- def execute()
44
- langs = @project.langs()
45
- generated_collections = @collections_generator.generate(@project.code_dir())
42
+ @langs = @project.langs()
43
+ @generated_collections = @collections_generator.generate(@project.code_dir())
44
+ end
46
45
 
46
+ def fetch()
47
47
  # 1
48
- generated_collections.each do |generated_collection|
49
- langs.each do |lang|
50
- print "\t* fetch: #{lang}/#{generated_collection.name}.strings\n"
48
+ @generated_collections.each do |generated_collection|
49
+ @langs.each do |lang|
50
+ print "[*] fetch: #{lang}/#{generated_collection.name}.strings\n"
51
51
  data = @onesky.fetch_translations(lang, "#{generated_collection.name}.strings")
52
52
  fetched_collection = @collection_builder.collection_from_datastring(data)
53
53
 
@@ -55,16 +55,20 @@ module Locca
55
55
  local_collection = @collection_builder.collection_at_path(local_collection_path)
56
56
 
57
57
  # 2
58
- print "\t* merge: onesky -> #{lang}/#{generated_collection.name}.strings\n"
58
+ print "[*] merge: onesky -> #{lang}/#{generated_collection.name}.strings\n"
59
59
  @collection_merger.merge(fetched_collection, local_collection, CollectionMerger::ACTION_ADD | CollectionMerger::ACTION_UPDATE)
60
60
  @collection_writer.write_to_path(local_collection, local_collection_path)
61
61
  end
62
62
  end
63
+ end
64
+
65
+ def sync()
66
+ fetch()
63
67
 
64
68
  # 3
65
- generated_collections.each do |generated_collection|
66
- langs.each do |lang|
67
- print "\t* merge: code -> #{lang}/#{generated_collection.name}.strings\n"
69
+ @generated_collections.each do |generated_collection|
70
+ @langs.each do |lang|
71
+ print "[*] merge: code -> #{lang}/#{generated_collection.name}.strings\n"
68
72
 
69
73
  collection_path = @project.path_for_collection(generated_collection.name, lang)
70
74
  collection = @collection_builder.collection_at_path(collection_path)
@@ -74,8 +78,8 @@ module Locca
74
78
  end
75
79
 
76
80
  # 4
77
- generated_collections.each do |generated_collection|
78
- print "\t* upload: #{@project.base_lang}/#{generated_collection.name}.strings\n"
81
+ @generated_collections.each do |generated_collection|
82
+ print "[*] upload: #{@project.base_lang}/#{generated_collection.name}.strings\n"
79
83
  collection_path = @project.path_for_collection(generated_collection.name, @project.base_lang())
80
84
  @onesky.upload_file(collection_path)
81
85
  end
@@ -32,7 +32,10 @@ module Locca
32
32
  command = "find #{code_dir} -iname \"*.m\" -or -iname \"*.mm\" -or -iname \"*.c\" | xargs genstrings -o '#{tmp_dir}'"
33
33
  stdout, stderr, status = Open3.capture3(command)
34
34
 
35
- STDERR.puts(stderr)
35
+ stderr = stderr.strip
36
+ if stderr.length > 0
37
+ STDERR.puts()
38
+ end
36
39
 
37
40
  if status.success?
38
41
  Dir.glob(File.join(tmp_dir, '*.strings')) do |filename|
@@ -22,5 +22,5 @@
22
22
  # SOFTWARE.
23
23
  #
24
24
  module Locca
25
- VERSION = '0.9.3'
25
+ VERSION = '0.9.4'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shurakov Evgeny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-13 00:00:00.000000000 Z
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -107,7 +107,7 @@ files:
107
107
  - lib/babelyoda/strings_parser.rb
108
108
  - lib/locca/actions/build_action.rb
109
109
  - lib/locca/actions/merge_action.rb
110
- - lib/locca/actions/sync_action.rb
110
+ - lib/locca/actions/onesky_sync_action.rb
111
111
  - lib/locca/actions/translate_action.rb
112
112
  - lib/locca/collection.rb
113
113
  - lib/locca/collection_builder.rb