Skip to content

Commit

Permalink
fix: add missing translations (#4117)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski committed Jun 6, 2024
1 parent adab010 commit e7a5f54
Show file tree
Hide file tree
Showing 11 changed files with 1,173 additions and 516 deletions.
1 change: 1 addition & 0 deletions shared-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/react-text-mask": "^5.4.6",
"@types/react-transition-group": "^4.4.0",
"@types/tough-cookie": "^4.0.2",
"csv-parse": "^5.5.5",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.5.3",
"react": "18.2.0",
Expand Down
327 changes: 229 additions & 98 deletions shared-helpers/src/locales/es.json

Large diffs are not rendered by default.

227 changes: 59 additions & 168 deletions shared-helpers/src/locales/general.json

Large diffs are not rendered by default.

365 changes: 313 additions & 52 deletions shared-helpers/src/locales/tl.json

Large diffs are not rendered by default.

349 changes: 251 additions & 98 deletions shared-helpers/src/locales/vi.json

Large diffs are not rendered by default.

343 changes: 246 additions & 97 deletions shared-helpers/src/locales/zh.json

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions shared-helpers/src/scripts/get-machine-translations.ts
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 {}
5 changes: 4 additions & 1 deletion shared-helpers/src/scripts/missing-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ function main() {
return missingKeys
}

let missingTranslations = false
allTranslations.forEach((foreignKeys) => {
console.log("--------------------")
console.log(`Missing Public Site ${foreignKeys.language} Translations:`)
const missingPublicSiteTranslations = findMissingStrings(
englishTranslations,
foreignKeys.translationKeys
)
if (missingPublicSiteTranslations.length > 0) missingTranslations = true
missingPublicSiteTranslations.forEach((missingKey) =>
console.log(`${missingKey}, ${JSON.stringify(englishTranslations[missingKey])}`)
console.log(`${missingKey},${JSON.stringify(englishTranslations[missingKey])}`)
)
})
if (missingTranslations) throw Error
}

void main()
Expand Down
2 changes: 0 additions & 2 deletions shared-helpers/src/views/CustomIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const Application = (
fill="none"
role="img"
>
<title>{t("account.application.iconTitle")}</title>
<path d="M36.7665 11.439L25.3275 0H0V47.388H36.765V11.439H36.7665Z" fill="#EDEBDA" />
<path d="M25.3286 0V11.439H36.7676L25.3286 0Z" fill="#CEC9AE" />
<path
Expand Down Expand Up @@ -49,7 +48,6 @@ export const Profile = (
fill="none"
role="img"
>
<title>{t("account.settings.iconTitle")}</title>
<path
d="M16.8447 37.6683L9.68974 41.5631C9.23674 41.8346 8.87374 42.106 8.51074 42.379C12.6777 45.9108 18.1107 47.9939 23.9982 47.9939C29.8857 47.9939 35.2272 45.9108 39.3942 42.4704C39.0312 42.1075 38.5782 41.8376 38.1267 41.6546L30.4272 37.8513C29.4312 37.3984 28.7982 36.3111 28.7982 35.2268V32.2394C28.9782 31.9679 29.2512 31.6965 29.5227 31.335C30.6102 29.8863 31.3347 28.2561 31.8777 26.5359C32.8737 26.2645 33.5982 25.3572 33.5982 24.2729V21.1024C33.5982 20.3781 33.3267 19.7437 32.7822 19.2908V14.4917C32.7822 14.4917 33.7782 7.24805 23.9067 7.24805C14.0352 7.24805 15.0312 14.4917 15.0312 14.4917V19.1108C14.5782 19.5637 14.2152 20.1981 14.2152 20.9225V24.0929C14.2152 24.9087 14.6682 25.7216 15.3027 26.0845C16.1187 29.6164 18.2022 32.0624 18.2022 32.0624V34.9614C18.3822 36.1401 17.7492 37.1359 16.8432 37.6773L16.8447 37.6683Z"
fill="#E7ECED"
Expand Down
5 changes: 5 additions & 0 deletions shared-helpers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
"emitDecoratorMetadata": true,
"resolveJsonModule": true
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"include": ["src/**/*", "__tests__/**/*"]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8524,6 +8524,11 @@ csv-parse@^4.15.3:
resolved "https://registry.npmjs.org/csv-parse/-/csv-parse-4.16.3.tgz"
integrity sha512-cO1I/zmz4w2dcKHVvpCr7JVRu8/FymG5OEpmvsZYlccYolPBLoVGKUHgNoc4ZGkFeFlWGEDmMyBM+TTqRdW/wg==

csv-parse@^5.5.5:
version "5.5.6"
resolved "https://registry.yarnpkg.com/csv-parse/-/csv-parse-5.5.6.tgz#0d726d58a60416361358eec291a9f93abe0b6b1a"
integrity sha512-uNpm30m/AGSkLxxy7d9yRXpJQFrZzVWLFBkS+6ngPcZkw/5k3L/jjFuj7tVnEpRn+QgmiXr21nDlhCiUK4ij2A==

cypress-file-upload@^5.0.8:
version "5.0.8"
resolved "https://registry.npmjs.org/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz"
Expand Down

0 comments on commit e7a5f54

Please sign in to comment.