mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
Renaming invalid resource file and adding simple check in tests for the future. (#930)
This commit is contained in:
parent
5ae3c1819c
commit
6f4637a8f0
@ -8,6 +8,18 @@ import fs from "fs";
|
|||||||
import os from "os";
|
import os from "os";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
|
||||||
|
// We only support those formats for now:
|
||||||
|
// en.client.json
|
||||||
|
// en_US.client.json
|
||||||
|
// en_US.server.json
|
||||||
|
// zh_Hant.client.json
|
||||||
|
// {lang code (+ maybe with underscore and country code}.{namespace}.json
|
||||||
|
//
|
||||||
|
// Only this format was tested and is known to work.
|
||||||
|
|
||||||
|
const VALID_LOCALE_FORMAT = /^[a-z]{2,}(_\w+)?\.(\w+)\.json$/;
|
||||||
|
|
||||||
describe("Localization", function() {
|
describe("Localization", function() {
|
||||||
this.timeout(60000);
|
this.timeout(60000);
|
||||||
setupTestSuite();
|
setupTestSuite();
|
||||||
@ -40,20 +52,20 @@ describe("Localization", function() {
|
|||||||
const langs: Set<string> = new Set();
|
const langs: Set<string> = new Set();
|
||||||
const namespaces: Set<string> = new Set();
|
const namespaces: Set<string> = new Set();
|
||||||
for (const file of fs.readdirSync(localeDirectory)) {
|
for (const file of fs.readdirSync(localeDirectory)) {
|
||||||
if (file.endsWith(".json")) {
|
// Make sure we see only valid files.
|
||||||
const langRaw = file.split('.')[0];
|
assert.match(file, VALID_LOCALE_FORMAT);
|
||||||
const lang = langRaw?.replace(/_/g, '-');
|
const langRaw = file.split('.')[0];
|
||||||
const ns = file.split('.')[1];
|
const lang = langRaw?.replace(/_/g, '-');
|
||||||
const clientFile = path.join(localeDirectory,
|
const ns = file.split('.')[1];
|
||||||
`${langRaw}.client.json`);
|
const clientFile = path.join(localeDirectory,
|
||||||
const clientText = fs.readFileSync(clientFile, { encoding: 'utf8' });
|
`${langRaw}.client.json`);
|
||||||
if (!clientText.includes('Translators: please translate this only when')) {
|
const clientText = fs.readFileSync(clientFile, { encoding: 'utf8' });
|
||||||
// Translation not ready if this key is not present.
|
if (!clientText.includes('Translators: please translate this only when')) {
|
||||||
continue;
|
// Translation not ready if this key is not present.
|
||||||
}
|
continue;
|
||||||
langs.add(lang);
|
|
||||||
namespaces.add(ns);
|
|
||||||
}
|
}
|
||||||
|
langs.add(lang);
|
||||||
|
namespaces.add(ns);
|
||||||
}
|
}
|
||||||
assert.deepEqual(gristConfig.supportedLngs.sort(), [...langs].sort());
|
assert.deepEqual(gristConfig.supportedLngs.sort(), [...langs].sort());
|
||||||
assert.deepEqual(gristConfig.namespaces.sort(), [...namespaces].sort());
|
assert.deepEqual(gristConfig.namespaces.sort(), [...namespaces].sort());
|
||||||
@ -90,6 +102,8 @@ describe("Localization", function() {
|
|||||||
const enResponse = await (await fetch(homeUrl)).text();
|
const enResponse = await (await fetch(homeUrl)).text();
|
||||||
const uzResponse = await (await fetch(homeUrl, {headers: {"Accept-Language": "uz-UZ,uz;q=1"}})).text();
|
const uzResponse = await (await fetch(homeUrl, {headers: {"Accept-Language": "uz-UZ,uz;q=1"}})).text();
|
||||||
const ptResponse = await (await fetch(homeUrl, {headers: {"Accept-Language": "pt-PR,pt;q=1"}})).text();
|
const ptResponse = await (await fetch(homeUrl, {headers: {"Accept-Language": "pt-PR,pt;q=1"}})).text();
|
||||||
|
// We have file with nb_NO code, but still this should be preloaded.
|
||||||
|
const noResponse = await (await fetch(homeUrl, {headers: {"Accept-Language": "nb-NO,nb;q=1"}})).text();
|
||||||
|
|
||||||
function present(response: string, ...langs: string[]) {
|
function present(response: string, ...langs: string[]) {
|
||||||
for (const lang of langs) {
|
for (const lang of langs) {
|
||||||
@ -107,6 +121,7 @@ describe("Localization", function() {
|
|||||||
present(enResponse, "en");
|
present(enResponse, "en");
|
||||||
present(uzResponse, "en");
|
present(uzResponse, "en");
|
||||||
present(ptResponse, "en");
|
present(ptResponse, "en");
|
||||||
|
present(noResponse, "en");
|
||||||
|
|
||||||
// Other locales are not preloaded for English.
|
// Other locales are not preloaded for English.
|
||||||
notPresent(enResponse, "uz", "un-UZ", "en-US");
|
notPresent(enResponse, "uz", "un-UZ", "en-US");
|
||||||
@ -117,6 +132,9 @@ describe("Localization", function() {
|
|||||||
notPresent(uzResponse, "uz-UZ");
|
notPresent(uzResponse, "uz-UZ");
|
||||||
|
|
||||||
notPresent(ptResponse, "pt-PR", "uz", "en-US");
|
notPresent(ptResponse, "pt-PR", "uz", "en-US");
|
||||||
|
|
||||||
|
// For no-NO we have nb_NO file.
|
||||||
|
present(noResponse, "nb_NO");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("loads correct languages from file system", async function() {
|
it("loads correct languages from file system", async function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user