diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65973688..ab6baaf8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ ### countries -| Field | Description | Required | Example | -| ----- | ------------------------------------------------------------------------------------------ | -------- | ------------ | -| name | Official name of the country | Required | `Martinique` | -| code | [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code of the country | Required | `MQ` | -| lang | Official language in the country | Required | `fra` | -| flag | Country flag emoji | Required | `🇲🇶` | +| Field | Description | Required | Example | +| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | --------- | +| name | Official name of the country | Required | `Canada` | +| code | [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code of the country | Required | `CA` | +| languages | List of official languages of the country separated by `;`. A list of all supported languages can be found in [data/languages.csv](data/languages.csv). | Required | `eng;fra` | +| flag | Country flag emoji | Required | `🇨🇦` | ### subdivisions diff --git a/data/countries.csv b/data/countries.csv index 9a5c8b0a..a430d847 100644 --- a/data/countries.csv +++ b/data/countries.csv @@ -1,4 +1,4 @@ -name,code,lang,flag +name,code,languages,flag Afghanistan,AF,pus,🇦🇫 Albania,AL,sqi,🇦🇱 Algeria,DZ,ara,🇩🇿 diff --git a/scripts/db/schemes/countries.js b/scripts/db/schemes/countries.js index eee92bdd..31e737ac 100644 --- a/scripts/db/schemes/countries.js +++ b/scripts/db/schemes/countries.js @@ -7,9 +7,11 @@ module.exports = { code: Joi.string() .regex(/^[A-Z]{2}$/) .required(), - lang: Joi.string() - .regex(/^[a-z]{3}$/) - .required(), + languages: Joi.array().items( + Joi.string() + .regex(/^[a-z]{3}$/) + .required() + ), flag: Joi.string() .regex(/^[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]$/) .required() diff --git a/scripts/db/validate.js b/scripts/db/validate.js index f6b0bf10..c1cd5cfc 100644 --- a/scripts/db/validate.js +++ b/scripts/db/validate.js @@ -91,7 +91,7 @@ async function main() { } } else if (filename === 'countries') { for (const [i, row] of rowsCopy.entries()) { - fileErrors = fileErrors.concat(validateCountryLanguage(row, i)) + fileErrors = fileErrors.concat(validateCountryLanguages(row, i)) } } else if (filename === 'subdivisions') { for (const [i, row] of rowsCopy.entries()) { @@ -295,13 +295,15 @@ function validateChannel(row, i) { return errors } -function validateCountryLanguage(row, i) { +function validateCountryLanguages(row, i) { const errors = [] - if (!db.languages[row.lang]) { - errors.push({ - line: i + 2, - message: `"${row.code}" has the wrong language "${row.lang}"` - }) + for (let lang of row.languages) { + if (!db.languages[lang]) { + errors.push({ + line: i + 2, + message: `"${row.code}" has the wrong language "${lang}"` + }) + } } return errors