Skip to content

Commit a28c5f8

Browse files
committed
ran prettier
1 parent 429cff5 commit a28c5f8

File tree

5 files changed

+406
-402
lines changed

5 files changed

+406
-402
lines changed

i18n/controllers/gitComm.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,52 @@ import fs from "fs";
44
import path from "path";
55
dotenv.config();
66

7-
if (process.env.GITHUB_OWNER === undefined || process.env.GITHUB_REPO === undefined) {
8-
throw Error("Please specify GITHUB_OWNER, GITHUB_REPO to pull EN XML from!");
7+
if (
8+
process.env.GITHUB_OWNER === undefined ||
9+
process.env.GITHUB_REPO === undefined
10+
) {
11+
throw Error("Please specify GITHUB_OWNER, GITHUB_REPO to pull EN XML from!");
912
}
1013

1114
// initialize GitHub API
1215
const octokit = new Octokit();
1316

1417
async function getSource(filePath: string): Promise<string> {
15-
let toTranslate;
16-
17-
try {
18-
const result = await octokit.request(
19-
"GET /repos/{owner}/{repo}/contents/{path}",
20-
{
21-
owner: process.env.GITHUB_OWNER!,
22-
repo: process.env.GITHUB_REPO!,
23-
path: filePath,
24-
headers: {
25-
accept: "application/vnd.github.raw+json",
26-
},
27-
}
28-
);
29-
30-
toTranslate = result.data;
31-
const output_dir = path.join(import.meta.dirname, "../../ori");
32-
33-
// Ensure directory exists
34-
const dir = path.dirname(path.join(output_dir, filePath));
35-
fs.mkdirSync(dir, { recursive: true });
36-
37-
const fullPath = path.resolve(path.join(output_dir, filePath));
38-
fs.writeFileSync(fullPath, toTranslate);
39-
40-
console.log(
41-
`Successfully retrieved ${filePath} from GitHub, retrieval status: ${result.status}`
42-
);
43-
} catch (error) {
44-
console.log(
45-
`Error retrieving ${filePath} from GitHub.\n Status: ${error.status}.\n Rate limit remaining: ${error.response.headers["x-ratelimit-remaining"]}.\n Message: ${error.response.data.message}`
46-
);
47-
}
48-
49-
return toTranslate as string;
18+
let toTranslate;
19+
20+
try {
21+
const result = await octokit.request(
22+
"GET /repos/{owner}/{repo}/contents/{path}",
23+
{
24+
owner: process.env.GITHUB_OWNER!,
25+
repo: process.env.GITHUB_REPO!,
26+
path: filePath,
27+
headers: {
28+
accept: "application/vnd.github.raw+json"
29+
}
30+
}
31+
);
32+
33+
toTranslate = result.data;
34+
const output_dir = path.join(import.meta.dirname, "../../ori");
35+
36+
// Ensure directory exists
37+
const dir = path.dirname(path.join(output_dir, filePath));
38+
fs.mkdirSync(dir, { recursive: true });
39+
40+
const fullPath = path.resolve(path.join(output_dir, filePath));
41+
fs.writeFileSync(fullPath, toTranslate);
42+
43+
console.log(
44+
`Successfully retrieved ${filePath} from GitHub, retrieval status: ${result.status}`
45+
);
46+
} catch (error) {
47+
console.log(
48+
`Error retrieving ${filePath} from GitHub.\n Status: ${error.status}.\n Rate limit remaining: ${error.response.headers["x-ratelimit-remaining"]}.\n Message: ${error.response.data.message}`
49+
);
50+
}
51+
52+
return toTranslate as string;
5053
}
5154

5255
async function commitTranslated() {}

i18n/controllers/translate.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,22 @@ async function translate(language: string, filePath: string) {
166166
translated += `<!-- ${comment} -->`;
167167
});
168168

169-
clean.on("error", error => {
170-
console.log(
171-
"error encountered when validating XML: " +
172-
error +
173-
"\nvalidating section: " +
174-
chunk.substring(0, 100) + "..."
175-
);
176-
177-
// Attempt to recover using the internal parser
178-
try {
179-
clean._parser.resume();
180-
} catch (e) {
181-
console.log("Failed to resume parser:", e);
182-
}
183-
});
169+
clean.on("error", error => {
170+
console.log(
171+
"error encountered when validating XML: " +
172+
error +
173+
"\nvalidating section: " +
174+
chunk.substring(0, 100) +
175+
"..."
176+
);
177+
178+
// Attempt to recover using the internal parser
179+
try {
180+
clean._parser.resume();
181+
} catch (e) {
182+
console.log("Failed to resume parser:", e);
183+
}
184+
});
184185

185186
let translated = "";
186187

@@ -239,13 +240,11 @@ function escapeXML(str: string): string {
239240
return str.replace(/&(?!(?:amp;|lt;|gt;|apos;|quot;))/g, "&amp;");
240241
}
241242

242-
243-
244243
function strongEscapeXML(str: string): string {
245244
return str
246245
.replace(/&(?!(?:amp;|lt;|gt;|apos;|quot;))/g, "&amp;")
247246
.replace(/</g, "&lt;")
248247
.replace(/>/g, "&gt;")
249248
.replace(/"/g, "&quot;")
250249
.replace(/'/g, "&apos;");
251-
}
250+
}

0 commit comments

Comments
 (0)