Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically switching from left to right/right to left localization. #14755

Open
bluetreee opened this issue Apr 24, 2023 · 15 comments
Open
Labels
area-localization Localization and globalization issues platform/android 🤖 platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@bluetreee
Copy link

Description

We are trying to implement a settings page that will allow the user to select a language preference between English and Arabic. When we programmatically change the System.Globalization.CultureInfo.CurrentCulture and System.Globalization.CultureInfo.CurrentUICulture, the text resources will translate, but the left to right/right to left orientation of the screen elements will not change. Currently, it appears the only way for the app to change from left to right/right to left is when the device language is changed.

Steps to Reproduce

  1. Have the phone language set to Arabic.
  2. Open the sample project. Observe that the right to left layout flow is being used due to Arabic being the current culture.
  3. Press the "Click to switch language button".

Result: The text has switched to English, but the right to left layout flow is still being observed.
Expected Result: The text has switched to English, and the layout flow has switched to left to right.

This also occurs if the device setting is set to English on startup and the language is switched to Arabic in the app (text changes, but left to right layout flow persists).

Link to public reproduction project repository

https://github.com/bluetreee/LocalizationTest

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

Android API 33, iOS 16

Did you find any workaround?

No response

Relevant log output

No response

@bluetreee bluetreee added the t/bug Something isn't working label Apr 24, 2023
@Eilon Eilon added the area-localization Localization and globalization issues label Apr 24, 2023
@rachelkang
Copy link
Member

@rolfbjarne @jonathanpeppers What is the expectation for in-app culture changes related to system language settings on Android and iOS?

@rachelkang rachelkang added this to the Backlog milestone Apr 26, 2023
@ghost
Copy link

ghost commented Apr 26, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@rachelkang
Copy link
Member

@bluetreee While we get clarity on expectations here of whether the layout direction should change automatically, I suggest you try changing it by setting the LayoutDirection to RightToLeft or LeftToRight. https://learn.microsoft.com/dotnet/api/microsoft.maui.applicationmodel.layoutdirection?view=net-maui-7.0

@rolfbjarne
Copy link
Member

@rolfbjarne @jonathanpeppers What is the expectation for in-app culture changes related to system language settings on Android and iOS?

It's seems like Apple's expectation for iOS is "don't do that."

I haven't found anything official from Apple, but these stackoverflow posts don't seem to find a good solution for Objective-C/Swift apps:

Where the answer basically is: do it yourself, there's no automatic support for it.

@jonathanpeppers
Copy link
Member

The info I found for Android basically recommends restarting the entire Activity:

https://stackoverflow.com/q/13181847

This would probably still work in a .NET MAUI app, as calling Activity.Recreate() should refresh/recreate all MAUI views.

@PureWeen
Copy link
Member

You can set the FlowDirection on the Window and that should shift the app to RTL or LTR as well.

You can get to the window from any xaml element
element.Window

@rachelkang rachelkang added the s/needs-info Issue needs more info from the author label Apr 27, 2023
@ghost
Copy link

ghost commented Apr 27, 2023

Hi @bluetreee. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label May 1, 2023
@ghost
Copy link

ghost commented May 1, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@bluetreee
Copy link
Author

Thanks for looking into this. We've tried setting the FlowDirection on AppShell and Window with no success. When setting FlowDirection on the page level, it worked on the page contents, but did not work on the toolbar. Also, upon adding another page to the stack, the new FlowDirection was not inherited. We can try creating a base class that sets the FlowDirection during construction. We also tested Activity.Recreate() which worked, so we can try to find a similar solution for iOS. However, it would be nice to have a .NET MAUI solution that could be reflected across any platform.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity labels May 3, 2023
@cruzmar
Copy link

cruzmar commented May 18, 2023

Setting the FlowDirection at page level works on elements declared directly on that page. However, elements inside of a ContentView are not displayed if the FlowDirection is set to RightToLeft.

@hartez
Copy link
Contributor

hartez commented May 18, 2023

Setting the FlowDirection at page level works on elements declared directly on that page. However, elements inside of a ContentView are not displayed if the FlowDirection is set to RightToLeft.

What you're seeing is issue #15095, and we're currently working on a fix for that: #15114

@dk-mushiyoke
Copy link

Greetings folks, it's been a while, is there any new updates to this ticket?

@shmoe01
Copy link

shmoe01 commented Aug 22, 2023

Did this one ever get resolved in .NET 8?

@hartez
Copy link
Contributor

hartez commented Aug 23, 2023

The flow direction issues in ContentView were resolved. That may be the last thing we needed to resolve to close this issue.

@rachelkang and @PureWeen - do we think this is closeable, or is there more to address?

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jan 9, 2024
@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 2.1. Can repro on android platforms with sample project.
LocalizationTest-main.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-localization Localization and globalization issues platform/android 🤖 platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests