Open saiganesh-sakthivel opened 1 year ago
@saiganesh-sakthivel This is not specific to the DatePicker
control, it's how you're setting the language in code.
public App()
{
InitializeComponent();
var culture = new CultureInfo("fr-FR"); // Replace with your desired culture or language code
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
MainPage = new AppShell();
}
Setting the CurrentCulture
values affects the .NET side of localization but doesn't necessarily touch the native platform. So if you had, say, a RESX
file with the fr
language, that would be set and rendered, but these controls would not get touched because the underlying platform still treats the overall system as running in whatever local you have.
For example, on iOS/Mac Catalyst, you need to declare the language in your Info.plist (The documentation refers to Xamarin.iOS but it also applies to MAUI for iOS and Catalyst),
If you set those values, then it will appear in the local you want, regardless of what's on the system. This is also how you can allow users in the iOS setting app to change the application's language.
In the case of iOS/Catalyst, AFAIK, there's no way to programmatically control what local the controls use without at least setting up the info.plist (CC @rolfbjarne is that right?)
IMO, this isn't a MAUI bug persay, we need documentation on the proper way to localize a MAUI app, just setting the CurrentCulture in dotnet isn't enough.
@Redth @davidbritch does that sound right?
Hi @drasticactions,
Any proper guidelines is have to achieve the MAUI DatePicker calendar view localization for Windows, UWP, android, iOS and MacOS.
In the case of iOS/Catalyst, AFAIK, there's no way to programmatically control what local the controls use without at least setting up the info.plist (CC @rolfbjarne is that right?)
Correct, and also note that the correct way to change the selected locale of the app is to change it in the Settings app (see https://developer.apple.com/news/?id=u2cfuj88).
@Redth @davidbritch does that sound right?
Yes. IIRC (and my memory's a bit fuzzy on this), I had some success in updating the approach to use Microsoft.Extensions.Localization.
But yes, the doc still needs writing.
On windows in Package.appxmanifest
:
If I only have <Resource Language="x-generate" />
the datepicker will use the current os language.
If I specify one language, it will use the language specified.
If I have multiple languages specified, it will take the first in order.
<Resources>
<!--<Resource Language="x-generate" />-->
<Resource Language="de-DE"/>
<!--<Resource Language="en-US"/>-->
<!--<Resource Language="nl"/>-->
</Resources>
So, these settings determines the language of the datepicker. How can I change the language of the datepicker during runtime?
This doesn't work:
var userLanguages = new List<string>() { iso };
DatePickerHandler.Mapper.AppendToMapping("FixDatepickerLanguage", (handler, view) =>
{
handler.PlatformView.Language = twoLetterIso;
});
@saiganesh-sakthivel This is not specific to the
DatePicker
control, it's how you're setting the language in code.public App() { InitializeComponent(); var culture = new CultureInfo("fr-FR"); // Replace with your desired culture or language code CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; MainPage = new AppShell(); }
Setting the
CurrentCulture
values affects the .NET side of localization but doesn't necessarily touch the native platform. So if you had, say, aRESX
file with thefr
language, that would be set and rendered, but these controls would not get touched because the underlying platform still treats the overall system as running in whatever local you have.For example, on iOS/Mac Catalyst, you need to declare the language in your Info.plist (The documentation refers to Xamarin.iOS but it also applies to MAUI for iOS and Catalyst),
If you set those values, then it will appear in the local you want, regardless of what's on the system. This is also how you can allow users in the iOS setting app to change the application's language.
In the case of iOS/Catalyst, AFAIK, there's no way to programmatically control what local the controls use without at least setting up the info.plist (CC @rolfbjarne is that right?)
IMO, this isn't a MAUI bug persay, we need documentation on the proper way to localize a MAUI app, just setting the CurrentCulture in dotnet isn't enough.
@Redth @davidbritch does that sound right?
@Redth @davidbritch @drasticactions :
If I set the folwoing code in MainApplication.cs
:
this.Resources.Configuration.Locales = new Android.OS.LocaleList(new Java.Util.Locale("fr-FR"));
then, I only get the header in French and the rest stays in German:
Verified this issue with Visual Studio Enterprise 17.9.0 Preview 4. Can repro on android platforms with sample project. It's no longer repro on iOS and Windows platforms. https://github.com/dotnet/maui/files/11798627/MauiApp1.zip
Zhanglirong-Winnie, I opened your example and I can still repro this, with the latest .NET 8 and VS 2022 17.10.6 No matter what CultureInfo I set in app.xaml.cs, it is still showing the default one set in the Maui app (English US) Even if I set the region to French (France) in Windows (11), it is still not showing correctly the date in the picker.
Description
We want to localize the calendar in the datepicker. We have set the cultureInfo as fr (French) for the application. but it does not change the language as french locale the view.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/dotnet/maui/files/11798627/MauiApp1.zip
Version with bug
7.0.49
Last version that worked well
6.0
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
iOS 16, android 11, windows
Did you find any workaround?
No response
Relevant log output
No response