Skip to content

Commit 462592c

Browse files
wackerowpettinarip
andcommitted
chore: apply suggestions from code review
Co-Authored-By: Pablo Pettinari <[email protected]>
1 parent 51267c8 commit 462592c

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/scripts/crowdin/import/utils.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync } from "fs"
22
import { join } from "path"
33

44
import i18Config from "../../../../i18n.config.json"
5+
import { INTL_JSON_DIR, TRANSLATIONS_DIR } from "../../../lib/constants"
56
import { DOT_CROWDIN } from "../translations/constants"
67

78
import { BucketsList, SelectionItem, SummaryItem, TrackerObject } from "./types"
@@ -18,26 +19,26 @@ export const getCrowdinCode = (code: string): string =>
1819
* to their corresponding destinations in the repo. Function is called
1920
* again recursively for subdirectories.
2021
*
21-
* @param _path An absolute path to the directory being scraped.
22+
* @param path An absolute path to the directory being scraped.
2223
* @param contentSubpath The subpath deep to the lang-code directory,
2324
* used to construct destination for markdown content files
2425
* @param repoLangCode Language code used within the repo
2526
* @returns void
2627
*/
2728
export const scrapeDirectory = (
28-
_path: string,
29+
path: string,
2930
contentSubpath: string,
3031
repoLangCode: string,
3132
trackers: TrackerObject
3233
): void => {
33-
if (!existsSync(_path)) return
34-
const ls: string[] = readdirSync(_path).filter(
34+
if (!existsSync(path)) return
35+
const ls: string[] = readdirSync(path).filter(
3536
(dir: string) => !dir.startsWith(".")
3637
)
3738
ls.forEach((item: string) => {
38-
const source: string = join(_path, item)
39+
const source: string = join(path, item)
3940
if (item.endsWith(".json")) {
40-
const jsonDestDirPath: string = join("src", "intl", repoLangCode)
41+
const jsonDestDirPath: string = join(INTL_JSON_DIR, repoLangCode)
4142
if (!existsSync(jsonDestDirPath))
4243
mkdirSync(jsonDestDirPath, { recursive: true })
4344
const jsonDestinationPath: string = join(jsonDestDirPath, item)
@@ -50,9 +51,7 @@ export const scrapeDirectory = (
5051
item.endsWith(".xlsx")
5152
) {
5253
const mdDestDirPath: string = join(
53-
"public",
54-
"content",
55-
"translations",
54+
TRANSLATIONS_DIR,
5655
repoLangCode,
5756
contentSubpath
5857
)
@@ -65,7 +64,7 @@ export const scrapeDirectory = (
6564
} else {
6665
// If another directory, recursively call `scrapeDirectory`
6766
scrapeDirectory(
68-
`${_path}/${item}`,
67+
`${path}/${item}`,
6968
`${contentSubpath}/${item}`,
7069
repoLangCode,
7170
trackers
@@ -126,14 +125,14 @@ export const processLanguage = (
126125
error: "",
127126
}
128127
// Initialize working directory and check for existence
129-
const _path: string = join(DOT_CROWDIN, crowdinLangCode)
130-
if (!existsSync(_path)) {
128+
const path: string = join(DOT_CROWDIN, crowdinLangCode)
129+
if (!existsSync(path)) {
131130
trackers.langs[
132131
repoLangCode
133132
].error = `Path doesn't exist for lang ${crowdinLangCode}`
134133
return
135134
}
136-
const langLs: string[] = readdirSync(_path)
135+
const langLs: string[] = readdirSync(path)
137136
// Iterate over each selected bucket, scraping contents with `scrapeDirectory`
138137
buckets.forEach((bucket) =>
139138
processBucket(bucket, crowdinLangCode, repoLangCode, langLs, trackers)

src/scripts/crowdin/translations/getApprovedBuckets.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ async function getApprovedBuckets(): Promise<BucketsList> {
4040
return bucketsList
4141
}
4242

43-
getApprovedBuckets()
44-
4543
export default getApprovedBuckets

src/scripts/crowdin/translations/postLangPRs.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import fs from "fs"
22

3-
import i18n from "../../../../i18n.config.json"
3+
import { LOCALES_CODES } from "../../../lib/constants"
44
import { BucketsList } from "../import/types"
55

66
import { BUCKETS_PATH } from "./constants"
7-
import { processLocale } from "./utils"
8-
9-
const locales = i18n.map((lang) => lang.code)
7+
import { createLocaleTranslationPR } from "./utils"
108

119
function postLangPRs() {
1210
const bucketsListRead = fs.readFileSync(BUCKETS_PATH, "utf-8")
1311
const bucketsList = JSON.parse(bucketsListRead) as BucketsList
1412

1513
if (!bucketsList) throw new Error("Failed to read buckets list.")
1614

17-
for (const locale of locales) {
15+
for (const locale of LOCALES_CODES) {
1816
if (!bucketsList[locale]) continue
19-
processLocale(locale, bucketsList[locale])
17+
createLocaleTranslationPR(locale, bucketsList[locale])
2018
}
2119
}
2220

src/scripts/crowdin/translations/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ ${qaResults}
5959
`
6060
}
6161

62-
export const processLocale = (locale: string, buckets: number[]) => {
62+
export const createLocaleTranslationPR = (
63+
locale: string,
64+
buckets: number[]
65+
) => {
6366
const gitStatus = execSync(`git status -s | grep -E "/${locale}/" | wc -l`, {
6467
encoding: "utf-8",
6568
}).trim()

0 commit comments

Comments
 (0)