Skip to content

Commit

Permalink
feat(*): support localization setting nested-field fields (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj authored Jun 1, 2023
1 parent c6ba74f commit 561e8e2
Show file tree
Hide file tree
Showing 6 changed files with 852 additions and 68 deletions.
5 changes: 4 additions & 1 deletion src/api/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ export async function getCurrentDocumentTranslation({
htmlFields[field.name] = document[field.name]
))
return {
...buildCrowdinJsonObject(document, localizedFields),
...buildCrowdinJsonObject({
doc: document,
fields: localizedFields
}),
...htmlFields
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/hooks/collections/afterChange.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CollectionAfterChangeHook, CollectionConfig, Field, GlobalConfig, GlobalAfterChangeHook, PayloadRequest } from 'payload/types';
import { CrowdinPluginRequest, FieldWithName } from '../../types'
import { findOrCreateArticleDirectory, payloadCreateCrowdInFile, payloadUpdateCrowdInFile, getCrowdinFile } from '../../api/payload'
import { buildCrowdinHtmlObject, buildCrowdinJsonObject, containsNestedFields, convertSlateToHtml, fieldChanged, getLocalizedFields } from '../../utilities'
import { buildCrowdinHtmlObject, buildCrowdinJsonObject, convertSlateToHtml, fieldChanged, getLocalizedFields } from '../../utilities'
import deepEqual from 'deep-equal'
import dot from "dot-object"

Expand Down Expand Up @@ -116,14 +116,16 @@ const performAfterChange = async ({
return doc
}

console.log(getLocalizedFields({ fields: localizedFields, type: 'html'}))

/**
* Prepare JSON objects
*
* `text` fields are compiled into a single JSON file
* on CrowdIn. Prepare previous and current objects.
*/
const currentCrowdinJsonData = buildCrowdinJsonObject(doc, localizedFields as FieldWithName[])
const prevCrowdinJsonData = buildCrowdinJsonObject(previousDoc, localizedFields as FieldWithName[])
const currentCrowdinJsonData = buildCrowdinJsonObject({doc, fields: localizedFields})
const prevCrowdinJsonData = buildCrowdinJsonObject({doc: previousDoc, fields: localizedFields})
/**
* Retrieve the CrowdIn Article Directory article
*
Expand Down Expand Up @@ -199,11 +201,13 @@ const performAfterChange = async ({
doc: previousDoc,
fields: localizedFields,
})
console.log(currentCrowdinHtmlData)
Object.keys(currentCrowdinHtmlData).forEach(async name => {
const crowdinFile = await getCrowdinFile(name, articleDirectory.id, req.payload)
const currentValue = currentCrowdinHtmlData[name]
const prevValue = prevCrowdinHtmlData[name]
if (!fieldChanged(prevValue, currentValue, 'richText')) {
console.log(`${name} not changed`)
return
}
if (typeof crowdinFile === 'undefined') {
Expand Down
Loading

0 comments on commit 561e8e2

Please sign in to comment.