How do we set the Default Culture and UI Culture
abineshamatya opened this issue · 3 comments
Can someone help me with setting up the Default Culture and Default UI Culture?
I did try setting the following options at the Startup. cs:
services.AddJsonLocalization(options =>
{
options.SupportedCultureInfos = new HashSet<CultureInfo>()
{
new CultureInfo("np"),
new CultureInfo("en-US")
};
options.DefaultCulture = new CultureInfo("np");
options.DefaultUICulture = new CultureInfo("np");
options.CacheDuration = TimeSpan.FromMinutes(15);
options.ResourcesPath = "Resources";
options.LocalizationMode = LocalizationMode.I18n;
});
However, it is always taking the "en-Us" as the default culture resource. Here is the snapshot of the file located on the project:
Any help would be much more appreciable.
Thanks
I have no solution but maybe to try the following...
Maybe to configure this in appsettings.json:
"JsonLocalizationOptions": {
"ResourcesPath": "Resources",
"CacheDuration": "00:00:15",
"DefaultCulture": "np",
"DefaultUICulture": "np",
"SupportedCultureInfos": [ "en-US", "np" ],
"IsAbsolutePath": false,
"FileEncodingName": "utf-8",
"UseBaseName": false
}
I then added:
services.AddJsonLocalization(options =>
{
options.ResourcesPath = _jsonLocalizationOptions.ResourcesPath;
options.UseBaseName = _jsonLocalizationOptions.UseBaseName;
options.CacheDuration = _jsonLocalizationOptions.CacheDuration;
options.SupportedCultureInfos = _jsonLocalizationOptions.SupportedCultureInfos;
options.FileEncoding = _jsonLocalizationOptions.FileEncoding;
options.IsAbsolutePath = _jsonLocalizationOptions.IsAbsolutePath;
options.LocalizationMode = LocalizationMode.I18n;
});
If it doesn't work maybe the issue is np - as that culture info format is not proper one most probably.
Is it Nepal? So... should be ne-NP
@tijana-vujanac thanks for your answer.
Your are right with the configuration and I @abineshamatya you need to be sure that np is the correct ISO name for your langage.
You can also use app.UseRequestLocalization to use cookie or browser langage.
You can have more information about it here : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-5.0#localization-middleware
@tijana-vujanac : Actually it was for Nepal and yes the filename of the resource was incorrect. Thanks for the reply :)