Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: locale aware sorting #2906

Closed
16 changes: 13 additions & 3 deletions scripts/generate-locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async function updateLocaleFileHook(
console.log(`${filePath} <-> ${locale} @ ${definitionKey} -> ${entryName}`);
}

return normalizeLocaleFile(filePath, definitionKey);
return normalizeLocaleFile(filePath, locale, definitionKey);
}

/**
Expand All @@ -283,22 +283,32 @@ async function updateLocaleFileHook(
* This function mutates the file by reading and writing to it!
*
* @param filePath The full file path to the file.
* @param locale The locale for that file.
* @param definitionKey The definition key of the current file (ex. 'location').
*/
async function normalizeLocaleFile(filePath: string, definitionKey: string) {
async function normalizeLocaleFile(
filePath: string,
locale: string,
definitionKey: string
) {
function normalizeDataRecursive<T>(localeData: T): T {
if (typeof localeData !== 'object' || localeData === null) {
// we can only traverse object-like structs
return localeData;
}

// eslint-disable-next-line no-restricted-globals
const collator = new Intl.Collator(
locale === 'base' ? 'en' : locale.replaceAll('_', '-')
);

if (Array.isArray(localeData)) {
return (
[...new Set(localeData)]
// limit entries to 1k
.slice(0, 1000)
// sort entries alphabetically
.sort() as T
.sort(collator.compare) as T
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/locales/ar/commerce/department.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export default [
'أدوات',
'أطفال',
'أغراض رياضية',
'السيارات',
'ألعاب',
'إلكترونيات',
'السيارات',
'بقالة',
'بيت',
'جمال',
Expand Down
8 changes: 4 additions & 4 deletions src/locales/ar/date/month.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ export default {
'آذَار',
'أَيَّار',
'أَيْلُول',
'تَمُّوز',
'تِشْرِين ٱلثَّانِي',
'تِشْرِين ٱلْأَوَّل',
'تِشْرِين ٱلثَّانِي',
'تَمُّوز',
'حَزِيرَان',
'شُبَاط',
'كَانُون ٱلثَّانِي',
'كَانُون ٱلْأَوَّل',
'كَانُون ٱلثَّانِي',
'نَيْسَان',
],
abbr: [
'إبريل',
'أغسطس',
'أكتوبر',
'إبريل',
'ديسمبر',
'سبتمبر',
'فبراير',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/ar/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default {
abbr: null,
wide: [
'الإثنين',
'الأحَد',
'الأربعاء',
'الإثنين',
'الثلاثاء',
'الجمعة',
'الخميس',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/ar/vehicle/manufacturer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default [
'أودي',
'استون مارتن',
'أودي',
'بنتلي',
'بوجاتي',
'بورش',
Expand Down
8 changes: 4 additions & 4 deletions src/locales/ar/vehicle/model.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export default [
'أفينتادور',
'ألتيما',
'إسكاليد',
'إمبالا',
'اتفاق',
'إسكاليد',
'أفينتادور',
'اكسبلورر',
'البعثة',
'التركيز',
'ألتيما',
'الثور',
'القافلة الكبرى',
'الكونتاش',
'المدنية',
'النموذج 3',
'إمبالا',
'بريوس',
'بي تي كروزر',
'تشالنجر',
Expand Down
14 changes: 7 additions & 7 deletions src/locales/az/color/human.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export default [
'ala',
'açıq bənövşəyi',
'ağ',
'boz',
'ala',
'bənövşəyi',
'boz',
'çəhrayı',
'göy rəng',
'gümüşü',
'xlorofil',
'kardinal',
'mavi',
'narıncı',
'qara',
'qırmızı',
'qəhvəyi',
'qırmızı',
'mavi',
'narıncı',
'tünd göy',
'tünd qırmızı',
'xlorofil',
'yaşıl',
'çəhrayı',
];
10 changes: 5 additions & 5 deletions src/locales/az/commerce/department.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export default [
'Avtomobil',
'Ayyaqqabı',
'bəzək',
'Elektronika',
'Ev',
'Filmlər',
'Geyim',
'gözəllik',
'İdman',
'Kitablar',
'Kompyuterlər',
'Oyuncaqlar',
'Səhiyyə',
'bəzək',
'gözəllik',
'musiqi',
'Oyuncaqlar',
'oyunlar',
'Səhiyyə',
'turizm',
'uşaq üçün',
'İdman',
'садинструмент',
];
10 changes: 5 additions & 5 deletions src/locales/az/commerce/product_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ export default {
adjective: [
'Balaca',
'Ergonomik',
'Əlverişli',
'Fantastik',
'İnanılmaz',
'İntellektual',
'Kobud',
'Möhtəşəm',
'Mükəmməl',
'Parlaq',
'İnanılmaz',
'İntellektual',
'Əlverişli',
],
material: ['Ağac', 'Beton', 'Pambıq', 'Plastik', 'Polad', 'Qranit', 'Rezin'],
material: ['Ağac', 'Beton', 'Qranit', 'Pambıq', 'Plastik', 'Polad', 'Rezin'],
product: [
'Avtomobil',
'Beret',
'Kəmər',
'Kompyuter',
'Kulon',
'Kəmər',
'Stol',
'Stul',
'Sviter',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/az/company/prefix.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default ['ASC', 'MMC', 'QSC'];
export default ['ASC', 'QSC', 'MMC'];
2 changes: 1 addition & 1 deletion src/locales/az/date/weekday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export default {
'суббота',
'четверг',
],
abbr: ['BE', 'Ba', 'CA', 'Cü', 'ÇA', 'Çə', 'Şə'],
abbr: ['Ba', 'BE', 'CA', 'Cü', 'ÇA', 'Çə', 'Şə'],
abbr_context: ['вс', 'вт', 'пн', 'пт', 'сб', 'ср', 'чт'],
};
14 changes: 7 additions & 7 deletions src/locales/base/color/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ export default [
'Pantone Matching System (PMS)',
'ProPhoto RGB Color Space',
'RAL',
'RG',
'RGBA',
'RGK',
'Rec. 2020',
'Rec. 2100',
'Rec. 601',
'Rec. 709',
'RG',
'RGBA',
'RGK',
'scRGB',
'sRGB',
'sYCC',
'Uniform Color Spaces (UCSs)',
'xvYCC',
'YDbDr',
'YIQ',
'YPbPr',
'sRGB',
'sYCC',
'scRGB',
'xvYCC',
];
16 changes: 8 additions & 8 deletions src/locales/cs_CZ/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export default {
wide: [
'Březen',
'Červen',
'Červenec',
'Duben',
'Květen',
'Leden',
'Listopad',
'Prosinec',
'Říjen',
'Srpen',
'Září',
'Únor',
'Červen',
'Červenec',
'Říjen',
'Září',
],
abbr: [
'Bře',
'Čer',
'Črc',
'Dub',
'Kvě',
'Led',
'Lis',
'Pro',
'Říj',
'Srp',
'Zář',
'Úno',
'Čer',
'Črc',
'Říj',
'Zář',
],
};
4 changes: 2 additions & 2 deletions src/locales/cs_CZ/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
wide: ['Neděle', 'Pondělí', 'Pátek', 'Sobota', 'Středa', 'Úterý', 'čtvrtek'],
abbr: ['Ne', 'Po', 'Pá', 'So', 'St', 'Út', 'čt'],
wide: ['čtvrtek', 'Neděle', 'Pátek', 'Pondělí', 'Sobota', 'Středa', 'Úterý'],
abbr: ['čt', 'Ne', 'Pá', 'Po', 'So', 'St', 'Út'],
};
2 changes: 1 addition & 1 deletion src/locales/da/company/buzz_adjective.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default [
'24/365',
'24/7',
'allestedsnærværende',
'B2B',
'B2C',
'allestedsnærværende',
'back-end',
'bedst-i-klassen',
'brugercentrerede',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/da/company/buzz_noun.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default [
'ROI',
'applikationer',
'arkitektur',
'blockchains',
Expand Down Expand Up @@ -32,6 +31,7 @@ export default [
'platforme',
'portaler',
'relationer',
'ROI',
'skemaer',
'synergier',
'systemer',
Expand Down
20 changes: 10 additions & 10 deletions src/locales/da/company/company_name.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export default [
'Aabenraa Anlæg',
'Aabenraa Automater',
'Aalborg Aqua',
'Aarhus Automatik',
'Albertslund Aluminium',
'Albertslund App',
'Allerød Akustik',
Expand Down Expand Up @@ -36,7 +32,6 @@ export default [
'Egedal Erhverv',
'Esbjerg Elektronik',
'Esbjerg Energi',
'Faaborg-Midtfyn Film',
'Falster Farmaceuter',
'Fanø Fartøj',
'Fanø Forsikring',
Expand All @@ -58,6 +53,7 @@ export default [
'Furesø Fisk',
'Fyn Fiskeri',
'Fynske Fødevarer',
'Faaborg-Midtfyn Film',
'Gentofte Genbrug',
'Gladsaxe Glas',
'Glostrup Gaming',
Expand All @@ -66,9 +62,9 @@ export default [
'Gribskov Græs',
'GrønBølge Energi',
'Grønland Gourmet',
'GuldHornet Mode',
'Guldborgsund Gas',
'Guldborgsund Guld',
'GuldHornet Mode',
'Haderslev Haver',
'Haderslev Håndværk',
'Halsnæs Halvleder',
Expand Down Expand Up @@ -110,9 +106,9 @@ export default [
'Mors Møbler',
'Morsø Maling',
'NaturLinjen Kosmetik',
'NordHavn Teknologier',
'Norddjurs Naturlig',
'Nordfyn Næringsstoffer',
'NordHavn Teknologier',
'Nordisk NanoLab',
'Nordlys Finans',
'Nyborg Nytte',
Expand Down Expand Up @@ -143,12 +139,12 @@ export default [
'Sydfyn Sko',
'SynergiSport Udstyr',
'Sønderborg Sol',
'Taastrup Transport',
'Thisted Tjenester',
'Thy Teknik',
'Trekroner Forsikring',
'Tårnby Tekstiler',
'Tønder Tekstil',
'Tårnby Tekstiler',
'Taastrup Transport',
'Valby VandTek',
'Varde Varehandel',
'Vejen Vand',
Expand All @@ -157,7 +153,11 @@ export default [
'Viborg Video',
'VikingNetværk',
'Vordingborg Vind',
'Århus Robotik',
'Øresund MarineTek',
'ØstVind Innovation',
'Aabenraa Anlæg',
'Aabenraa Automater',
'Aalborg Aqua',
'Aarhus Automatik',
'Århus Robotik',
];
2 changes: 1 addition & 1 deletion src/locales/da/company/descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default [
'holdningsorienteret',
'homogen',
'hybrid',
'håndgribelig',
'højniveau',
'håndgribelig',
'indholdsbaseret',
'inkremental',
'interaktiv',
Expand Down
Loading
Loading