Update country display names

This commit is contained in:
Fedor Indutny 2024-02-14 18:08:21 -08:00 committed by GitHub
parent 9b98e20a8c
commit 46b620228e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 1163 additions and 1159 deletions

View file

@ -6,23 +6,6 @@ import fs from 'fs/promises';
import { z } from 'zod';
import { _getAvailableLocales } from '../../app/locale';
const availableLocales = _getAvailableLocales();
const LocaleString = z.string().refine(arg => {
try {
return new Intl.Locale(arg) && true;
} catch {
return false;
}
});
const LocaleDisplayNames = z
.tuple([z.tuple([z.literal('locale')]).rest(LocaleString)])
.rest(z.tuple([LocaleString]).rest(z.string()));
type Row = ReadonlyArray<string>;
type Records = ReadonlyArray<Row>;
const type = process.argv[2];
if (type !== 'countries' && type !== 'locales') {
throw new Error('Invalid first argument, expceted "countries" or "locales"');
@ -37,6 +20,27 @@ if (!localeDisplayNamesBuildPath) {
throw new Error('Missing third argument: output json file');
}
const availableLocales = _getAvailableLocales();
const LocaleString = z.string().refine(arg => {
try {
return new Intl.Locale(arg) && true;
} catch {
return false;
}
});
const LocaleDisplayNames = z
.tuple([
z
.tuple([z.literal(type === 'locales' ? 'locale' : 'Country Code')])
.rest(LocaleString),
])
.rest(z.tuple([LocaleString]).rest(z.string()));
type Row = ReadonlyArray<string>;
type Records = ReadonlyArray<Row>;
function parseCsv(input: string) {
return new Promise<Records>((resolve, reject) => {
parse(input, { trim: true }, (error, records: Records) => {