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
23 changes: 20 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, definitionKey, locale);
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
}

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

let collator = null;
try {
// eslint-disable-next-line no-restricted-globals
collator = new Intl.Collator(locale.replaceAll('_', '-'));
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
} catch {
console.warn(
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
`Failed to create collator for locale ${locale}. Using default collator.`
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
);
// eslint-disable-next-line no-restricted-globals
collator = new Intl.Collator('en');
}

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
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'];
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',
];
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
2 changes: 1 addition & 1 deletion src/locales/de/color/human.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default [
'Indigo',
'Jadegrün',
'Kastanienbraun',
'Kupfer',
'Königsblau',
'Kupfer',
'Lila',
'Magenta',
'Mintgrün',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/de/company/name_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default [
'{{person.last_name}} {{company.suffix}}',
'{{person.last_name}}, {{person.last_name}} und {{person.last_name}}',
'{{person.last_name}}-{{person.last_name}}',
'{{person.last_name}}, {{person.last_name}} und {{person.last_name}}',
];
2 changes: 1 addition & 1 deletion src/locales/de_AT/company/name_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default [
'{{person.last_name}} {{company.suffix}}',
'{{person.last_name}}, {{person.last_name}} und {{person.last_name}}',
'{{person.last_name}}-{{person.last_name}}',
'{{person.last_name}}, {{person.last_name}} und {{person.last_name}}',
];
2 changes: 1 addition & 1 deletion src/locales/de_CH/company/name_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default [
'{{person.last_name}} {{company.suffix}}',
'{{person.last_name}}, {{person.last_name}} und {{person.last_name}}',
'{{person.last_name}}-{{person.last_name}}',
'{{person.last_name}}, {{person.last_name}} und {{person.last_name}}',
];
2 changes: 1 addition & 1 deletion src/locales/dv/company/name_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export default [
'{{company.adjective}} {{company.noun}} {{company.suffix}}',
'{{company.adjective}} {{person.last_name}} {{person.last_name}} {{company.suffix}}',
'{{person.first_name}} {{company.suffix}}',
'{{person.last_name}} & {{person.last_name}} {{company.noun}} {{company.suffix}}',
'{{person.last_name}} {{company.suffix}}',
'{{person.last_name}} & {{person.last_name}} {{company.noun}} {{company.suffix}}',
];
4 changes: 2 additions & 2 deletions src/locales/el/commerce/department.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default [
'Grocery',
'Sports',
'Αυτοκίνητο',
'Βιβλία',
'Βιομηχανικά',
Expand All @@ -20,4 +18,6 @@ export default [
'Ταινίες',
'Υγεία',
'Υπολογιστές',
'Grocery',
'Sports',
];
6 changes: 3 additions & 3 deletions src/locales/el/commerce/product_name.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
adjective: [
'Άδεια',
'Αγροτικό',
'Άδεια',
'Απίστευτο',
'Εργονομικό',
'Κομψό',
Expand All @@ -13,7 +13,6 @@ export default {
],
material: ['Κατεψυγμένο', 'Μέταλο', 'Ξύλινο', 'Πλαστικό', 'Φρέσκο'],
product: [
'Pizza',
'Αυτοκίνητο',
'Γάντια',
'Καπέλο',
Expand All @@ -30,10 +29,11 @@ export default {
'Πουκάμισο',
'Σαλάτα',
'Σαπούνι',
'Τόνος',
'Τραπέζι',
'Τυρί',
'Τόνος',
'Υπολογιστής',
'Ωάρι',
'Pizza',
],
};
Loading
Loading