locca 2.2.1 → 2.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5978bebc86227a0fe1a3d4107d20195fdbc694203aba39ec7c0d961d9d6d65ea
4
- data.tar.gz: e559b2182937946a576c278acab2030c5d7ddfdda62273166434f30cd8b52c50
3
+ metadata.gz: 85bc8e7332a664e063b3699de43982fa2fa04fc2b9cfe5f1d508ca8921196497
4
+ data.tar.gz: 05b435158c0e7ab9c0a4ef1f7a14195d28c4ae6a60eaeedb6c633341cde59051
5
5
  SHA512:
6
- metadata.gz: c957f56a157d38816a1fed311e308d3fa5f3fbcd7d0191778549404914f47960e00808592bf65ee46c60d90a1b9e7ac88b8162d1f11fe559dadd2a9f4b4fb964
7
- data.tar.gz: '081b6a36bfddece0aca9a6105f9a873fbad76337cbbbf14dbbea0228c8428ec13a0b0509c0ba98ab7c1abb56929bf2503783e192d0a0b19823d6908266aac37a'
6
+ metadata.gz: 54dbd87da63f47cd74024614c76b84dd7671a2feda5ca7c87d342728850265553a94411e5449aaa0502337c17053867aeb35eb5b7c39e3835bff80f1594efaf9
7
+ data.tar.gz: '08c972ce6a53bd9aa149dd9af9b5d808f72089ba11c7d2ebfb0020e8f9d5ef786373fc03e4d0e7ad58906997e2c44ab9efefd1c0a6a747d581ce343b398bc2dd'
data/bin/locca CHANGED
@@ -109,6 +109,24 @@ command :translate do |c|
109
109
  end
110
110
  end
111
111
 
112
+ desc 'Audit translation (find missing / extra / untranslated keys)'
113
+ command :audit do |c|
114
+ c.action do |global_options, options, args|
115
+ work_dir = global_options['work-dir'.to_sym]
116
+ if not work_dir
117
+ work_dir = Dir.getwd
118
+ end
119
+
120
+ success = true
121
+ projects_in_dir(work_dir).each { |project|
122
+ if !$locca.audit(project)
123
+ success = false
124
+ end
125
+ }
126
+ exit!(success)
127
+ end
128
+ end
129
+
112
130
  pre do |global, command, options, args|
113
131
  $locca = Locca::Locca.new()
114
132
  true
@@ -0,0 +1,80 @@
1
+ #
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2014 Evgeny Shurakov
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #
24
+
25
+ require 'locca/audit_result'
26
+
27
+ module Locca
28
+ class AuditAction
29
+ def initialize(project, collection_builder, collections_generator)
30
+ @project = project
31
+ @collections_generator = collections_generator
32
+ @collection_builder = collection_builder
33
+ end
34
+
35
+ def execute()
36
+ generated_collections = @collections_generator.generate()
37
+
38
+ audit_ignore = @project.config_value_for_key('audit_ignore')
39
+ failed_audit_results = []
40
+
41
+ @project.collection_names().each do |collection_name|
42
+ keys_to_ignore = []
43
+ if audit_ignore != nil && audit_ignore.key?(collection_name)
44
+ keys_to_ignore = audit_ignore[collection_name]
45
+ end
46
+
47
+ @project.langs().each do |lang|
48
+ collection_path = @project.path_for_collection(collection_name, lang)
49
+ collection = @collection_builder.collection_at_path(collection_path)
50
+
51
+ audit_result = AuditResult.new(collection_name, lang)
52
+
53
+ generated_collections.each do |generated_collection|
54
+ if generated_collection.name == collection.name
55
+ generated_collection_keys = generated_collection.all_keys().to_set
56
+ collection_keys = collection.all_keys().to_set
57
+
58
+ audit_result.missing_keys = (generated_collection_keys - collection_keys).to_a
59
+ audit_result.extra_keys = (collection_keys - generated_collection_keys).to_a
60
+ end
61
+ end
62
+
63
+ collection.sorted_each do |item|
64
+ if item.translated? || keys_to_ignore.include?(item.key) || audit_result.extra_keys.include?(item.key)
65
+ next
66
+ end
67
+
68
+ audit_result.add_untranslated_key(item.key)
69
+ end
70
+
71
+ unless audit_result.passed?
72
+ failed_audit_results.push(audit_result)
73
+ end
74
+ end
75
+ end
76
+
77
+ return failed_audit_results
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2014 Evgeny Shurakov
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #
24
+
25
+ module Locca
26
+ class AuditResult
27
+ attr_reader :collection_name
28
+ attr_reader :lang
29
+ attr_reader :untranslated_keys
30
+ attr_accessor :missing_keys
31
+ attr_accessor :extra_keys
32
+
33
+ def initialize(collection_name, lang)
34
+ @collection_name = collection_name
35
+ @lang = lang
36
+ @untranslated_keys = []
37
+ @missing_keys = []
38
+ @extra_keys = []
39
+ end
40
+
41
+ def add_untranslated_key(value)
42
+ @untranslated_keys.push(value)
43
+ end
44
+
45
+ def passed?
46
+ return @untranslated_keys.empty? && @missing_keys.empty? && @extra_keys.empty?
47
+ end
48
+ end
49
+ end
data/lib/locca/version.rb CHANGED
@@ -22,5 +22,5 @@
22
22
  # SOFTWARE.
