crowdin-cli 0.0.8 → 0.0.9

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.
data/README.md CHANGED
@@ -38,7 +38,7 @@ base_path: /path/to/your/project
38
38
  files:
39
39
  -
40
40
  source: /locale/en/LC_MESSAGES/messages.po
41
- translation: /locale/%two_letter_code%/LC_MESSAGES/%original_file_name%
41
+ translation: /locale/%two_letters_code%/LC_MESSAGES/%original_file_name%
42
42
  ```
43
43
 
44
44
  * `api_key` - Crowdin Project API key
@@ -51,8 +51,8 @@ files:
51
51
 
52
52
  Use the following placeholders to put appropriate variables into the resulting file name:
53
53
  * `%language%` - Language name (i.e. Ukrainian)
54
- * `%two_letter_code%` - Language code ISO 639-1 (i.e. uk)
55
- * `%three_letter_code%` - Language code ISO 639-2/T (i.e. ukr)
54
+ * `%two_letters_code%` - Language code ISO 639-1 (i.e. uk)
55
+ * `%three_letters_code%` - Language code ISO 639-2/T (i.e. ukr)
56
56
  * `%locale%` - Locale (like uk-UA)
57
57
  * `%locale_with_underscore%` - Locale (i.e. uk_UA)
58
58
  * `%original_file_name%` - Original file name
@@ -67,7 +67,7 @@ files:
67
67
  ```
68
68
  Example for Gettext projects:
69
69
  ```
70
- /locale/%two_letter_code%/LC_MESSAGES/%original_file_name%
70
+ /locale/%two_letters_code%/LC_MESSAGES/%original_file_name%
71
71
  ```
72
72
 
73
73
  Also you can add and upload all directories mathing the pattern including all nested files and localizable files.
@@ -83,7 +83,7 @@ base_path: /path/to/your/project
83
83
  files:
84
84
  -
85
85
  source: /locale/en/**/*.po
86
- translation: /locale/%two_letter_code%/**/%original_file_name%
86
+ translation: /locale/%two_letters_code%/**/%original_file_name%
87
87
  ```
88
88
  ## Usage
89
89
 
data/bin/crowdin-cli CHANGED
@@ -40,6 +40,30 @@ def walk_local_tree(files, result = { dirs: [], files: [] })
40
40
  return result
41
41
  end
42
42
 
43
+ # +path_ - relative path to file in Crowdin project
44
+ # +export_pattern+ - basically, is a file['translation'] from crowdin.yaml
45
+ # +lang+ - Hash containing language information
46
+ #
47
+ def export_pattern_to_path(path, export_pattern, lang)
48
+ original_path = File.dirname(path)
49
+ original_file_name = File.basename(path)
50
+ file_extension = File.extname(path)[1..-1]
51
+ file_name = File.basename(path, file_extension)
52
+
53
+ export_pattern.gsub(/%.+?%/, {
54
+ '%language%' => lang['name'],
55
+ '%two_letters_code%' => lang['iso_639_1'],
56
+ '%tree_letters_code%' => lang['iso_639_3'],
57
+ '%locale%' => lang['locale'],
58
+ '%locale_with_underscore%' => lang['locale'].gsub('-', '_'),
59
+ '%android_code%' => android_locale_code(lang['locale']),
60
+ '%original_file_name%' => original_file_name,
61
+ '%original_path%' => original_path,
62
+ '%file_extension%' => file_extension,
63
+ '%file_name%' => file_extension,
64
+ })
65
+ end
66
+
43
67
  def unzip_file(file, dest)
44
68
  # overwrite files if they already exist inside of the extracted path
45
69
  Zip.options[:on_exists_proc] = true
@@ -119,23 +143,7 @@ command :upload do |c|
119
143
  else
120
144
  Dir.glob("#{@base_path}#{file['source']}").each do |source|
121
145
  dest = source.sub("#{@base_path}", '') # relative path in Crowdin
122
- original_path = File.dirname(dest)
123
- original_file_name = File.basename(dest)
124
- file_extension = File.extname(dest)
125
- file_name = File.basename(dest, file_extension)
126
-
127
- file_pattern = file['translation'].gsub(/%.+?%/, {
128
- '%language%' => source_language['name'],
129
- '%two_letter_code%' => source_language['iso_639_1'],
130
- '%tree_letter_code%' => source_language['iso_639_3'],
131
- '%locale%' => source_language['locale'],
132
- '%locale_with_underscore%' => source_language['locale'].gsub('-', '_'),
133
- '%original_file_name%' => original_file_name,
134
- '%android_code%' => android_locale_code(source_language['locale']),
135
- '%original_path%' => original_path,
136
- '%file_extension%' => file_extension,
137
- '%file_name%' => file_extension,
138
- })
146
+ file_pattern = export_pattern_to_path(dest, file['translation'], source_language)
139
147
 
140
148
  diff = (dest.split('/') - file_pattern.split('/')).join('/')
141
149
  export_pattern = file['translation'].sub('**', diff)
@@ -220,64 +228,23 @@ command :upload do |c|
220
228
  @config['files'].each do |file|
221
229
  if File.exists?("#{@base_path}#{file['source']}")
222
230
  dest = file['source'].sub("#{@base_path}", '')
223
- original_path = File.dirname(dest)
224
- original_file_name = File.basename(dest)
225
- file_extension = File.extname(dest)[1..-1]
226
- file_name = File.basename(dest, file_extension)
227
231
 
228
232
  translation_languages.each do |lang|
229
- source = file['translation'].gsub(/%.+?%/, {
230
- '%language%' => lang['name'],
231
- '%two_letter_code%' => lang['iso_639_1'],
232
- '%tree_letter_code%' => lang['iso_639_3'],
233
- '%locale%' => lang['locale'],
234
- '%locale_with_underscore%' => lang['locale'].gsub('-', '_'),
235
- '%original_file_name%' => original_file_name,
236
- '%android_code%' => android_locale_code(lang['locale']),
237
- '%original_path%' => original_path,
238
- '%file_extension%' => file_extension,
239
- '%file_name%' => file_extension,
240
- })
233
+ source = export_pattern_to_path(dest, file['translation'], lang)
241
234
 
242
235
  translated_files[lang['crowdin_code']] << { source: "#{@base_path}#{source}", dest: dest }
243
236
  end
244
237
  else
245
238
  Dir.glob("#{@base_path}#{file['source']}").each do |source|
246
239
  dest = source.sub("#{@base_path}", '')
247
- original_path = File.dirname(dest)
248
- original_file_name = File.basename(dest)
249
- file_extension = File.extname(dest)
250
- file_name = File.basename(dest, file_extension)
251
-
252
- file_pattern = file['translation'].gsub(/%.+?%/, {
253
- '%language%' => source_language['name'],
254
- '%two_letter_code%' => source_language['iso_639_1'],
255
- '%tree_letter_code%' => source_language['iso_639_3'],
256
- '%locale%' => source_language['locale'],
257
- '%locale_with_underscore%' => source_language['locale'].gsub('-', '_'),
258
- '%original_file_name%' => original_file_name,
259
- '%android_code%' => android_locale_code(source_language['locale']),
260
- '%original_path%' => original_path,
261
- '%file_extension%' => file_extension,
262
- '%file_name%' => file_extension,
263
- })
240
+
241
+ file_pattern = export_pattern_to_path(dest, file['translation'], source_language)
264
242
 
265
243
  diff = (dest.split('/') - file_pattern.split('/')).join('/')
266
244
  export_pattern = file['translation'].sub('**', diff)
267
245
 
268
246
  translation_languages.each do |lang|
269
- source = export_pattern.gsub(/%.+?%/, {
270
- '%language%' => lang['name'],
271
- '%two_letter_code%' => lang['iso_639_1'],
272
- '%tree_letter_code%' => lang['iso_639_3'],
273
- '%locale%' => lang['locale'],
274
- '%locale_with_underscore%' => lang['locale'].gsub('-', '_'),
275
- '%original_file_name%' => original_file_name,
276
- '%android_code%' => android_locale_code(lang['locale']),
277
- '%original_path%' => original_path,
278
- '%file_extension%' => file_extension,
279
- '%file_name%' => file_extension,
280
- })
247
+ source = export_pattern_to_path(dest, export_pattern, lang)
281
248
 
282
249
  translated_files[lang['crowdin_code']] << { source: "#{@base_path}#{source}", dest: dest }
283
250
  end
@@ -1,5 +1,5 @@
1
1
  module Crowdin
2
2
  module CLI
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowdin-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -96,7 +96,7 @@ dependencies:
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - '='
99
+ - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: 0.0.8
102
102
  type: :runtime
@@ -104,7 +104,7 @@ dependencies:
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - '='
107
+ - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: 0.0.8
110
110
  description: