mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-23 04:34:15 -04:00
28 lines
1004 B
TypeScript
28 lines
1004 B
TypeScript
import locales from '~~/locale/locales.ts';
|
|
import type { LocaleCode, LocaleDescription } from '~~/locale/locales.ts';
|
|
|
|
export default (current: LocaleCode | null, includeUnpublished = false): LocaleDescription[] => {
|
|
const matchedLocales: LocaleDescription[] = locales.filter((locale) => {
|
|
return locale.code === current || locale.published || includeUnpublished;
|
|
});
|
|
|
|
// hoist current to top, then published, then unpublished
|
|
const sortedLocales: LocaleDescription[] = [];
|
|
const currentLocale = matchedLocales.find((locale) => locale.code === current);
|
|
if (currentLocale) {
|
|
sortedLocales.push(currentLocale);
|
|
}
|
|
for (const locale of matchedLocales) {
|
|
if (locale.code !== current && locale.published) {
|
|
sortedLocales.push(locale);
|
|
}
|
|
}
|
|
for (const locale of matchedLocales) {
|
|
if (locale.code !== current && !locale.published) {
|
|
sortedLocales.push(locale);
|
|
}
|
|
}
|
|
|
|
return sortedLocales;
|
|
};
|