Skip to content

Commit

Permalink
feat(phone-number): add missing locales & validation script
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Jul 29, 2024
1 parent 0b32123 commit b79c6a1
Show file tree
Hide file tree
Showing 15 changed files with 1,620 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/ods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/vanillajs-datepicker": "1.3.5",
"autoprefixer": "10.4.17",
"concurrently": "8.2.2",
"glob": "11.0.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-puppeteer": "10.0.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/ods/src/components/phone-number/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"clean": "rimraf .stencil coverage dist docs-api www",
"doc": "typedoc --pretty --plugin ../../../scripts/typedoc-plugin-decorator.js && node ../../../scripts/generate-typedoc-md.js",
"lint:scss": "stylelint 'src/components/**/*.scss'",
"lint:ts": "eslint '{src,tests}/**/*.{js,ts,tsx}'",
"lint:ts": "npm run validate && eslint '{src,tests}/**/*.{js,ts,tsx}'",
"start": "stencil build --dev --watch --serve",
"test:e2e": "stencil test --e2e --config stencil.config.ts",
"test:e2e:ci": "tsc --noEmit && stencil test --e2e --ci --runInBand --config stencil.config.ts",
"test:spec": "stencil test --spec --config stencil.config.ts --coverage",
"test:spec:ci": "tsc --noEmit && stencil test --config stencil.config.ts --spec --ci --coverage"
"test:spec:ci": "tsc --noEmit && stencil test --config stencil.config.ts --spec --ci --coverage",
"validate": "node scripts/validate-i18n-keys.js 'src/i18n/*.json'"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#! /usr/bin/env node

const fs = require('fs');
const { glob } = require('glob');

const expectedIsoCodes = [
'ad','ae','af','ag','ai','al','am','ao','aq','ar','as','at','au','aw','ax',
'az','ba','bb','bd','be','bf','bg','bh','bi','bj','bl','bm','bn','bo','br',
'bs','bt','bw','by','bz','ca','cc','cd','cf','cg','ch','ci','ck','cl','cm',
'cn','co','cr','cu','cv','cw','cx','cy','cz','de','dj','dk','dm','do','dz',
'ec','ee','eg','eh','er','es','et','fi','fj','fk','fm','fo','fr','ga','gb',
'gd','ge','gg','gh','gi','gl','gm','gn','gq','gr','gs','gt','gu','gw','gy',
'hk','hn','hr','ht','hu','id','ie','il','im','in','iq','ir','is','it','je',
'jm','jo','jp','ke','kg','kh','ki','km','kn','kp','kr','kw','ky','kz','la',
'lb','lc','li','lk','lr','ls','lt','lu','lv','ly','ma','mc','md','me','mf',
'mg','mh','mk','ml','mm','mn','mo','mp','mq','mr','ms','mt','mu','mv','mw',
'mx','my','mz','na','nc','ne','nf','ng','ni','nl','no','np','nr','nu','nz',
'om','pa','pe','pf','pg','ph','pk','pl','pn','pr','ps','pt','pw','py','qa',
'ro','rs','ru','rw','sa','sb','sc','sd','se','sg','sh','si','sk','sl','sm',
'sn','so','sr','ss','st','sv','sy','sz','tc','td','tf','tg','th','tj','tk',
'tl','tm','tn','to','tr','tt','tv','tw','tz','ua','ug','us','uy','uz','va',
'vc','ve','vg','vi','vn','vu','wf','ws','ye','yt','za','zm','zw',
];

const dirPath = process.argv[2];

(async function main() {
const errors = [];

try {
const filePaths = await glob(dirPath);

for (const filePath of filePaths) {
const fileRows = JSON.parse(fs.readFileSync(filePath, 'utf8'))
const fileIsoCodes = fileRows.map((row) => row.isoCode);

const emptyValues = fileRows.filter((row) => {
return !row.name;
}).map((row) => row.isoCode);

const extraCodes = fileIsoCodes.filter((isoCode) => {
return expectedIsoCodes.indexOf(isoCode) < 0;
});

const missingCodes = expectedIsoCodes.filter((isoCode) => {
return fileIsoCodes.indexOf(isoCode) < 0;
});

if (emptyValues.length || extraCodes.length || missingCodes.length) {
errors.push({ emptyValues, extraCodes, filePath, missingCodes });
}
}
} catch (error) {
console.error('Something went wrong during the i18n keys validation', error);
}

if (errors.length) {
console.log('Following errors have been found during i18n keys validation:')

errors.forEach((error) => {
console.log(`--- File ${error.filePath} ---`);

(error.emptyValues || []).forEach((emptyValue) => {
console.log(`Empty isoCode value to fill: ${emptyValue}`);
});

(error.extraCodes || []).forEach((extraCode) => {
console.log(`Extra isoCode to remove: ${extraCode}`);
});

(error.missingCodes || []).forEach((missingCode) => {
console.log(`Missing isoCode to add: ${missingCode}`);
});
});

process.exitCode = 1;
}
})();
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
enum ODS_PHONE_NUMBER_LOCALE {
en = 'en',
fr = 'fr',
}
import { ODS_LOCALE, ODS_LOCALES, type OdsLocale } from '../../../../utils/locale';

type OdsPhoneNumberLocale = `${ODS_PHONE_NUMBER_LOCALE}`;

const ODS_PHONE_NUMBER_LOCALES = Object.freeze(Object.values(ODS_PHONE_NUMBER_LOCALE));

export {
ODS_PHONE_NUMBER_LOCALE,
ODS_PHONE_NUMBER_LOCALES,
type OdsPhoneNumberLocale,
};
export { ODS_LOCALE as ODS_PHONE_NUMBER_LOCALE, ODS_LOCALES as ODS_PHONE_NUMBER_LOCALES, type OdsLocale as OdsPhoneNumberLocale };
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { type PhoneNumber, PhoneNumberFormat, type PhoneNumberUtil } from 'googl
import { ODS_PHONE_NUMBER_COUNTRY_ISO_CODE, ODS_PHONE_NUMBER_COUNTRY_ISO_CODES, type OdsPhoneNumberCountryIsoCode } from '../constants/phone-number-country-iso-code';
import { ODS_PHONE_NUMBER_COUNTRY_PRESET, type OdsPhoneNumberCountryPreset } from '../constants/phone-number-country-preset';
import { ODS_PHONE_NUMBER_LOCALE, ODS_PHONE_NUMBER_LOCALES, type OdsPhoneNumberLocale } from '../constants/phone-number-locale';
import countriesTranslationDe from '../i18n/countries-de.json';
import countriesTranslationEn from '../i18n/countries-en.json';
import countriesTranslationEs from '../i18n/countries-es.json';
import countriesTranslationFr from '../i18n/countries-fr.json';
import countriesTranslationIt from '../i18n/countries-it.json';
import countriesTranslationNl from '../i18n/countries-nl.json';
import countriesTranslationPl from '../i18n/countries-pl.json';
import countriesTranslationPt from '../i18n/countries-pt.json';

type TranslatedCountryMap = Map<OdsPhoneNumberCountryIsoCode, { isoCode: OdsPhoneNumberCountryIsoCode , name: string, phoneCode?: number }>;

Expand Down Expand Up @@ -56,9 +62,22 @@ function getPhoneNumberExample(isoCode: OdsPhoneNumberCountryIsoCode | undefined

function getTranslatedCountries(locale: OdsPhoneNumberLocale): { isoCode: string, name: string }[] {
switch (locale) {
case ODS_PHONE_NUMBER_LOCALE.de:
return countriesTranslationDe;
case ODS_PHONE_NUMBER_LOCALE.en:
return countriesTranslationEn;
case ODS_PHONE_NUMBER_LOCALE.es:
return countriesTranslationEs;
case ODS_PHONE_NUMBER_LOCALE.fr:
return countriesTranslationFr;
case ODS_PHONE_NUMBER_LOCALE.it:
return countriesTranslationIt;
case ODS_PHONE_NUMBER_LOCALE.nl:
return countriesTranslationNl;
case ODS_PHONE_NUMBER_LOCALE.pl:
return countriesTranslationPl;
case ODS_PHONE_NUMBER_LOCALE.pt:
return countriesTranslationPt;
default:
return countriesTranslationFr;
}
Expand Down
240 changes: 240 additions & 0 deletions packages/ods/src/components/phone-number/src/i18n/countries-de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
[
{"isoCode": "ad", "name": "Andorra"},
{"isoCode": "ae", "name": "Vereinigte Arabische Emirate"},
{"isoCode": "af", "name": "Afghanistan"},
{"isoCode": "ag", "name": "Antigua und Barbuda"},
{"isoCode": "ai", "name": "Anguilla"},
{"isoCode": "al", "name": "Albanien"},
{"isoCode": "am", "name": "Armenien"},
{"isoCode": "ao", "name": "Angola"},
{"isoCode": "aq", "name": "Antarktis (Sonderstatus durch Antarktisvertrag)"},
{"isoCode": "ar", "name": "Argentinien"},
{"isoCode": "as", "name": "Amerikanisch-Samoa"},
{"isoCode": "at", "name": "Österreich"},
{"isoCode": "au", "name": "Australien"},
{"isoCode": "aw", "name": "Aruba"},
{"isoCode": "ax", "name": "Åland"},
{"isoCode": "az", "name": "Aserbaidschan"},
{"isoCode": "ba", "name": "Bosnien und Herzegowina"},
{"isoCode": "bb", "name": "Barbados"},
{"isoCode": "bd", "name": "Bangladesch"},
{"isoCode": "be", "name": "Belgien"},
{"isoCode": "bf", "name": "Burkina Faso"},
{"isoCode": "bg", "name": "Bulgarien"},
{"isoCode": "bh", "name": "Bahrain"},
{"isoCode": "bi", "name": "Burundi"},
{"isoCode": "bj", "name": "Benin"},
{"isoCode": "bl", "name": "Saint-Barthélemy"},
{"isoCode": "bm", "name": "Bermuda"},
{"isoCode": "bn", "name": "Brunei"},
{"isoCode": "bo", "name": "Bolivien"},
{"isoCode": "br", "name": "Brasilien"},
{"isoCode": "bs", "name": "Bahamas"},
{"isoCode": "bt", "name": "Bhutan"},
{"isoCode": "bw", "name": "Botswana"},
{"isoCode": "by", "name": "Belarus"},
{"isoCode": "bz", "name": "Belize"},
{"isoCode": "ca", "name": "Kanada"},
{"isoCode": "cc", "name": "Kokosinseln"},
{"isoCode": "cd", "name": "Kongo, Demokratische Republik"},
{"isoCode": "cf", "name": "Zentralafrikanische Republik"},
{"isoCode": "cg", "name": "Kongo, Republik"},
{"isoCode": "ch", "name": "Schweiz"},
{"isoCode": "ci", "name": "Elfenbeinküste"},
{"isoCode": "ck", "name": "Cookinseln"},
{"isoCode": "cl", "name": "Chile"},
{"isoCode": "cm", "name": "Kamerun"},
{"isoCode": "cn", "name": "China, Volksrepublik"},
{"isoCode": "co", "name": "Kolumbien"},
{"isoCode": "cr", "name": "Costa Rica"},
{"isoCode": "cu", "name": "Kuba"},
{"isoCode": "cv", "name": "Kap Verde"},
{"isoCode": "cw", "name": "Curaçao"},
{"isoCode": "cx", "name": "Weihnachtsinsel"},
{"isoCode": "cy", "name": "Zypern"},
{"isoCode": "cz", "name": "Tschechien"},
{"isoCode": "de", "name": "Deutschland"},
{"isoCode": "dj", "name": "Dschibuti"},
{"isoCode": "dk", "name": "Dänemark"},
{"isoCode": "dm", "name": "Dominica"},
{"isoCode": "do", "name": "Dominikanische Republik"},
{"isoCode": "dz", "name": "Algerien"},
{"isoCode": "ec", "name": "Ecuador"},
{"isoCode": "ee", "name": "Estland"},
{"isoCode": "eg", "name": "Ägypten"},
{"isoCode": "eh", "name": "Westsahara"},
{"isoCode": "er", "name": "Eritrea"},
{"isoCode": "es", "name": "Spanien"},
{"isoCode": "et", "name": "Äthiopien"},
{"isoCode": "fi", "name": "Finnland"},
{"isoCode": "fj", "name": "Fidschi"},
{"isoCode": "fk", "name": "Falklandinseln"},
{"isoCode": "fm", "name": "Mikronesien"},
{"isoCode": "fo", "name": "Färöer"},
{"isoCode": "fr", "name": "Frankreich"},
{"isoCode": "ga", "name": "Gabun"},
{"isoCode": "gb", "name": "Vereinigtes Königreich"},
{"isoCode": "gd", "name": "Grenada"},
{"isoCode": "ge", "name": "Georgien"},
{"isoCode": "gg", "name": "Guernsey (Kanalinsel)"},
{"isoCode": "gh", "name": "Ghana"},
{"isoCode": "gi", "name": "Gibraltar"},
{"isoCode": "gl", "name": "Grönland"},
{"isoCode": "gm", "name": "Gambia"},
{"isoCode": "gn", "name": "Guinea"},
{"isoCode": "gq", "name": "Äquatorialguinea"},
{"isoCode": "gr", "name": "Griechenland"},
{"isoCode": "gs", "name": "Südgeorgien und die Südlichen Sandwichinseln"},
{"isoCode": "gt", "name": "Guatemala"},
{"isoCode": "gu", "name": "Guam"},
{"isoCode": "gw", "name": "Guinea-Bissau"},
{"isoCode": "gy", "name": "Guyana"},
{"isoCode": "hk", "name": "Hongkong"},
{"isoCode": "hn", "name": "Honduras"},
{"isoCode": "hr", "name": "Kroatien"},
{"isoCode": "ht", "name": "Haiti"},
{"isoCode": "hu", "name": "Ungarn"},
{"isoCode": "id", "name": "Indonesien"},
{"isoCode": "ie", "name": "Irland"},
{"isoCode": "il", "name": "Israel"},
{"isoCode": "im", "name": "Insel Man"},
{"isoCode": "in", "name": "Indien"},
{"isoCode": "iq", "name": "Irak"},
{"isoCode": "ir", "name": "Iran"},
{"isoCode": "is", "name": "Island"},
{"isoCode": "it", "name": "Italien"},
{"isoCode": "je", "name": "Jersey (Kanalinsel)"},
{"isoCode": "jm", "name": "Jamaika"},
{"isoCode": "jo", "name": "Jordanien"},
{"isoCode": "jp", "name": "Japan"},
{"isoCode": "ke", "name": "Kenia"},
{"isoCode": "kg", "name": "Kirgisistan"},
{"isoCode": "kh", "name": "Kambodscha"},
{"isoCode": "ki", "name": "Kiribati"},
{"isoCode": "km", "name": "Komoren"},
{"isoCode": "kn", "name": "St. Kitts und Nevis"},
{"isoCode": "kp", "name": "Korea, Nord (Nordkorea)"},
{"isoCode": "kr", "name": "Korea, Süd (Südkorea)"},
{"isoCode": "kw", "name": "Kuwait"},
{"isoCode": "ky", "name": "Kaimaninseln"},
{"isoCode": "kz", "name": "Kasachstan"},
{"isoCode": "la", "name": "Laos"},
{"isoCode": "lb", "name": "Libanon"},
{"isoCode": "lc", "name": "St. Lucia"},
{"isoCode": "li", "name": "Liechtenstein"},
{"isoCode": "lk", "name": "Sri Lanka"},
{"isoCode": "lr", "name": "Liberia"},
{"isoCode": "ls", "name": "Lesotho"},
{"isoCode": "lt", "name": "Litauen"},
{"isoCode": "lu", "name": "Luxemburg"},
{"isoCode": "lv", "name": "Lettland"},
{"isoCode": "ly", "name": "Libyen"},
{"isoCode": "ma", "name": "Marokko"},
{"isoCode": "mc", "name": "Monaco"},
{"isoCode": "md", "name": "Moldau"},
{"isoCode": "me", "name": "Montenegro"},
{"isoCode": "mf", "name": "Saint-Martin (französischer Teil)"},
{"isoCode": "mg", "name": "Madagaskar"},
{"isoCode": "mh", "name": "Marshallinseln"},
{"isoCode": "mk", "name": "Nordmazedonien"},
{"isoCode": "ml", "name": "Mali"},
{"isoCode": "mm", "name": "Myanmar"},
{"isoCode": "mn", "name": "Mongolei"},
{"isoCode": "mo", "name": "Macau"},
{"isoCode": "mp", "name": "Nördliche Marianen"},
{"isoCode": "mq", "name": "Martinique"},
{"isoCode": "mr", "name": "Mauretanien"},
{"isoCode": "ms", "name": "Montserrat"},
{"isoCode": "mt", "name": "Malta"},
{"isoCode": "mu", "name": "Mauritius"},
{"isoCode": "mv", "name": "Malediven"},
{"isoCode": "mw", "name": "Malawi"},
{"isoCode": "mx", "name": "Mexiko"},
{"isoCode": "my", "name": "Malaysia"},
{"isoCode": "mz", "name": "Mosambik"},
{"isoCode": "na", "name": "Namibia"},
{"isoCode": "nc", "name": "Neukaledonien"},
{"isoCode": "ne", "name": "Niger"},
{"isoCode": "nf", "name": "Norfolkinsel"},
{"isoCode": "ng", "name": "Nigeria"},
{"isoCode": "ni", "name": "Nicaragua"},
{"isoCode": "nl", "name": "Niederlande"},
{"isoCode": "no", "name": "Norwegen"},
{"isoCode": "np", "name": "Nepal"},
{"isoCode": "nr", "name": "Nauru"},
{"isoCode": "nu", "name": "Niue"},
{"isoCode": "nz", "name": "Neuseeland"},
{"isoCode": "om", "name": "Oman"},
{"isoCode": "pa", "name": "Panama"},
{"isoCode": "pe", "name": "Peru"},
{"isoCode": "pf", "name": "Französisch-Polynesien"},
{"isoCode": "pg", "name": "Papua-Neuguinea"},
{"isoCode": "ph", "name": "Philippinen"},
{"isoCode": "pk", "name": "Pakistan"},
{"isoCode": "pl", "name": "Polen"},
{"isoCode": "pn", "name": "Pitcairninseln"},
{"isoCode": "pr", "name": "Puerto Rico"},
{"isoCode": "ps", "name": "Palästina"},
{"isoCode": "pt", "name": "Portugal"},
{"isoCode": "pw", "name": "Palau"},
{"isoCode": "py", "name": "Paraguay"},
{"isoCode": "qa", "name": "Katar"},
{"isoCode": "ro", "name": "Rumänien"},
{"isoCode": "rs", "name": "Serbien"},
{"isoCode": "ru", "name": "Russland"},
{"isoCode": "rw", "name": "Ruanda"},
{"isoCode": "sa", "name": "Saudi-Arabien"},
{"isoCode": "sb", "name": "Salomonen"},
{"isoCode": "sc", "name": "Seychellen"},
{"isoCode": "sd", "name": "Sudan"},
{"isoCode": "se", "name": "Schweden"},
{"isoCode": "sg", "name": "Singapur"},
{"isoCode": "sh", "name": "St. Helena, Ascension und Tristan da Cunha"},
{"isoCode": "si", "name": "Slowenien"},
{"isoCode": "sk", "name": "Slowakei"},
{"isoCode": "sl", "name": "Sierra Leone"},
{"isoCode": "sm", "name": "San Marino"},
{"isoCode": "sn", "name": "Senegal"},
{"isoCode": "so", "name": "Somalia"},
{"isoCode": "sr", "name": "Suriname"},
{"isoCode": "ss", "name": "Südsudan"},
{"isoCode": "st", "name": "São Tomé und Príncipe"},
{"isoCode": "sv", "name": "El Salvador"},
{"isoCode": "sy", "name": "Syrien"},
{"isoCode": "sz", "name": "Eswatini"},
{"isoCode": "tc", "name": "Turks- und Caicosinseln"},
{"isoCode": "td", "name": "Tschad"},
{"isoCode": "tf", "name": "Französische Süd- und Antarktisgebiete"},
{"isoCode": "tg", "name": "Togo"},
{"isoCode": "th", "name": "Thailand"},
{"isoCode": "tj", "name": "Tadschikistan"},
{"isoCode": "tk", "name": "Tokelau"},
{"isoCode": "tl", "name": "Osttimor"},
{"isoCode": "tm", "name": "Turkmenistan"},
{"isoCode": "tn", "name": "Tunesien"},
{"isoCode": "to", "name": "Tonga"},
{"isoCode": "tr", "name": "Türkei"},
{"isoCode": "tt", "name": "Trinidad und Tobago"},
{"isoCode": "tv", "name": "Tuvalu"},
{"isoCode": "tw", "name": "China, Republik"},
{"isoCode": "tz", "name": "Tansania"},
{"isoCode": "ua", "name": "Ukraine"},
{"isoCode": "ug", "name": "Uganda"},
{"isoCode": "us", "name": "Vereinigte Staaten"},
{"isoCode": "uy", "name": "Uruguay"},
{"isoCode": "uz", "name": "Usbekistan"},
{"isoCode": "va", "name": "Vatikanstadt"},
{"isoCode": "vc", "name": "St. Vincent und die Grenadinen"},
{"isoCode": "ve", "name": "Venezuela"},
{"isoCode": "vg", "name": "Britische Jungferninseln"},
{"isoCode": "vi", "name": "Amerikanische Jungferninseln"},
{"isoCode": "vn", "name": "Vietnam"},
{"isoCode": "vu", "name": "Vanuatu"},
{"isoCode": "wf", "name": "Wallis und Futuna"},
{"isoCode": "ws", "name": "Samoa"},
{"isoCode": "ye", "name": "Jemen"},
{"isoCode": "yt", "name": "Mayotte"},
{"isoCode": "za", "name": "Südafrika"},
{"isoCode": "zm", "name": "Sambia"},
{"isoCode": "zw", "name": "Simbabwe"}
]
Loading

0 comments on commit b79c6a1

Please sign in to comment.