50 lines
3.7 KiB
Plaintext
50 lines
3.7 KiB
Plaintext
const fs = require('node:fs');
|
|
const crypto = require('node:crypto');
|
|
const path = require('node:path');
|
|
const [catalogPath, outputPath] = process.argv.slice(2);
|
|
if (!catalogPath || !outputPath) throw new Error('Pass catalogue and output paths');
|
|
const raw = fs.readFileSync(catalogPath, 'utf8');
|
|
const catalog = JSON.parse(raw);
|
|
const euLanguages = ['bg','hr','cs','da','nl','en','et','fi','fr','de','el','hu','ga','it','lv','lt','mt','pl','pt','ro','sk','sl','es','sv'];
|
|
const samples = [0,1,2,3,4,5,6,10,11,12,20,21,100,101,1.5,1000000];
|
|
const results = catalog.locales.map(entry => {
|
|
const tag = entry.tag;
|
|
if (entry.status !== 'planned' || Object.values(entry.surfaces).some(status => status !== 'planned')) throw new Error('Probe must not advance locale status');
|
|
const canonical = Intl.getCanonicalLocales(tag)[0];
|
|
const supported = Object.fromEntries(['NumberFormat','DateTimeFormat','PluralRules','Collator','DisplayNames'].map(api => [api, Intl[api].supportedLocalesOf([tag], { localeMatcher: 'lookup' })]));
|
|
const numbers = new Intl.NumberFormat(tag, { style: 'currency', currency: 'EUR' });
|
|
const date = new Intl.DateTimeFormat(tag, { dateStyle: 'full', timeStyle: 'short', timeZone: 'Europe/Paris' });
|
|
const plural = new Intl.PluralRules(tag);
|
|
const inputLanguage = tag.split('-')[0];
|
|
return {
|
|
tag, inputLanguage, plannedStatus: entry.status, euOfficialLanguage: euLanguages.includes(inputLanguage),
|
|
canonical, canonicalChanged: canonical !== tag, maximized: new Intl.Locale(canonical).maximize().toString(), supported,
|
|
nativeName: new Intl.DisplayNames([canonical], { type: 'language' }).of(canonical),
|
|
englishName: new Intl.DisplayNames(['en'], { type: 'language' }).of(canonical),
|
|
resolved: { number: numbers.resolvedOptions().locale, date: date.resolvedOptions().locale, plural: plural.resolvedOptions().locale },
|
|
pluralCategories: plural.resolvedOptions().pluralCategories,
|
|
pluralSamples: samples.map(value => ({ value, category: plural.select(value) })),
|
|
fixedEurAmount: numbers.format(12345.67),
|
|
fixedUtcInstantInParis: date.format(new Date('2026-03-29T01:30:00Z')),
|
|
dottedIUppercase: 'i'.toLocaleUpperCase(canonical),
|
|
};
|
|
});
|
|
const euCoverage = euLanguages.map(language => ({ language, candidateTags: results.filter(x => x.inputLanguage === language).map(x => x.tag) }));
|
|
if (euCoverage.some(x => x.candidateTags.length === 0)) throw new Error('EU24 candidate missing');
|
|
if (new Set(results.map(x => x.tag)).size !== results.length) throw new Error('Duplicate input tag');
|
|
const evidence = {
|
|
scope: 'I18N-00 host Intl research only; no translations, product formatting engine, browser/.NET/PDF/native qualification or release',
|
|
runtime: { node: process.version, versions: process.versions, platform: process.platform, architecture: process.arch },
|
|
catalogSha256Lf: crypto.createHash('sha256').update(raw.replace(/\r\n/g, '\n')).digest('hex'),
|
|
candidates: results.length, euLanguages: euLanguages.length, euCoverage, results,
|
|
negativeControls: ['en_US','zz-ZZ'].map(tag => {
|
|
try { return { tag, canonical: Intl.getCanonicalLocales(tag)[0], dateSupported: Intl.DateTimeFormat.supportedLocalesOf([tag], { localeMatcher: 'lookup' }) }; }
|
|
catch (error) { return { tag, error: error.name }; }
|
|
}),
|
|
};
|
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
fs.writeFileSync(outputPath, JSON.stringify(evidence, null, 2) + '\n');
|
|
console.log('Candidate probes:', results.length, 'EU language candidates:', euCoverage.length);
|
|
console.log('Canonical changes:', results.filter(x => x.canonicalChanged).map(x => [x.tag, x.canonical]));
|
|
console.log('Missing API data:', results.filter(x => Object.values(x.supported).some(list => list.length === 0)).map(x => ({ tag: x.tag, supported: x.supported, resolved: x.resolved })));
|