From 63bc64995f165a152491a11ce82195ef5a2501ae Mon Sep 17 00:00:00 2001 From: Lorenzo Lewis Date: Fri, 18 Aug 2023 08:29:53 +0100 Subject: [PATCH] =?UTF-8?q?Enable=20Espa=C3=B1ol=20and=20=E4=B8=AD?= =?UTF-8?q?=E6=96=87=EF=BC=88=E4=B8=AD=E5=9B=BD=EF=BC=89locales=20(#1413)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add spanish and simplified chinese Signed-off-by: Lorenzo Lewis * fix locale build Signed-off-by: Lorenzo Lewis --------- Signed-off-by: Lorenzo Lewis --- .github/labeler.yml | 3 +++ locales.json | 8 ++++++++ packages/i18n-tracker/build.ts | 3 +-- packages/i18n-tracker/lib/translation-status/builder.ts | 8 +++++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index ec0ae1688..bc93396af 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,4 +1,7 @@ # See https://github.com/actions/labeler i18n: + - src/content/docs/es/**/* - src/content/docs/fr/**/* + - src/content/docs/zh-cn/**/* + diff --git a/locales.json b/locales.json index 414d7a583..30a9b2a86 100644 --- a/locales.json +++ b/locales.json @@ -6,5 +6,13 @@ "fr": { "label": "Français", "lang": "fr" + }, + "es": { + "label": "Español", + "lang": "es" + }, + "zh-cn": { + "label": "中文(中国)", + "lang": "zh-CN" } } diff --git a/packages/i18n-tracker/build.ts b/packages/i18n-tracker/build.ts index 10e49e7f0..9339e7845 100644 --- a/packages/i18n-tracker/build.ts +++ b/packages/i18n-tracker/build.ts @@ -6,8 +6,7 @@ const translationStatusBuilder = new TranslationStatusBuilder({ htmlOutputFilePath: '../../dist/contribute/translate-status.html', sourceLanguage: 'en', targetLanguages: Object.values(locales) - .map((el) => el.lang) - .filter((lang) => lang !== 'en') + .reduce((acc, { lang }) => (lang !== 'en' ? [lang, ...acc] : acc), []) .sort(), languageLabels: Object.values(locales) .filter((loc) => loc.lang !== 'en') diff --git a/packages/i18n-tracker/lib/translation-status/builder.ts b/packages/i18n-tracker/lib/translation-status/builder.ts index a63db5c91..ff7e88002 100644 --- a/packages/i18n-tracker/lib/translation-status/builder.ts +++ b/packages/i18n-tracker/lib/translation-status/builder.ts @@ -125,7 +125,7 @@ export class TranslationStatusBuilder { const pages: PageIndex = { [this.sourceLanguage]: {}, }; - this.targetLanguages.forEach((lang) => (pages[lang] = {})); + this.targetLanguages.forEach((lang) => (pages[lang.toLowerCase()] = {})); // Enumerate all markdown pages with supported languages in pageSourceDir, // retrieve their page data and update them @@ -135,7 +135,9 @@ export class TranslationStatusBuilder { const updatedPages = await Promise.all( pagePaths.sort().map(async (pagePath) => { const pathParts = pagePath.split('/'); - const isLanguageSubpathIncluded = this.targetLanguages.includes(pathParts[0]!); + const isLanguageSubpathIncluded = this.targetLanguages + .map((el) => el.toLowerCase()) + .includes(pathParts[0]!); // If the first path of a file does not belong to a language, it will be by default a page of the original language set. const lang = isLanguageSubpathIncluded ? pathParts[0] : this.sourceLanguage; @@ -232,7 +234,7 @@ export class TranslationStatusBuilder { }; this.targetLanguages.forEach((lang) => { - const i18nPage = pages[lang]![subpath]!; + const i18nPage = pages[lang.toLowerCase()]![subpath]!; content.translations[lang] = { page: i18nPage, isMissing: !i18nPage,