23
23
  #
24
24
  module Locca
25
- VERSION = '2.2.1'
25
+ VERSION = '2.2.2'
26
26
  end
data/lib/locca.rb CHANGED
@@ -33,6 +33,7 @@ require 'locca/projects/android_project'
33
33
  require 'locca/config_reader'
34
34
  require 'locca/config_validator'
35
35
 
36
+ require 'locca/actions/audit_action'
36
37
  require 'locca/actions/build_action'
37
38
  require 'locca/actions/merge_action'
38
39
  require 'locca/actions/onesky_sync_action'
@@ -58,6 +59,42 @@ require 'babelyoda/strings_parser'
58
59
 
59
60
  module Locca
60
61
  class Locca
62
+ def audit(project)
63
+ if not project
64
+ raise 'Can\'t initialize Locca with nil project'
65
+ end
66
+
67
+ action = AuditAction.new(project, project.collection_builder(), project.collections_generator())
68
+ failed_audit_results = action.execute()
69
+
70
+ failed_audit_results.each do |audit_result|
71
+ puts()
72
+ puts(">>> #{project.name}/#{audit_result.lang}/#{audit_result.collection_name}")
73
+ unless audit_result.missing_keys.empty?
74
+ puts("Missing Keys:")
75
+ audit_result.missing_keys.each do |key|
76
+ puts("- #{key}")
77
+ end
78
+ end
79
+
80
+ unless audit_result.extra_keys.empty?
81
+ puts("Extra Keys:")
82
+ audit_result.extra_keys.each do |key|
83
+ puts("- #{key}")
84
+ end
85
+ end
86
+
87
+ unless audit_result.untranslated_keys.empty?
88
+ puts("Untranslated:")
89
+ audit_result.untranslated_keys.each do |key|
90
+ puts("- #{key}")
91
+ end
92
+ end
93
+ end
94
+
95
+ return failed_audit_results.empty?
96
+ end
97
+
61
98
  def build(project)
62
99
  if not project
63
100
  raise 'Can\'t initialize Locca with nil project'
@@ -96,7 +133,7 @@ module Locca
96
133
  lang = project.base_lang
97
134
  end
98
135
 
99
- action = TranslateAction.new(project, lang, project.collection_builder, project.collection_writer, collection_merger())
136
+ action = TranslateAction.new(project, lang, project.collection_builder(), project.collection_writer(), collection_merger())
100
137
  action.execute()
101
138
  end
102
139
 
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: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shurakov Evgeny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-04 00:00:00.000000000 Z
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -203,6 +203,7 @@ files:
203
203
  - lib/babelyoda/strings_lexer.rb
204
204
  - lib/babelyoda/strings_parser.rb
205
205
  - lib/locca.rb
206
+ - lib/locca/actions/audit_action.rb
206
207
  - lib/locca/actions/build_action.rb
207
208
  - lib/locca/actions/merge_action.rb
208
209
  - lib/locca/actions/onesky_sync_action.rb
@@ -210,6 +211,7 @@ files:
210
211
  - lib/locca/android_collection_writer.rb
211
212
  - lib/locca/android_collections_generator.rb
212
213
  - lib/locca/android_strings_parser.rb
214
+ - lib/locca/audit_result.rb
213
215
  - lib/locca/collection.rb
214
216
  - lib/locca/collection_builder.rb
215
217
  - lib/locca/collection_item.rb
@@ -249,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
251
  version: '0'
250
252
  requirements: []
251
253
  rubyforge_project:
252
- rubygems_version: 2.7.4
254
+ rubygems_version: 2.7.6
253
255
  signing_key:
254
256
  specification_version: 4
255
257
  summary: Application localization kit