phraseapp_android 0.2.0 → 0.3.0

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: e93e77c6176e4fae785005ad6e07522cf258961b
4
- data.tar.gz: 1801f2e7bda8d371c5240145b69ee0671aa022fd
3
+ metadata.gz: 3e5139f1a0cf880f123934b4aa27bc94d2921042
4
+ data.tar.gz: ded9010d9639f38e3f44c15d5df8d0624aa4fb86
5
5
  SHA512:
6
- metadata.gz: 4436a3b1498b843cc05d71787e909716327ec6c34b5a652c8b430e354f62b9c2800337937bb194f9045c4117e1c4f4353c521eed73f211f6d4a67f9bc4e157c3
7
- data.tar.gz: 740ddce5b12a579e27ee4aae46fde0aba2e02155fe0651ed0e856728481fd926abfe1e8349c55e7842d15b39aa3e53a38a87ed42a19cd0311b9bccc140940a77
6
+ metadata.gz: fa9e1a581a30861167d740aa42ad8492f406141f185acda4eecc673f22f9294db064e60035d226069dbf8141a98e0a97c04f113e780d4dc77bb6de8a8111c3bc
7
+ data.tar.gz: 2eabeceff879bb801bb5d5774a48ff99adc129614a45796ff2a3e5e218f641831c341fed006b3479253eeeb8a8758600e96333bf5e3b62cf15f5c1f47d967440
@@ -11,7 +11,9 @@ class PhraseApp::Android::FormatCheck < PhraseApp::Android::PhraseAppClient
11
11
  end
12
12
 
13
13
  def perform
14
- locales.map { |l| perform_for_locale(l) }.reduce(:+)
14
+ count = locales.map { |l| perform_for_locale(l) }.reduce(:+)
15
+ puts 'All texts are ok.'.green
16
+ count
15
17
  end
16
18
 
17
19
  def perform_for_locale(locale)
@@ -44,6 +44,10 @@ class PhraseApp::Android::MissingTranslations < PhraseApp::Android::PhraseAppCli
44
44
  arrays: {added: 0, updated: 0}
45
45
  }
46
46
 
47
+ default_strings = doc_to_hash read_locale_file('strings', nil)
48
+ default_arrays = doc_to_hash read_locale_file('arrays', nil)
49
+ default = default_strings.merge default_arrays
50
+
47
51
  strings = doc_to_hash read_locale_file('strings', locale)
48
52
  arrays = doc_to_hash read_locale_file('arrays', locale)
49
53
  current = strings.merge arrays
@@ -52,8 +56,8 @@ class PhraseApp::Android::MissingTranslations < PhraseApp::Android::PhraseAppCli
52
56
  doc = Nokogiri::XML client.locale_download(project_id, locale, params)
53
57
  recent = doc_to_hash doc
54
58
 
55
- merge_translations current, recent, :strings, stats
56
- merge_translations current, recent, :arrays, stats
59
+ merge_translations default, current, recent, :strings, stats, locale
60
+ merge_translations default, current, recent, :arrays, stats, locale
57
61
 
58
62
  formatter = PhraseApp::Android::FileFormatter.new
59
63
 
@@ -71,9 +75,9 @@ class PhraseApp::Android::MissingTranslations < PhraseApp::Android::PhraseAppCli
71
75
  updated = stats[:strings][:updated] + stats[:arrays][:updated]
72
76
 
73
77
  if added + updated > 0
74
- puts "#{added + updated} keys were updated!".green
78
+ puts "#{added + updated} keys were updated for #{locale} locale!".green
75
79
  else
76
- puts 'no keys were updated.'.yellow
80
+ puts "no keys were updated for #{locale} locale.".yellow
77
81
  end
78
82
 
79
83
  stats
@@ -110,22 +114,36 @@ class PhraseApp::Android::MissingTranslations < PhraseApp::Android::PhraseAppCli
110
114
  result.reject { |k, v| v.empty? }
111
115
  end
112
116
 
113
- def merge_translations(current, updated, key, stats)
117
+ def merge_translations(default, current, updated, key, stats, locale)
114
118
  updated[key].each do |name, values|
115
- current[key] ||= {}
116
- current_value = current[key][name]
117
- if current_value
118
- if values != current_value
119
+ if default[key][name]
120
+ current[key] ||= {}
121
+ current_value = current[key][name]
122
+ # auto prettify string resources
123
+ values = clean_up_string values if values.is_a? String
124
+ values = values.map { |item| clean_up_string item } if values.is_a? Array
125
+
126
+ if current_value
127
+ if values != current_value
128
+ if values.is_a?(Array) && values.size != current_value.size
129
+ puts "MERGE CONFLICT for #{name} array in #{locale} locale!\n#{current_value.inspect} vs #{values.inspect}".red
130
+ else
131
+ current[key][name] = values
132
+ stats[key][:updated] += 1
133
+ end
134
+ end
135
+ else
119
136
  current[key][name] = values
120
- stats[key][:updated] += 1
137
+ stats[key][:added] += 1
121
138
  end
122
- else
123
- current[key][name] = values
124
- stats[key][:added] += 1
125
139
  end
126
140
  end
127
141
  end
128
142
 
143
+ def clean_up_string(value)
144
+ value.strip.gsub '...', '…'
145
+ end
146
+
129
147
  def hash_to_doc(source)
130
148
  doc = Nokogiri::XML::Document.new
131
149
  doc.encoding = 'utf-8'
@@ -1,3 +1,3 @@
1
1
  module PhraseappAndroid
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phraseapp_android
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Glukhov (serggl)