Skip to content

Commit

Permalink
Allow for empty input translations
Browse files Browse the repository at this point in the history
  • Loading branch information
cliftonc committed Dec 3, 2022
1 parent 4e99939 commit 4e6829b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let erroredRows = 0

const getText = (richText) => {
if (richText && richText.length > 0) {
return richText[0].plain_text
return richText[0].plain_text.trim()
} else {
return ''
}
Expand Down Expand Up @@ -45,9 +45,11 @@ const translate = async ({ notion, database, rows, fields }) => {
for (const input of fields.inputs) {
const inputText = getText(row.properties[input].rich_text)
try {
translations[input] = inputText ? await translator(inputText, { from: inputLanguage, to: defaultLanguageTo }) : ''
if (inputText) {
translations[input] = inputText ? await translator(inputText, { from: inputLanguage, to: defaultLanguageTo }) : ''
}
} catch (ex) {
core.error(`Error with translation: ${ex.message}`)
core.error(`Error with translation ${ex.message} [${inputText} from ${inputLanguage} to ${defaultLanguageTo}]`)
process.exit(1)
}
}
Expand Down

0 comments on commit 4e6829b

Please sign in to comment.