-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allows translation of texts larger than 5K chars in getTranslat…
…ion and <Translate />
- Loading branch information
1 parent
af9549b
commit 726ea71
Showing
7 changed files
with
74 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const chunkRequest = async ( | ||
text: string | string[], | ||
translationReqFunc: (_chunk: string | string[]) => Promise<string | undefined>, | ||
chunkSize: number = 0, | ||
) => { | ||
const promises = []; | ||
|
||
for (let i = 0; i < text.length; i += chunkSize) { | ||
// issue: need better way to handle arrays with text items > 5000 chars | ||
// below just takes arrays with more than 5000 items and slices it. | ||
// nested approach required? | ||
const chunk = text.slice(i, i + chunkSize); | ||
promises.push(translationReqFunc(chunk)); | ||
} | ||
|
||
const translatedChunks = await Promise.all(promises); | ||
return translatedChunks.join(''); | ||
}; | ||
|
||
export default chunkRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters