Skip to content

Commit

Permalink
adding translations to excel extractor and extractor plugin (#738)
Browse files Browse the repository at this point in the history
* adding translations to excel extractor and extractor plugin

* updated paths to point to plugins

* chore: update package.lock

* Create tricky-plants-kiss.md

* moved additional variables to plugins

* moved extractionfailed message

---------

Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
  • Loading branch information
elisadinsmore and carlbrugger authored Jan 30, 2025
1 parent 4b8f123 commit 40717d0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/tricky-plants-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@flatfile/plugin-xlsx-extractor': minor
'@flatfile/util-extractor': minor
---

This release adds job message translations
2 changes: 2 additions & 0 deletions flatfilers/sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import type { FlatfileListener } from '@flatfile/listener'
import { exportDelimitedZip } from '@flatfile/plugin-export-delimited-zip'
import { JSONExtractor } from '@flatfile/plugin-json-extractor'
import { configureSpace } from '@flatfile/plugin-space-configure'
import { ExcelExtractor } from '@flatfile/plugin-xlsx-extractor'

export default async function (listener: FlatfileListener) {
listener.use(ExcelExtractor())
listener.use(JSONExtractor())
listener.use(
exportDelimitedZip({
Expand Down
6 changes: 2 additions & 4 deletions plugins/xlsx-extractor/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export async function parseBuffer(
'File is too large to parse. Try converting this file to CSV.'
)
}
throw new Error(
'File is too large to parse. Try converting this file to CSV.'
)
throw new Error('plugins.extraction.fileTooLarge')
}

// Try reading the file again without the 'WTF' option.
Expand Down Expand Up @@ -83,7 +81,7 @@ export async function parseBuffer(
return Object.fromEntries(processedSheets)
} catch (e) {
console.error(e)
throw new Error('Failed to parse workbook')
throw new Error('plugins.extraction.failedToParseWorkbook')
}
}

Expand Down
18 changes: 9 additions & 9 deletions utils/extractor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const Extractor = (
}

try {
await tick(1, 'Retrieving file')
await tick(1, 'plugins.extraction.retrieveFile')
const { data: file } = await api.files.get(fileId)
const buffer = await getFileBuffer(event)

Expand All @@ -75,15 +75,15 @@ export const Extractor = (
(e) => e.key === 'sourceEditor'
)

await tick(3, 'Parsing Sheets')
await tick(3, 'plugins.extraction.parseSheets')
const capture = await parseBuffer(buffer, {
...options,
fileId,
fileExt: file.ext,
headerSelectionEnabled,
})

await tick(5, 'Creating workbook')
await tick(5, 'plugins.extraction.createWorkbook')
const workbook = await createWorkbook(
event.context.environmentId,
file,
Expand All @@ -98,10 +98,10 @@ export const Extractor = (
})

if (!workbook.sheets || workbook.sheets.length === 0) {
throw new Error('No Sheets found')
throw new Error('plugins.extraction.noSheets')
}

await tick(10, 'Adding records to Sheets')
await tick(10, 'plugins.extraction.addingRecords')

let processedRecords = 0
const totalLength = Object.values(capture).reduce(
Expand All @@ -123,7 +123,7 @@ export const Extractor = (
async (_progress, part, totalParts) => {
await tick(
Math.min(99, Math.round(10 + 90 * (part / totalParts))),
'Adding records to Sheets'
'plugins.extraction.addingRecords'
)
}
)
Expand All @@ -138,9 +138,9 @@ export const Extractor = (
status: 'complete',
})
await api.jobs.complete(jobId, {
info: 'Extraction complete',
info: 'files.uploadFile.popovers.extractionCompleted',
outcome: {
message: 'Extracted file',
message: 'plugins.extraction.extractedFile',
},
})
} catch (e) {
Expand All @@ -151,7 +151,7 @@ export const Extractor = (
status: 'failed',
})
await api.jobs.fail(jobId, {
info: 'Extraction failed',
info: 'plugins.extraction.extractionFailed',
outcome: {
message: e.message,
},
Expand Down

0 comments on commit 40717d0

Please sign in to comment.