mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
fix: add check for invalid locales (#1353)
## Description Currently invalid or missing `accept-language` headers will cause issues rendering Plural components since we do not validate them. This adds a check to try filter out invalid locales. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced locale filtering process to ensure only valid locales are processed. - **Bug Fixes** - Improved data integrity by preventing invalid locales from affecting application functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@ -90,8 +90,18 @@ export const extractLocaleData = ({
|
||||
lang = 'en';
|
||||
}
|
||||
|
||||
// Filter out locales that are not valid.
|
||||
const locales = (langHeader?.locales ?? []).filter((locale) => {
|
||||
try {
|
||||
new Intl.Locale(locale);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
lang: lang || APP_I18N_OPTIONS.sourceLang,
|
||||
locales: langHeader.locales,
|
||||
locales,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user