Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active February 22, 2021 17:41
Show Gist options
  • Save gregtatum/775379b393da798c7be172f31f954f3d to your computer and use it in GitHub Desktop.
Save gregtatum/775379b393da798c7be172f31f954f3d to your computer and use it in GitHub Desktop.
Unique pattern variants in CLDR skeleton data
{
variants: [
{
locale: 'en-CA',
bareSkeleton: 'Md',
skeleton: 'Md',
pattern: 'MM-dd',
variant: ''
},
{
locale: 'en-CA',
bareSkeleton: 'Md',
skeleton: 'Md-alt-variant',
pattern: 'd/M',
variant: 'alt-variant'
}
],
uniquePatterns: Set(2) { 'MM-dd', 'd/M' }
}
{
variants: [
{
locale: 'en-CA',
bareSkeleton: 'MEd',
skeleton: 'MEd',
pattern: 'E, MM-dd',
variant: ''
},
{
locale: 'en-CA',
bareSkeleton: 'MEd',
skeleton: 'MEd-alt-variant',
pattern: 'E, d/M',
variant: 'alt-variant'
}
],
uniquePatterns: Set(2) { 'E, MM-dd', 'E, d/M' }
}
{
variants: [
{
locale: 'en-CA',
bareSkeleton: 'MMdd',
skeleton: 'MMdd',
pattern: 'MM-dd',
variant: ''
},
{
locale: 'en-CA',
bareSkeleton: 'MMdd',
skeleton: 'MMdd-alt-variant',
pattern: 'dd/MM',
variant: 'alt-variant'
}
],
uniquePatterns: Set(2) { 'MM-dd', 'dd/MM' }
}
{
variants: [
{
locale: 'en-CA',
bareSkeleton: 'yM',
skeleton: 'yM',
pattern: 'y-MM',
variant: ''
},
{
locale: 'en-CA',
bareSkeleton: 'yM',
skeleton: 'yM-alt-variant',
pattern: 'M/y',
variant: 'alt-variant'
}
],
uniquePatterns: Set(2) { 'y-MM', 'M/y' }
}
{
variants: [
{
locale: 'en-CA',
bareSkeleton: 'yMd',
skeleton: 'yMd',
pattern: 'y-MM-dd',
variant: ''
},
{
locale: 'en-CA',
bareSkeleton: 'yMd',
skeleton: 'yMd-alt-variant',
pattern: 'd/M/y',
variant: 'alt-variant'
}
],
uniquePatterns: Set(2) { 'y-MM-dd', 'd/M/y' }
}
{
variants: [
{
locale: 'en-CA',
bareSkeleton: 'yMEd',
skeleton: 'yMEd',
pattern: 'E, y-MM-dd',
variant: ''
},
{
locale: 'en-CA',
bareSkeleton: 'yMEd',
skeleton: 'yMEd-alt-variant',
pattern: 'E, d/M/y',
variant: 'alt-variant'
}
],
uniquePatterns: Set(2) { 'E, y-MM-dd', 'E, d/M/y' }
}
{
variants: [
{
locale: 'fil',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-one',
pattern: "'ika'-W 'linggo' 'ng' MMMM",
variant: 'count-one'
},
{
locale: 'fil',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-other',
pattern: "'linggo' W 'ng' MMMM",
variant: 'count-other'
}
],
uniquePatterns: Set(2) { "'ika'-W 'linggo' 'ng' MMMM", "'linggo' W 'ng' MMMM" }
}
{
variants: [
{
locale: 'fil',
bareSkeleton: 'yw',
skeleton: 'yw-count-one',
pattern: "'ika'-w 'linggo' 'ng' Y",
variant: 'count-one'
},
{
locale: 'fil',
bareSkeleton: 'yw',
skeleton: 'yw-count-other',
pattern: "'linggo' w 'ng' Y",
variant: 'count-other'
}
],
uniquePatterns: Set(2) { "'ika'-w 'linggo' 'ng' Y", "'linggo' w 'ng' Y" }
}
{
variants: [
{
locale: 'hy',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-one',
pattern: 'MMMM W-ին շաբաթ',
variant: 'count-one'
},
{
locale: 'hy',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-other',
pattern: 'MMMM W-րդ շաբաթ',
variant: 'count-other'
}
],
uniquePatterns: Set(2) { 'MMMM W-ին շաբաթ', 'MMMM W-րդ շաբաթ' }
}
{
variants: [
{
locale: 'hy',
bareSkeleton: 'yw',
skeleton: 'yw-count-one',
pattern: 'Y թ․ w-ին շաբաթ',
variant: 'count-one'
},
{
locale: 'hy',
bareSkeleton: 'yw',
skeleton: 'yw-count-other',
pattern: 'Y թ․ w-րդ շաբաթ',
variant: 'count-other'
}
],
uniquePatterns: Set(2) { 'Y թ․ w-ին շաբաթ', 'Y թ․ w-րդ շաբաթ' }
}
{
variants: [
{
locale: 'pcm',
bareSkeleton: 'yw',
skeleton: 'yw-count-one',
pattern: "'Wik' w 'fọ' Y",
variant: 'count-one'
},
{
locale: 'pcm',
bareSkeleton: 'yw',
skeleton: 'yw-count-other',
pattern: "'Wiik' w 'fọ' Y",
variant: 'count-other'
}
],
uniquePatterns: Set(2) { "'Wik' w 'fọ' Y", "'Wiik' w 'fọ' Y" }
}
{
variants: [
{
locale: 'ps',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-one',
pattern: 'اونۍ‘ W د MMMM‘',
variant: 'count-one'
},
{
locale: 'ps',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-other',
pattern: 'اونۍ W د MMMM',
variant: 'count-other'
}
],
uniquePatterns: Set(2) { 'اونۍ‘ W د MMMM‘', 'اونۍ W د MMMM' }
}
{
variants: [
{
locale: 'ps-PK',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-one',
pattern: 'اونۍ‘ W د MMMM‘',
variant: 'count-one'
},
{
locale: 'ps-PK',
bareSkeleton: 'MMMMW',
skeleton: 'MMMMW-count-other',
pattern: 'اونۍ W د MMMM',
variant: 'count-other'
}
],
uniquePatterns: Set(2) { 'اونۍ‘ W د MMMM‘', 'اونۍ W د MMMM' }
}
const fs = require('fs');
const path = require('path');
const localesPath = "./cldr-json/cldr-dates-full/main";
const skeletonVariants = new Map();
for (const locale of fs.readdirSync(localesPath)) {
const calendarPath = path.join(localesPath, locale, "ca-gregorian.json");
const calendar = JSON.parse(fs.readFileSync(calendarPath, 'utf8'));
const { availableFormats } = calendar.main[locale].dates.calendars.gregorian.dateTimeFormats
for (const [skeleton, pattern] of Object.entries(availableFormats)) {
const parts = skeleton.split('-');
const bareSkeleton = parts[0]
const variant = parts.slice(1).join('-')
// Do an analysis of how many unique variants there are.
const tag = locale + ', ' + bareSkeleton;
let variants = skeletonVariants.get(tag);
if (!variants) {
variants = {
variants: [],
uniquePatterns: new Set(),
}
skeletonVariants.set(tag, variants);
}
variants.uniquePatterns.add(pattern);
variants.variants.push({
locale, bareSkeleton, skeleton, pattern, variant
})
}
}
// Output the analysis of the skeleton variants.
for (const variant of skeletonVariants.values()) {
// console.log(variant);
if (variant.uniquePatterns.size !== 1) {
console.log(variant);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment