transifex-interface-ruby 0.0.1

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.
Files changed (57) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +513 -0
  6. data/Rakefile +1 -0
  7. data/lib/transifex.rb +87 -0
  8. data/lib/transifex/crud_requests.rb +99 -0
  9. data/lib/transifex/errors.rb +25 -0
  10. data/lib/transifex/formats.rb +9 -0
  11. data/lib/transifex/json.rb +23 -0
  12. data/lib/transifex/language.rb +13 -0
  13. data/lib/transifex/languages.rb +13 -0
  14. data/lib/transifex/project.rb +38 -0
  15. data/lib/transifex/project_components/language.rb +39 -0
  16. data/lib/transifex/project_components/language_components/coordinators.rb +29 -0
  17. data/lib/transifex/project_components/language_components/reviewers.rb +33 -0
  18. data/lib/transifex/project_components/language_components/translators.rb +33 -0
  19. data/lib/transifex/project_components/languages.rb +21 -0
  20. data/lib/transifex/projects.rb +22 -0
  21. data/lib/transifex/resource.rb +41 -0
  22. data/lib/transifex/resource_components/content.rb +54 -0
  23. data/lib/transifex/resource_components/source.rb +23 -0
  24. data/lib/transifex/resource_components/stats.rb +26 -0
  25. data/lib/transifex/resource_components/translation.rb +59 -0
  26. data/lib/transifex/resource_components/translation_components/string.rb +29 -0
  27. data/lib/transifex/resource_components/translation_components/strings.rb +39 -0
  28. data/lib/transifex/resource_components/translation_components/utilities.rb +22 -0
  29. data/lib/transifex/resources.rb +19 -0
  30. data/lib/transifex/version.rb +3 -0
  31. data/spec/lib/transifex/configuration_spec.rb +17 -0
  32. data/spec/lib/transifex/coordinators_spec.rb +32 -0
  33. data/spec/lib/transifex/formats_spec.rb +13 -0
  34. data/spec/lib/transifex/language_spec.rb +19 -0
  35. data/spec/lib/transifex/languages_spec.rb +13 -0
  36. data/spec/lib/transifex/project_language_spec.rb +49 -0
  37. data/spec/lib/transifex/project_languages_spec.rb +35 -0
  38. data/spec/lib/transifex/project_spec.rb +91 -0
  39. data/spec/lib/transifex/projects_spec.rb +48 -0
  40. data/spec/lib/transifex/resource_content_spec.rb +40 -0
  41. data/spec/lib/transifex/resource_source_spec.rb +30 -0
  42. data/spec/lib/transifex/resource_spec.rb +66 -0
  43. data/spec/lib/transifex/resources_spec.rb +50 -0
  44. data/spec/lib/transifex/reviewers_spec.rb +32 -0
  45. data/spec/lib/transifex/stats_spec.rb +34 -0
  46. data/spec/lib/transifex/translation_spec.rb +53 -0
  47. data/spec/lib/transifex/translation_string_spec.rb +33 -0
  48. data/spec/lib/transifex/translation_strings_spec.rb +57 -0
  49. data/spec/lib/transifex/translators_spec.rb +32 -0
  50. data/spec/lib/yaml/en.yml +26 -0
  51. data/spec/lib/yaml/fr.yml +4 -0
  52. data/spec/lib/yaml/resource_content_test.yml +27 -0
  53. data/spec/lib/yaml/resource_translation_default_content_test.yml +4 -0
  54. data/spec/lib/yaml/resource_translation_reviewed_content_test.yml +9 -0
  55. data/spec/spec_helper.rb +96 -0
  56. data/transifex-interface-ruby.gemspec +25 -0
  57. metadata +181 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDI5MmRmMmZhMjVlYzU1NWI0NDZkNTVlYmYzODYyNmJiODAwYzlkMQ==
