Fixing basque language name hydration issues on Google Chrome (#1415)

This commit is contained in:
Keith Stevens
2023-02-10 07:47:43 +01:00
committed by GitHub
parent aaa1276bae
commit ebd05e8d32
5 changed files with 22 additions and 9 deletions
+13
View File
@@ -0,0 +1,13 @@
/**
* Returns the locale's name.
*/
export const getLocaleDisplayName = (locale, displayLocale = undefined) => {
// Different browsers seem to handle "eu" differently from the Node server.
// Special case this to avoid a hydration failure.
if (locale === "eu") {
return "Eurakasa";
}
const displayName = new Intl.DisplayNames([displayLocale || locale], { type: "language" }).of(locale);
// Return the Titlecased version of the language name.
return displayName.charAt(0).toLocaleUpperCase() + displayName.slice(1);
};