Validate i18n file names with ISO-639x (#5505)

* validate i18n files

* add changeset

* lockfile

* test

* remove log

* Rename zh-tw.json to zh-TW.json

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Hannah 2023-09-12 17:39:15 +01:00 committed by GitHub
parent 9234167c85
commit 9ee20f499f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 5 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/app": minor
"gradio": minor
---
feat:Validate i18n file names with ISO-639x

View File

@ -1,5 +1,7 @@
import { describe, test, assert } from "vitest";
import { process_langs } from "./i18n";
import languagesByAnyCode from "wikidata-lang/indexes/by_any_code";
import BCP47 from "./lang/BCP47_codes";
describe("i18n", () => {
test("languages are loaded correctly", () => {
@ -12,10 +14,13 @@ describe("i18n", () => {
const langs = Object.entries(process_langs());
langs.forEach(([code, translation]) => {
// must be "xx" or "xx-xx" -- http://4umi.com/web/html/languagecodes.php
const RE = /^([a-z]{2}-[a-zA-Z]{2}|[a-z]{2})$/;
const BCP47_REGEX = /^.{2}-.{2}$/;
assert.ok(RE.test(code));
if (BCP47_REGEX.test(code)) {
assert.ok(BCP47.includes(code));
} else {
assert.exists(languagesByAnyCode[code]);
}
assert.ok(translation.common);
});
});

View File

@ -0,0 +1,58 @@
// BCP47 locales are used to identify language variants + are composed of a ISO 639x language code and a region code
const BCP47_codes = [
"ar-SA",
"bn-BD",
"bn-IN",
"cs-CZ",
"da-DK",
"de-AT",
"de-CH",
"de-DE",
"el-GR",
"en-AU",
"en-CA",
"en-GB",
"en-IE",
"en-IN",
"en-NZ",
"en-US",
"en-ZA",
"es-AR",
"es-CL",
"es-CO",
"es-ES",
"es-MX",
"es-US",
"fi-FI",
"fr-BE",
"fr-CA",
"fr-CH",
"fr-FR",
"he-IL",
"hi-IN",
"hu-HU",
"id-ID",
"it-CH",
"it-IT",
"ja-JP",
"ko-KR",
"nl-BE",
"nl-NL",
"no-NO",
"pl-PL",
"pt-BR",
"pt-PT",
"ro-RO",
"ru-RU",
"sk-SK",
"sv-SE",
"ta-IN",
"ta-LK",
"th-TH",
"tr-TR",
"zh-CN",
"zh-HK",
"zh-TW"
];
export default BCP47_codes;

View File

@ -102,6 +102,7 @@
"chromatic": "^7.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.23"
"storybook": "^7.0.23",
"wikidata-lang": "^4.1.2"
}
}

9
pnpm-lock.yaml generated
View File

@ -1,4 +1,4 @@
lockfileVersion: '6.0'
lockfileVersion: '6.1'
settings:
autoInstallPeers: true
@ -204,6 +204,9 @@ importers:
storybook:
specifier: ^7.0.23
version: 7.0.23
wikidata-lang:
specifier: ^4.1.2
version: 4.1.2
client/js:
dependencies:
@ -15457,6 +15460,10 @@ packages:
dependencies:
string-width: 4.2.3
/wikidata-lang@4.1.2:
resolution: {integrity: sha512-Nw+loOQQO02cVZQCAFCaE5IWdPakX9zXLr4Pjv0GA81OyI+TPWC6iLy/0cORL6YbYde19MbRVITIHiKRv1HmFA==}
dev: true
/word-wrap@1.2.3:
resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==}
engines: {node: '>=0.10.0'}