forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f7bdc1
commit 5b29cdd
Showing
7 changed files
with
653 additions
and
125 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,60 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires, import/no-unresolved */ | ||
|
||
// Takes in a CSV file with two columns (t_key,t_value) with the key being the translation file key and the value being the associated English string, and prints out in the JSON translation file format the "key": "translated string" | ||
// Temporarily update the shared-helpers tsconfig to include `"module": "commonjs"` | ||
// example from within this directory, first argument is one of LanguagesEnum and second argument is the formatted CSV filename with keys and english strings, piped to a new file: `ts-node get-machine-translations es english-keys.csv > any-filename-here.json` | ||
import fs from "node:fs" | ||
import { parse } from "csv-parse/sync" | ||
|
||
import { Translate } from "@google-cloud/translate/build/src/v2" | ||
|
||
async function main(argv: string[]) { | ||
enum LanguagesEnum { | ||
"en" = "en", | ||
"es" = "es", | ||
"vi" = "vi", | ||
"zh" = "zh", | ||
"tl" = "tl", | ||
} | ||
|
||
const GOOGLE_API_EMAIL = "SECRET_VALUE" | ||
const GOOGLE_API_ID = "SECRET_VALUE" | ||
const GOOGLE_API_KEY = "SECRET_VALUE" | ||
|
||
const makeTranslateService = () => { | ||
return new Translate({ | ||
credentials: { | ||
private_key: GOOGLE_API_KEY.replace(/\\n/gm, "\n"), | ||
client_email: GOOGLE_API_EMAIL, | ||
}, | ||
projectId: GOOGLE_API_ID, | ||
}) | ||
} | ||
|
||
const fetch = async (values: string[], language: LanguagesEnum) => { | ||
return await makeTranslateService().translate(values, { | ||
from: LanguagesEnum.en, | ||
to: language, | ||
}) | ||
} | ||
|
||
const [language, englishStringsCsv] = argv.slice(2) | ||
|
||
const csvFile = fs.readFileSync(englishStringsCsv) | ||
|
||
const csvData = parse(csvFile, { | ||
columns: true, | ||
skip_empty_lines: true, | ||
}) | ||
|
||
for (const row of csvData) { | ||
const tKey = row["t_key"].trim() | ||
const tValue = row["t_value"].trim() | ||
const translatedValue = await fetch([tValue], language as LanguagesEnum) | ||
console.log(`"${tKey}": "${translatedValue[0][0]}",`) | ||
} | ||
} | ||
|
||
void main(process.argv) | ||
|
||
export {} |
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