Skip to content

Commit 4d346d2

Browse files
authored
Add Translation resource (#495)
Following the API documentation (https://developer.zendesk.com/api-reference/help_center/help-center-api/translations), this will enable CRUD operations for Article / Section / Category translations. Notes: - Translation lookups use the `locale`, which needs to be passed in the `id` param to `#find` / `#find!` (ie. `article.translations.find(id: 'fr-FR')`) - The path for `#destroy` (https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#delete-translation) differs from the read paths for these objects. Curiously, the default `#destroy` seems to work on Article translations, but not for Section or Category translations. One workaround until this is resolved is to modify the path in a block ```ruby translation = client.categories.translations.find(id: 'fr-FR') translation.destroy do |req| req.path = "#{client.config.url}/help_center/translations/#{translation.id}" end ```
1 parent c7647bc commit 4d346d2

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

lib/zendesk_api/resources.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ def resource_path
191191

192192
class Section < Resource
193193
end
194+
class Translation < Resource; end
194195

195196
has_many Section
197+
has_many Translation
196198
end
197199

198200
class Section < ReadResource
@@ -205,10 +207,13 @@ def resource_path
205207
has Category
206208

207209
class Vote < Resource; end
210+
class Translation < Resource; end
208211
class Article < Resource
209212
has_many Vote
213+
has_many Translation
210214
end
211215

216+
has_many Translation
212217
has_many Article
213218
end
214219

@@ -221,6 +226,8 @@ def resource_path
221226

222227
class Vote < Resource; end
223228
has_many Vote
229+
class Translation < Resource; end
230+
has_many Translation
224231
end
225232

226233
class TopicSubscription < Resource

spec/live/article_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
expect(article).not_to be_nil
66
end
77

8+
it "can have translations", :vcr do
9+
article.translations.create(locale: "fr", title: "Traduction", body: "Bonjour")
10+
11+
expect(article.translations.map(&:locale)).to include("fr")
12+
end
13+
814
describe "creating articles within a section" do
915
def valid_attributes
1016
{ :name => "My Article", user_segment_id: nil, permission_group_id: 2801272, title: "My super article" }

spec/live/category_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ def valid_attributes
55
{ :name => "My Category" }
66
end
77

8+
it "can have translations", :vcr do
9+
category.translations.create(locale: "fr-ca", title: "Traduction", body: "Bon matin")
10+
11+
expect(category.translations.map(&:locale)).to include("fr-ca")
12+
end
13+
814
it_should_be_creatable
915
it_should_be_updatable :position, 2
1016
it_should_be_deletable

spec/live/section_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
expect(section).not_to be_nil
66
end
77

8+
it "can have translations", :vcr do
9+
section.translations.create(locale: "es", title: "Traducción", body: "Hola")
10+
11+
expect(section.translations.map(&:locale)).to include("es")
12+
end
13+
814
describe "creating sections withing categories" do
915
def valid_attributes
1016
{ :name => "My Section" }

0 commit comments

Comments
 (0)