Skip to content

Commit 831a976

Browse files
authored
Merge pull request Expensify#64389 from Expensify/Rory-DecodeUnicode
[No QA] Decode unicode
2 parents 6986581 + 6bda7bf commit 831a976

19 files changed

Lines changed: 32326 additions & 38726 deletions

File tree

.github/actions/javascript/proposalPoliceComment/index.js

Lines changed: 9073 additions & 13922 deletions
Large diffs are not rendered by default.

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@
450450
"positionMillis",
451451
"Postharvest",
452452
"Postproduction",
453+
"Précédent",
453454
"precheck",
454455
"Precheck",
455456
"prescribers",

package-lock.json

Lines changed: 16 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
"memfs": "^4.6.0",
330330
"nitro-codegen": "0.25.2",
331331
"onchange": "^7.1.0",
332-
"openai": "^4.47.2",
332+
"openai": "5.5.1",
333333
"patch-package": "^8.1.0-canary.1",
334334
"peggy": "^4.0.3",
335335
"portfinder": "^1.0.28",

scripts/generateTranslations.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import fs from 'fs';
88
import path from 'path';
99
import type {TemplateExpression} from 'typescript';
1010
import ts from 'typescript';
11+
import decodeUnicode from '@libs/StringUtils/decodeUnicode';
1112
import dedent from '@libs/StringUtils/dedent';
1213
import hashStr from '@libs/StringUtils/hash';
13-
import {isTranslationTargetLocale, TRANSLATION_TARGET_LOCALES} from '@src/CONST/LOCALES';
14+
import {isTranslationTargetLocale, LOCALES, TRANSLATION_TARGET_LOCALES} from '@src/CONST/LOCALES';
1415
import type {TranslationTargetLocale} from '@src/CONST/LOCALES';
1516
import CLI from './utils/CLI';
1617
import Prettier from './utils/Prettier';
@@ -112,7 +113,7 @@ class TranslationGenerator {
112113

113114
// Generate translated TypeScript code
114115
const printer = ts.createPrinter();
115-
const translatedCode = printer.printFile(transformedSourceFile);
116+
const translatedCode = decodeUnicode(printer.printFile(transformedSourceFile));
116117

117118
// Write to file
118119
const outputPath = path.join(this.languagesDir, `${targetLanguage}.ts`);
@@ -182,9 +183,15 @@ class TranslationGenerator {
182183
return false;
183184
}
184185

185-
// Only translate string literals if they contain alphabet characters
186+
// Don't translate object keys
187+
if (ts.isComputedPropertyName(node.parent)) {
188+
return false;
189+
}
190+
191+
// Only translate string literals if they contain at least one real letter
186192
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
187-
return /[a-zA-Z]/.test(node.text);
193+
// \p{L} matches a-z, à-ö, Α-Ω, Ж, 文, … – but NOT digits, emoji, punctuation, etc.
194+
return /\p{L}/u.test(node.text);
188195
}
189196

190197
// Only translate a template expression if it contains alphabet characters outside the spans
@@ -441,7 +448,7 @@ async function main(): Promise<void> {
441448
// By default, generate translations for all supported languages. Can be overridden with the --locales flag
442449
locales: {
443450
description: 'Locales to generate translations for.',
444-
default: TRANSLATION_TARGET_LOCALES,
451+
default: Object.values(TRANSLATION_TARGET_LOCALES).filter((locale) => locale !== LOCALES.ES),
445452
parse: (val: string): TranslationTargetLocale[] => {
446453
const rawLocales = val.split(',');
447454
const validatedLocales: TranslationTargetLocale[] = [];

scripts/utils/OpenAIUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class OpenAIUtils {
7676
let count = 0;
7777
while (!response && count < OpenAIUtils.MAX_POLL_COUNT) {
7878
// await thread run completion
79-
threadRun = await this.client.beta.threads.runs.retrieve(threadRun.thread_id, threadRun.id);
79+
threadRun = await this.client.beta.threads.runs.retrieve(threadRun.thread_id, {thread_id: threadRun.id});
8080
if (threadRun.status !== 'completed') {
8181
count++;
8282
await new Promise((resolve) => {
@@ -110,7 +110,7 @@ class OpenAIUtils {
110110
// Handle known/predictable API errors
111111
if (error instanceof OpenAI.APIError) {
112112
// Only retry 429 (rate limit) or 5xx errors
113-
const status = error.status;
113+
const status = error.status as number;
114114
return !!status && (status === 429 || status >= 500);
115115
}
116116

scripts/utils/Translator/ChatGPTTranslator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ChatGPTTranslator extends Translator {
99
/**
1010
* The maximum number of times we'll retry a successful translation request in the event of hallucinations.
1111
*/
12-
private static readonly MAX_RETRIES: number = 2;
12+
private static readonly MAX_RETRIES: number = 4;
1313

1414
/**
1515
* OpenAI API client to perform translations.
@@ -36,6 +36,9 @@ class ChatGPTTranslator extends Translator {
3636
});
3737

3838
if (this.validateTemplatePlaceholders(text, result)) {
39+
if (attempt > 0) {
40+
console.log(`🙃 Translation succeeded after ${attempt + 1} attempts`);
41+
}
3942
console.log(`🧠 Translated "${text}" to ${targetLang}: "${result}"`);
4043
return result;
4144
}

0 commit comments

Comments
 (0)