5
+ data.tar.gz: !binary |-
6
+ YjJmYjhlOGFmMmE2ZWQxMzZiOThmYzM0NTAwY2ExMjJmNjI5ZjlkNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Mjk2ZmY2ZjM3NmE0Y2MyOTA4OGE5Y2FkZmMzMDVhZTk5N2RiNDcyYzhmNDll
10
+ ZThlODlhMDU2MGZlOGQwMTgxODA3NzdhNjVhOTIxYzU0ZGUzYzFhYWRkOTJk
11
+ MTAwNTAxOTQ0YTVlYTIyMzliNDAwOGM2NTczYTI2ZmFmZDlhNjE=
12
+ data.tar.gz: !binary |-
13
+ YjBlYWE2ZTI0NjJkMjc5MjM5NmYzNmMyZTg1MmY5NzIwNTJlMTBlMGIyZDY5
14
+ ODMyNDdmNTBjYjQ0Nzc0OTM3YWQyOGY5NjdkZGQwNTI1Yzk0MzliY2YxMmQy
15
+ NDRjZjNiMzc5YWI4Y2IwYTI1NjgwMGY1YjRmZDE0YWYxOTUxMWI=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transifex-interface-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Fred-grais
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,513 @@
1
+ # Transifex::Interface::Ruby
2
+
3
+ This gem is designed to interact easily with the Transifex API. You can perform all the actions allowed by the API. Documentation located here : http://docs.transifex.com/developer/api/
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'transifex-interface-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install transifex-interface-ruby
18
+
19
+ ## Usage
20
+
21
+ ### Initialization
22
+
23
+ To initialize the gem, you will have to create an initializer like follow:
24
+
25
+ ```ruby
26
+ Transifex.configure do |c|
27
+ c.client_login = 'your_client_login'
28
+ c.client_secret = 'your_secret'
29
+ end
30
+ ```
31
+ Then restart the server.
32
+
33
+ If you don't do this you will end up with the following error:
34
+
35
+ ```ruby
36
+ #<Transifex::TransifexError: Authorization Required>
37
+ ```
38
+
39
+ ### Formats
40
+
41
+ It represents all the formats available on Transifex:
42
+
43
+ ```ruby
44
+ Transifex::Formats.fetch
45
+ ```
46
+
47
+ ### Languages
48
+
49
+ It represents all the languages available on Transifex:
50
+
51
+ #### Fetch
52
+
53
+ You can fetch all the languages:
54
+
55
+ ```ruby
56
+ Transifex::Languages.fetch
57
+ ```
58
+
59
+ Or specify a language:
60
+
61
+ ```ruby
62
+ Transifex::Languages.fetch('en')
63
+ ```
64
+
65
+ ### Projects (to fetch all projects and create a new one)
66
+
67
+ #### Fetch
68
+
69
+ To fetch all the projects owned by the account specified in the initializer:
70
+
71
+ ```ruby
72
+ Transifex::Projects.fetch
73
+ ```
74
+
75
+ #### Create
76
+
77
+ To create a new project, you can proceed as following:
78
+
79
+ For a private project:
80
+
81
+ ```ruby
82
+ private_project_params = {:slug => "private_project", :name => "Private Project", :description => "description", :source_language_code => "en", :private => true}
83
+
84
+ Transifex::Projects.create(private_project_params)
85
+ ```
86
+ For a public project:
87
+
88
+ ```ruby
89
+ public_project_params = {:slug => "public_project", :name => "Public Project", :description => "description", :source_language_code => "en", :repository_url => "http://example.com"}
90
+
91
+ Transifex::Projects.create(public_project_params)
92
+ ```
93
+
94
+ The complete list of the allowed parameters is located in the Transifex documentation.
95
+
96
+ ### Project (symbolize an existing project)
97
+
98
+ #### Instantiation
99
+
100
+ ```ruby
101
+ transifex_project = Transifex::Project.new('project_slug')
102
+ ```
103
+ or
104
+
105
+ ```ruby
106
+ transifex_project = Transifex::Projects.create(params)
107
+ ```
108
+ #### Fetch
109
+
110
+ You can fetch the project informations from transifex:
111
+
112
+ ```ruby
113
+ transifex_project_informations = transifex_project.fetch
114
+ ```
115
+
116
+ with more details:
117
+
118
+ ```ruby
119
+ transifex_project_informations = transifex_project.fetch_with_details
120
+ ```
121
+
122
+ #### Update
123
+
124
+ You can update the project: (see documentation for available fields)
125
+
126
+ ```ruby
127
+ transifex_project.update({:description => "new description"})
128
+ ```
129
+ #### Destroy
130
+
131
+ You can destroy a project:
132
+
133
+ ```ruby
134
+ transifex_project.delete
135
+ ```
136
+
137
+ ### Project Languages ( to fetch all languages of a project and create a new one)
138
+
139
+
140
+ #### Instantiation
141
+
142
+ ```ruby
143
+ project_languages = transifex_project.languages
144
+ ```
145
+
146
+ #### Fetch
147
+
148
+ You can retrieve informations about all the languages of a project:
149
+
150
+ ```ruby
151
+ project_languages.fetch
152
+ ```
153
+
154
+ #### Create
155
+
156
+ You can create a new language for a project:
157
+
158
+ ```ruby
159
+ params = {:language_code => "el", :coordinators => ['username']}
160
+ project_languages.create(params)
161
+ ```
162
+
163
+ ### Project Language (Symbolize a single language of a project)
164
+
165
+ #### Instantiation
166
+
167
+ ```ruby
168
+ project_language = transifex_project.language('en')
169
+ ```
170
+
171
+ #### Fetch
172
+
173
+ You can retrieve informations for a project's specified language:
174
+
175
+ ```ruby
176
+ project_language.fetch
177
+ ```
178
+
179
+ with details:
180
+
181
+ ```ruby
182
+ project_language.fetch_with_details
183
+ ```
184
+
185
+ #### Update
186
+
187
+ You can update the information of a project's specified language:
188
+
189
+ ```ruby
190
+ params = {:coordinators => ['username1', 'username2'], :translators => ['username'], :reviewers => ['username']}
191
+ project_language.update(params)
192
+ ```
193
+
194
+ #### Delete
195
+
196
+ You can delete a project's specified language:
197
+
198
+ ```ruby
199
+ project_language.delete
200
+ ```
201
+
202
+ ### Project language management
203
+
204
+ You have access to the differents teams of a language: coordinators, reviewers and translators.
205
+
206
+ #### Instantiation:
207
+
208
+ ```ruby
209
+ project_language_coordinators_team = project_language.coordinators
210
+ project_language_reviewers_team = project_language.reviewers
211
+ project_language_translators_team = project_language.translators
212
+ ```
213
+
214
+ #### Fetch
215
+
216
+ ```ruby
217
+ project_language_xxx_team.fetch
218
+ ```
219
+
220
+ #### Update
221
+
222
+ ```ruby
223
+ project_language_xxx_team.update(['username1', 'username2'])
224
+ ```
225
+
226
+ ### Resources ( to fetch all resources of a project and create a new one)
227
+
228
+ First, instantiate a project (see Project/instantiation)
229
+
230
+ #### Fetch
231
+
232
+ You can fetch all the resources of projects:
233
+
234
+ ```ruby
235
+ transifex_project.resources
236
+ ```
237
+
238
+ #### Create
239
+
240
+ You can create a new resource for the specified project:
241
+
242
+ Without a file (you have to send the content as a string) :
243
+
244
+ ```ruby
245
+ transifex_project.resources.create({:slug => "p", :name => "without_file", :i18n_type => "TXT", :content => "test"})
246
+ ```
247
+
248
+ With a file: (YAML currently supported)
249
+
250
+ ```ruby
251
+ options = {:trad_from_file => true}
252
+ transifex_project.resources.create({:slug => "q", :name => "with_file", :i18n_type => "YAML", :content => 'path/to/your/file.yml'}
253
+ ```
254
+
255
+ ### Resource (Symbolize a single resource of a project)
256
+
257
+ #### Instantiation
258
+
259
+ You can instantiate a resource as follow:
260
+
261
+ ```ruby
262
+ project_resource = transifex_project.resource("resource_slug")
263
+ ```
264
+
265
+ #### Fetch
266
+
267
+ You can retrieve informations of the specified resource:
268
+
269
+ ```ruby
270
+ project_resource.fetch
271
+ ```
272
+ with more details:
273
+
274
+ ```ruby
275
+ project_resource.fetch_with_details
276
+ ```
277
+
278
+ #### Update
279
+
280
+ You can update a resource: (see documentation for allowed fields)
281
+
282
+ ```ruby
283
+ project_resource.update({name: "new_name", categories: ["cat1", "cat2"]})
284
+ ```
285
+
286
+ #### Delete
287
+
288
+ You can delete the specified resource:
289
+
290
+ ```ruby
291
+ project_resource.delete
292
+ ```
293
+
294
+ ### Resource Content ( Source language content)
295
+
296
+ You can manage the resource's source language
297
+
298
+ #### Fetch
299
+
300
+ You can retrieve the source language content:
301
+
302
+ As a hash: (content is encoded as a string)
303
+
304
+ ```ruby
305
+ project_resource.content.fetch
306
+ ```
307
+
308
+ Or as a file
309
+ Here for a YAML file:
310
+
311
+ ```ruby
312
+ project_resource.content.fetch_with_file("path/where/file/will/be/saved.yml")
313
+ ```
314
+ The source language content will be copied in the specified file.
315
+
316
+ #### Update
317
+
318
+ You can update the source language content (add new traductions for example):
319
+ Attention: the source language content will be overrided.
320
+
321
+ You must update the source language content with the same method used to create the resource.
322
+
323
+ So if you used a YAML file, you must provide a new YAML file.
324
+
325
+ With the content as a string:
326
+
327
+ ```ruby
328
+ project_resource.content.update({:i18n_type => "TXT", :content => 'new_content'})
329
+ ```
330
+
331
+ With a file:
332
+
333
+ ```ruby
334
+ project_resource.content.update({:i18n_type => "YAML", :content => 'path/to/your/file.yml'})
335
+ ```
336
+
337
+ ### Resource Translations
338
+
339
+ The following will explain how you can fetch the different translations of a resource and update them.
340
+
341
+ You have to specify the language you want to work on.
342
+ For example to work on the english translation:
343
+
344
+ ```ruby
345
+ resource_translation = project_resource.translation('en')
346
+ ```
347
+
348
+ #### Fetch
349
+
350
+ You can fetch the translation content of a resource:
351
+
352
+ As a Hash: (content encoded as a string)
353
+
354
+ ```ruby
355
+ resource_translation.fetch
356
+ ```
357
+
358
+ As a file: (file saved to the specified location)
359
+
360
+ ```ruby
361
+ options = {:path_to_file => path_to_file}
362
+ resource_translation.fetch_with_file(options)
363
+ ```
364
+
365
+ You can use some options (as defined in the transifex documentations)
366
+
367
+ For example to retrieve only reviewed translations:
368
+
369
+ ```ruby
370
+ options = {:path_to_file => path_to_file, :mode => "reviewed"}
371
+ resource_translation.fetch_with_file(options)
372
+ ```
373
+
374
+ #### Update
375
+
376
+ You can update the translation content:
377
+
378
+ ```ruby
379
+ options = {:i18n_type => "YAML", :content => "/path/to/the/file/to/upload.yml"}
380
+ resource_translation.update(options)
381
+ ```
382
+
383
+ ### Resource Translations Strings
384
+
385
+ Resource translations strings allow you to retrieve meta-informations about translations strings (translation key, context, content, and so on)
386
+
387
+ #### Instantiation
388
+
389
+ ```ruby
390
+ resource_translation_strings = resource_translation.strings
391
+ ```
392
+
393
+ #### Fetch
394
+
395
+ You can fetch informations of all the strings of a translation:
396
+
397
+ ```ruby
398
+ resource_translation_strings.fetch
399
+ ```
400
+
401
+ With details:
402
+
403
+ ```ruby
404
+ resource_translation_strings.fetch_with_details
405
+ ```
406
+
407
+ You can specify a key and/or a context to search a particular string
408
+
409
+ ```ruby
410
+ options = {:key => "welcome", :context => "context"}
411
+ resource_translation_strings.fetch_with_details(options)
412
+ ```
413
+
414
+ #### Update
415
+
416
+ You can update some informations of a translation string (see documentation for available fields):
417
+
418
+ You must specify at least the key of the translation, and can add a context(by default empty).
419
+
420
+ ```ruby
421
+ options = {:key => "welcome", :context => "context"}
422
+ resource_translation_strings.update({:key => "welcome", :context => "", :translation => "new_translation"})
423
+ ```
424
+ ### Resource Translations String (Symbolize a single string)
425
+
426
+ #### Instantiation
427
+
428
+ Context is empty by default.
429
+
430
+ ```ruby
431
+ resource_translation_string = resource_translation.string(key, context)
432
+ ```
433
+
434
+ #### Fetch
435
+
436
+ You can fetch the informations about the specified string:
437
+
438
+ ```ruby
439
+ resource_translation_string.fetch
440
+ ```
441
+
442
+ #### Update
443
+
444
+ You can update the informations of the specified string: (available fields in the documentation)
445
+
446
+ ```ruby
447
+ params = {:reviewed => true, :translation => "new translation"}
448
+ resource_translation_string.update(params)
449
+ ```
450
+
451
+ ### Resource Source String
452
+
453
+ It allow you to retrieve meta-data on a source language string and update them.
454
+
455
+ #### Instantiation
456
+
457
+ Context is empty by default.
458
+
459
+ ```ruby
460
+ resource_source_string = project_resource.source(key, context)
461
+ ```
462
+
463
+ #### Fetch
464
+
465
+ You can fetch meta-data about the specified source string:
466
+
467
+ ```ruby
468
+ resource_source_string.fetch
469
+ ```
470
+
471
+ #### Update
472
+
473
+ You can update the meta-data of the specified source string
474
+
475
+ ```ruby
476
+ params = {:comment => "my comment", :character_limit => 140, :tags => ["tag1", "tag2"]}
477
+ resource_source_string.update(params)
478
+ ```
479
+
480
+ ### Resource Statistics
481
+
482
+ It allow you to retrieve some transifex stats about a resource.
483
+
484
+ #### Instantiation
485
+
486
+ ```ruby
487
+ resource_stats = project_resource.statistics
488
+ ```
489
+
490
+ #### Fetch
491
+
492
+ You can fetch the statistics:
493
+
494
+ Of all the the resource languages:
495
+
496
+ ```ruby
497
+ resource_stats.fetch
498
+ ```
499
+
500
+ Of a specified language:
501
+
502
+ ```ruby
503
+ resource_stats.fetch('en')
504
+ ```
505
+
506
+
507
+ ## Contributing
508
+
509
+ 1. Fork it
510
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
511
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
512
+ 4. Push to the branch (`git push origin my-new-feature`)
513
+ 5. Create new Pull Request