fix(tools): validate and lint i18n schema (#40597)

* tools: Move schema validation to linter

Migrates the schema validation process for
translation files out of the `test` step and
in to a `lint` step.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix: typo

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* tools: Lint motivation object

Verifies that the motivation.json objects are
correct, and that the quote objects are all
structured properly.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* tools: add object value validation

Adds a function that validates each translation
object does not have any empty keys.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* tools: Log missing values with property chain

Modifies the value validation to log property names
as chains, for easier identification of misisng key
values.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix(tools): Correct typo

Corrects the typo in the motivation-schema.js comments

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Nicholas Carrigan (he/him)
2021-01-05 06:50:59 -08:00
committed by Mrugesh Mohapatra
parent 41c4b7f49a
commit 49b1c29f6b
7 changed files with 887 additions and 560 deletions

View File

@@ -1,31 +1,25 @@
/* global expect */
import { translationsSchema } from './translations-schema';
import { motivationSchema } from './motivation-schema';
import {
availableLangs,
i18nextCodes,
langDisplayNames,
langCodes
} from './allLangs';
import { trendingSchema } from './trending-schema';
const fs = require('fs');
const { expectToMatchSchema, setup } = require('jest-json-schema-extended');
const { setup } = require('jest-json-schema-extended');
setup();
const filesThatShouldExist = [
{
name: 'translations.json',
schema: translationsSchema
name: 'translations.json'
},
{
name: 'motivation.json',
schema: motivationSchema
name: 'motivation.json'
},
{
name: 'trending.json',
schema: trendingSchema
name: 'trending.json'
}
];
@@ -40,13 +34,6 @@ describe('Locale tests:', () => {
const exists = fs.existsSync(`${path}/${lang}/${file.name}`);
expect(exists).toBeTruthy();
});
// check that each of the json files match the schema
test(`${file.name} has correct schema`, async () => {
const jsonFile = fs.readFileSync(`${path}/${lang}/${file.name}`);
let json = await JSON.parse(jsonFile);
expectToMatchSchema(json, file.schema);
});
});
test(`has a two character entry in the i18nextCodes variable`, () => {