Detecting Original System Language and Matching to Available Locale

Hi there,

Let’s say a user has selected a locale different from his system.

At runtime, I want to determine the user’s system language and find the closest matching locale from the available locales to present as an option to the user.

Please advise

Hi,
It sounds like you are trying to reproduce the SystemLocaleSelector behaviour.
Whilst this is used to select a locale at startup it can also be used to do what you want.
Do something like this:

var systemLocaleSelector = LocalizationSettings.StartupLocaleSelectors.FirstOrDefault(s => s is SystemLocaleSelector) ?? new SystemLocaleSelector();
var foundLocale = systemLocaleSelector.GetStartupLocale(LocalizationSettings.AvailableLocales);

This will find the closest locale to the system language from the list of AvailableLocales.

1 Like

Thanks, really appreciate
With above, now i can show user a “prefered language to switch”

1 Like