Skip to content

Commit

Permalink
fix(translations): docs with only richText translations do not update (
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj authored Jul 2, 2023
1 parent a20abaa commit 94b489f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
39 changes: 38 additions & 1 deletion dev/src/tests/translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Translations', () => {
})

describe('fn: updateTranslation', () => {
it('updates a Payload article with a translation retrieved from CrowdIn', async () => {
it('updates a Payload article with a `text` field translation retrieved from CrowdIn', async () => {
const post = await payload.create({
collection: collections.localized,
data: { title: 'Test post' },
Expand Down Expand Up @@ -90,4 +90,41 @@ describe('Translations', () => {
expect(result.title).toEqual("Testbeitrag")
});
})

it('updates a Payload article with a `richText` field translation retrieved from CrowdIn', async () => {
const post = await payload.create({
collection: collections.localized,
data: {
content: {
children: [
{
text: "Test content"
}
]
}
},
});
const translationsApi = new payloadCrowdInSyncTranslationsApi(
pluginOptions,
payload,
)
const scope = nock('https://api.crowdin.com')
.persist()
.get('/api/v2/projects/1/translations/builds/1/download')
.reply(200,
"<p>Testbeitrag</p>"
)
const translation = await translationsApi.updateTranslation({
documentId: post.id,
collection: collections.localized,
dryRun: false,
})
// retrieve translated post from Payload
const result = await payload.findByID({
collection: collections.localized,
id: post.id,
locale: 'de_DE',
});
expect(result.content).toEqual([{"children": [{"text": "{\"title\":\"Testbeitrag\"}"}]}])
});
});
5 changes: 3 additions & 2 deletions src/api/payload-crowdin-sync/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,13 @@ export class payloadCrowdInSyncTranslationsApi {
localizedJsonFields.push('meta.description')
}

let docTranslations: { [key: string]: any } = {}
// add json fields
const docTranslations = await this.getTranslation({
docTranslations = await this.getTranslation({
documentId: global ? collectionConfig.slug : doc.id,
fieldName: 'fields',
locale: locale,
})
}) || {}
// add html fields
for (const field of localizedHtmlFields) {
docTranslations[field] = await this.getTranslation({
Expand Down

0 comments on commit 94b489f

Please sign in to comment.