transifex-interface-ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +17 -17
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -4
  5. data/LICENSE.txt +22 -22
  6. data/README.md +517 -513
  7. data/Rakefile +1 -1
  8. data/lib/transifex.rb +84 -87
  9. data/lib/transifex/crud_requests.rb +43 -33
  10. data/lib/transifex/errors.rb +4 -4
  11. data/lib/transifex/project_components/language.rb +1 -1
  12. data/lib/transifex/project_components/language_components/coordinators.rb +4 -6
  13. data/lib/transifex/project_components/language_components/reviewers.rb +5 -8
  14. data/lib/transifex/project_components/language_components/translators.rb +6 -9
  15. data/lib/transifex/project_components/languages.rb +1 -1
  16. data/lib/transifex/resource.rb +1 -1
  17. data/lib/transifex/resource_components/content.rb +1 -1
  18. data/lib/transifex/resource_components/source.rb +1 -1
  19. data/lib/transifex/resource_components/stats.rb +1 -1
  20. data/lib/transifex/resource_components/translation.rb +1 -1
  21. data/lib/transifex/resource_components/translation_components/string.rb +1 -1
  22. data/lib/transifex/resource_components/translation_components/strings.rb +1 -1
  23. data/lib/transifex/resources.rb +1 -1
  24. data/lib/transifex/version.rb +3 -3
  25. data/spec/cassettes/fetch_formats.yml +121 -0
  26. data/spec/cassettes/language/fetch_language_info.yml +58 -0
  27. data/spec/cassettes/language/fetch_languages_info.yml +58 -0
  28. data/spec/cassettes/project/components/create_language.yml +95 -0
  29. data/spec/cassettes/project/components/create_language_non_existing_coordinator.yml +48 -0
  30. data/spec/cassettes/project/components/create_language_without_coordinator.yml +48 -0
  31. data/spec/cassettes/project/components/fetch_languages.yml +53 -0
  32. data/spec/cassettes/project/delete_project.yml +108 -0
  33. data/spec/cassettes/project/fetch_private_project_info.yml +59 -0
  34. data/spec/cassettes/project/fetch_with_details_private_project_info.yml +66 -0
  35. data/spec/cassettes/project/language/delete_language.yml +140 -0
  36. data/spec/cassettes/project/language/fetch_coordinators.yml +56 -0
  37. data/spec/cassettes/project/language/fetch_language_info.yml +52 -0
  38. data/spec/cassettes/project/language/fetch_reviewers.yml +56 -0
  39. data/spec/cassettes/project/language/fetch_translators.yml +54 -0
  40. data/spec/cassettes/project/language/fetch_with_details_language_info.yml +54 -0
  41. data/spec/cassettes/project/language/update_coordinators.yml +104 -0
  42. data/spec/cassettes/project/language/update_language.yml +100 -0
  43. data/spec/cassettes/project/language/update_non_existing_coordinator.yml +48 -0
  44. data/spec/cassettes/project/language/update_non_existing_language.yml +49 -0
  45. data/spec/cassettes/project/language/update_non_existing_reviewer.yml +101 -0
  46. data/spec/cassettes/project/language/update_non_existing_translator.yml +101 -0
  47. data/spec/cassettes/project/language/update_reviewers.yml +157 -0
  48. data/spec/cassettes/project/language/update_translators.yml +157 -0
  49. data/spec/cassettes/project/update_non_existing_attribute_private_project.yml +54 -0
  50. data/spec/cassettes/project/update_private_project.yml +120 -0
  51. data/spec/cassettes/project/update_with_missing_params_private_project.yml +54 -0
  52. data/spec/cassettes/projects/create_private_project.yml +111 -0
  53. data/spec/cassettes/projects/create_public_project.yml +111 -0
  54. data/spec/cassettes/projects/create_used_slug_project.yml +55 -0
  55. data/spec/cassettes/projects/fetch_projects.yml +61 -0
  56. data/spec/cassettes/resource/delete_not_existing_resource.yml +55 -0
  57. data/spec/cassettes/resource/delete_resource.yml +160 -0
  58. data/spec/cassettes/resource/fetch_all_languages_stats.yml +66 -0
  59. data/spec/cassettes/resource/fetch_content_as_file.yml +56 -0
  60. data/spec/cassettes/resource/fetch_content_as_hash.yml +58 -0
  61. data/spec/cassettes/resource/fetch_language_stats.yml +61 -0
  62. data/spec/cassettes/resource/fetch_not_existing_resource.yml +55 -0
  63. data/spec/cassettes/resource/fetch_resource_info.yml +59 -0
  64. data/spec/cassettes/resource/fetch_source_string_metadata.yml +52 -0
  65. data/spec/cassettes/resource/fetch_translations.yml +57 -0
  66. data/spec/cassettes/resource/fetch_updated_resource_info.yml +60 -0
  67. data/spec/cassettes/resource/fetch_updated_source_string_metadata.yml +52 -0
  68. data/spec/cassettes/resource/fetch_with_details_resource_info.yml +65 -0
  69. data/spec/cassettes/resource/fetch_with_file_and_mode_translations.yml +56 -0
  70. data/spec/cassettes/resource/fetch_with_file_translations.yml +56 -0
  71. data/spec/cassettes/resource/update_content_json.yml +115 -0
  72. data/spec/cassettes/resource/update_content_with_wrong_mimetype.yml +59 -0
  73. data/spec/cassettes/resource/update_content_yml.yml +114 -0
  74. data/spec/cassettes/resource/update_not_existing_resource.yml +55 -0
  75. data/spec/cassettes/resource/update_resource_info.yml +114 -0
  76. data/spec/cassettes/resource/update_source_language.yml +54 -0
  77. data/spec/cassettes/resource/update_source_string_metadata.yml +100 -0
  78. data/spec/cassettes/resource/update_translation_for_language.yml +62 -0
  79. data/spec/cassettes/resources/create_from_file.yml +55 -0
  80. data/spec/cassettes/resources/create_from_string.yml +54 -0
  81. data/spec/cassettes/resources/fetch_as_array.yml +62 -0
  82. data/spec/cassettes/resources/non_existing_project.yml +55 -0
  83. data/spec/cassettes/translation/fetch_string.yml +55 -0
  84. data/spec/cassettes/translation/fetch_strings.yml +54 -0
  85. data/spec/cassettes/translation/fetch_with_details_and_context_strings.yml +51 -0
  86. data/spec/cassettes/translation/fetch_with_details_and_key_strings.yml +56 -0
  87. data/spec/cassettes/translation/fetch_with_details_strings.yml +56 -0
  88. data/spec/cassettes/translation/update_multiple_translation_strings.yml +107 -0
  89. data/spec/cassettes/translation/update_single_translation_strings.yml +104 -0
  90. data/spec/cassettes/translation/update_string.yml +104 -0
  91. data/spec/lib/transifex/coordinators_spec.rb +22 -16
  92. data/spec/lib/transifex/formats_spec.rb +8 -8
  93. data/spec/lib/transifex/language_spec.rb +9 -10
  94. data/spec/lib/transifex/languages_spec.rb +8 -8
  95. data/spec/lib/transifex/project_language_spec.rb +41 -28
  96. data/spec/lib/transifex/project_languages_spec.rb +34 -18
  97. data/spec/lib/transifex/project_spec.rb +46 -73
  98. data/spec/lib/transifex/projects_spec.rb +72 -37
  99. data/spec/lib/transifex/resource_content_spec.rb +41 -24
  100. data/spec/lib/transifex/resource_source_spec.rb +21 -19
  101. data/spec/lib/transifex/resource_spec.rb +69 -41
  102. data/spec/lib/transifex/resources_spec.rb +42 -34
  103. data/spec/lib/transifex/reviewers_spec.rb +23 -17
  104. data/spec/lib/transifex/stats_spec.rb +20 -24
  105. data/spec/lib/transifex/translation_spec.rb +60 -38
  106. data/spec/lib/transifex/translation_string_spec.rb +26 -20
  107. data/spec/lib/transifex/translation_strings_spec.rb +65 -43
  108. data/spec/lib/transifex/translators_spec.rb +23 -17
  109. data/spec/lib/transifex_spec.rb +15 -0
  110. data/spec/lib/yaml/eo.yml +3 -0
  111. data/spec/spec_helper.rb +19 -83
  112. data/spec/support/client_helper.rb +8 -0
  113. data/spec/support/content_helper.rb +346 -0
  114. data/transifex-interface-ruby.gemspec +28 -25
  115. metadata +198 -21
  116. data/spec/lib/transifex/configuration_spec.rb +0 -17
  117. data/spec/lib/yaml/resource_translation_default_content_test.yml +0 -4
  118. data/spec/lib/yaml/resource_translation_reviewed_content_test.yml +0 -9
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
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=
2
+ SHA1:
3
+ metadata.gz: 54b9106f9ec2eb907afe6d31b83220b71a029bda
4
+ data.tar.gz: a9dc02d1e3fb33f07a78f9257b093d1708354f4a
5
+ SHA512:
6
+ metadata.gz: f0bfbb7d12edea0056a45646b347a34b6fef917d2e92cc7f5a56ced642a9a1ad4a0aed5e5b29b4cb657832252855f3a1a5ca844348eb20800bc6f2280211996a
7
+ data.tar.gz: 6e2e44980dd82c9258d709ca105351570a32227da83c5143fa0634d6e24ab02774759cc6e3b37c9dc3b81be064372f75065688b25248ee480e5bc94b5fd5eb73
data/.gitignore CHANGED
@@ -1,17 +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
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order rand
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in transifex-interface-ruby.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transifex-interface-ruby.gemspec
4
+ gemspec
@@ -1,22 +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.
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.
data/README.md CHANGED
@@ -1,513 +1,517 @@
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
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.fetch
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
+ params = {:slug => "resource_slug", :name => "Resource created with content as a string", :i18n_type => "TXT", :content => "test"}
246
+ transifex_project.resources.create(params)
247
+ ```
248
+
249
+ With a file: (YAML currently supported)
250
+
251
+ ```ruby
252
+ params = {:slug => "resource_slug", :name => "Resource created with a file", :i18n_type => "YAML", :content => 'path/to/your/file.yml'}
253
+ options = {:trad_from_file => true}
254
+ transifex_project.resources.create(params, options)
255
+ ```
256
+
257
+ ### Resource (Symbolize a single resource of a project)
258
+
259
+ #### Instantiation
260
+
261
+ You can instantiate a resource as follow:
262
+
263
+ ```ruby
264
+ project_resource = transifex_project.resource("resource_slug")
265
+ ```
266
+
267
+ #### Fetch
268
+
269
+ You can retrieve informations of the specified resource:
270
+
271
+ ```ruby
272
+ project_resource.fetch
273
+ ```
274
+ with more details:
275
+
276
+ ```ruby
277
+ project_resource.fetch_with_details
278
+ ```
279
+
280
+ #### Update
281
+
282
+ You can update a resource: (see documentation for allowed fields)
283
+
284
+ ```ruby
285
+ project_resource.update({name: "new_name", categories: ["cat1", "cat2"]})
286
+ ```
287
+
288
+ #### Delete
289
+
290
+ You can delete the specified resource:
291
+
292
+ ```ruby
293
+ project_resource.delete
294
+ ```
295
+
296
+ ### Resource Content ( Source language content)
297
+
298
+ You can manage the resource's source language
299
+
300
+ #### Fetch
301
+
302
+ You can retrieve the source language content:
303
+
304
+ As a hash: (content is encoded as a string)
305
+
306
+ ```ruby
307
+ project_resource.content.fetch
308
+ ```
309
+
310
+ Or as a file
311
+ Here for a YAML file:
312
+
313
+ ```ruby
314
+ project_resource.content.fetch_with_file("path/where/file/will/be/saved.yml")
315
+ ```
316
+ The source language content will be copied in the specified file.
317
+
318
+ #### Update
319
+
320
+ You can update the source language content (add new traductions for example):
321
+ Attention: the source language content will be overrided.
322
+
323
+ You must update the source language content with the same method used to create the resource.
324
+
325
+ So if you used a YAML file, you must provide a new YAML file.
326
+
327
+ With the content as a string:
328
+
329
+ ```ruby
330
+ project_resource.content.update({:i18n_type => "TXT", :content => 'new_content'})
331
+ ```
332
+
333
+ With a file:
334
+
335
+ ```ruby
336
+ params = {:i18n_type => "YAML", :content => 'path/to/your/file.yml'}
337
+ options = {:trad_from_file => true}
338
+ project_resource.content.update(params, options)
339
+ ```
340
+
341
+ ### Resource Translations
342
+
343
+ The following will explain how you can fetch the different translations of a resource and update them.
344
+
345
+ You have to specify the language you want to work on.
346
+ For example to work on the english translation:
347
+
348
+ ```ruby
349
+ resource_translation = project_resource.translation('en')
350
+ ```
351
+
352
+ #### Fetch
353
+
354
+ You can fetch the translation content of a resource:
355
+
356
+ As a Hash: (content encoded as a string)
357
+
358
+ ```ruby
359
+ resource_translation.fetch
360
+ ```
361
+
362
+ As a file: (file saved to the specified location)
363
+
364
+ ```ruby
365
+ options = {:path_to_file => path_to_file}
366
+ resource_translation.fetch_with_file(options)
367
+ ```
368
+
369
+ You can use some options (as defined in the transifex documentations)
370
+
371
+ For example to retrieve only reviewed translations:
372
+
373
+ ```ruby
374
+ options = {:path_to_file => path_to_file, :mode => "reviewed"}
375
+ resource_translation.fetch_with_file(options)
376
+ ```
377
+
378
+ #### Update
379
+
380
+ You can update the translation content:
381
+
382
+ ```ruby
383
+ options = {:i18n_type => "YAML", :content => "/path/to/the/file/to/upload.yml"}
384
+ resource_translation.update(options)
385
+ ```
386
+
387
+ ### Resource Translations Strings
388
+
389
+ Resource translations strings allow you to retrieve meta-informations about translations strings (translation key, context, content, and so on)
390
+
391
+ #### Instantiation
392
+
393
+ ```ruby
394
+ resource_translation_strings = resource_translation.strings
395
+ ```
396
+
397
+ #### Fetch
398
+
399
+ You can fetch informations of all the strings of a translation:
400
+
401
+ ```ruby
402
+ resource_translation_strings.fetch
403
+ ```
404
+
405
+ With details:
406
+
407
+ ```ruby
408
+ resource_translation_strings.fetch_with_details
409
+ ```
410
+
411
+ You can specify a key and/or a context to search a particular string
412
+
413
+ ```ruby
414
+ options = {:key => "welcome", :context => "context"}
415
+ resource_translation_strings.fetch_with_details(options)
416
+ ```
417
+
418
+ #### Update
419
+
420
+ You can update some informations of a translation string (see documentation for available fields):
421
+
422
+ You must specify at least the key of the translation, and can add a context(by default empty).
423
+
424
+ ```ruby
425
+ params = {:key => "welcome", :context => "", :translation => "new_translation"}
426
+ resource_translation_strings.update(params)
427
+ ```
428
+ ### Resource Translations String (Symbolize a single string)
429
+
430
+ #### Instantiation
431
+
432
+ Context is empty by default.
433
+
434
+ ```ruby
435
+ resource_translation_string = resource_translation.string(key, context)
436
+ ```
437
+
438
+ #### Fetch
439
+
440
+ You can fetch the informations about the specified string:
441
+
442
+ ```ruby
443
+ resource_translation_string.fetch
444
+ ```
445
+
446
+ #### Update
447
+
448
+ You can update the informations of the specified string: (available fields in the documentation)
449
+
450
+ ```ruby
451
+ params = {:reviewed => true, :translation => "new translation"}
452
+ resource_translation_string.update(params)
453
+ ```
454
+
455
+ ### Resource Source String
456
+
457
+ It allow you to retrieve meta-data on a source language string and update them.
458
+
459
+ #### Instantiation
460
+
461
+ Context is empty by default.
462
+
463
+ ```ruby
464
+ resource_source_string = project_resource.source('key', 'context')
465
+ ```
466
+
467
+ #### Fetch
468
+
469
+ You can fetch meta-data about the specified source string:
470
+
471
+ ```ruby
472
+ resource_source_string.fetch
473
+ ```
474
+
475
+ #### Update
476
+
477
+ You can update the meta-data of the specified source string
478
+
479
+ ```ruby
480
+ params = {:comment => "my comment", :character_limit => 140, :tags => ["tag1", "tag2"]}
481
+ resource_source_string.update(params)
482
+ ```
483
+
484
+ ### Resource Statistics
485
+
486
+ It allow you to retrieve some transifex stats about a resource.
487
+
488
+ #### Instantiation
489
+
490
+ ```ruby
491
+ resource_stats = project_resource.statistics
492
+ ```
493
+
494
+ #### Fetch
495
+
496
+ You can fetch the statistics:
497
+
498
+ Of all the the resource languages:
499
+
500
+ ```ruby
501
+ resource_stats.fetch
502
+ ```
503
+
504
+ Of a specified language:
505
+
506
+ ```ruby
507
+ resource_stats.fetch('en')
508
+ ```
509
+
510
+
511
+ ## Contributing
512
+
513
+ 1. Fork it
514
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
515
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
516
+ 4. Push to the branch (`git push origin my-new-feature`)
517
+ 5. Create new Pull Request