With Next.js, I have successfully retrieved the current locale and all available locales for a language selection menu:
const {currentLocale, availableLocales} = useContext(LangContext);
// currentLocale = "en-US"
// availableLocales = ["en-US", "de-DE"]
To facilitate the display of the full language name, I created this function:
const getLocaleDisplayName = ()=> {
if (currentLocale === "en-US") { return "English" };
if (currentLocale === "de-DE") { return "Deutsch" };
}
Now, I aim to transform availableLocales
from
["en-US", "de-DE"]
to ["English", "Deutsch"]
. This not only enhances the visual appeal but also simplifies the language selection process for users.
What would be the most effective approach to achieve this?