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

feat: get/set app locale #282

Closed
wants to merge 4 commits into from

Conversation

itsramiel
Copy link

Summary

Helpful for creating in-app language pickers(on Android) which sync with app system settings

Test Plan

What's required for testing (prerequisites)?

What are the steps to test it (after prerequisites)?

Compatibility

OS Implemented
iOS ✅❌
Android ✅❌

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I added a sample use of the API in the example project (example/src/App.js)

@zoontek
Copy link
Owner

zoontek commented Oct 30, 2024

@itsramiel Hey! Thanks for this, but can you reduce the amount of changes to the absolute strict minimum? So just the getter / setter. No code organization change, no event emittters, etc.

@itsramiel
Copy link
Author

itsramiel commented Oct 30, 2024

@itsramiel Hey! Thanks for this, but can you reduce the amount of changes to the absolute strict minimum? So just the getter / setter. No code organization change, no event emittters, etc.

Sure, but no event emitters would be an incomplete feature. If a user change the language from system settings, the app would not know that without an event.

The radical changes to the RNLocalizationModuleImpl changing it from static to nonstatic methods is to store the context and use it to send events in the sendEvent method.

I can drop these changes if you want, but let me know how you would like to notify changes back to the user.

@zoontek
Copy link
Owner

zoontek commented Oct 30, 2024

Sure, but no event emitters would be an incomplete feature. If a user change the language from system settings, the app would not know that without an event.

EDIT: Just got it. This can work without updating the whole code organisation (keeping static methods).

Check how I do on rn-edge-to-edge: https://github.com/zoontek/react-native-edge-to-edge/blob/main/android/src/oldarch/com/zoontek/rnedgetoedge/EdgeToEdgeModule.kt

@itsramiel
Copy link
Author

itsramiel commented Oct 30, 2024

EDIT: Just got it. This can work without updating the whole code organisation (keeping static methods).

Check how I do on rn-edge-to-edge: zoontek/react-native-edge-to-edge@main/android/src/oldarch/com/zoontek/rnedgetoedge/EdgeToEdgeModule.kt

In the linked code, you are not sending events to js(as far as I can see). I am not sure what you are referring to.

I'll be waiting for your feedback before moving forward with this pr cause I am not sure how you want me to proceed.

@zoontek
Copy link
Owner

zoontek commented Oct 30, 2024

I'm not, but you easily call a static method that will do it: Impl.emitEvent(reactContext, …) (in the example, I call EdgeToEdgeModuleImpl.onConfigChange(reactContext))

@itsramiel
Copy link
Author

Yes, in this case since you are creating a broadcastlistener while having access to the context.
In my implementation, users of the library will have to call an onConfigurationChanged from the MainActivity because setting a BroadcastReceiver for ACTION_LOCALE_CHANGED or ACTION_CONFIGURATION_CHANGED is not triggering for Apis < 33, but the onConfigurationChanged on the main activity is called on all Apis

@zoontek
Copy link
Owner

zoontek commented Oct 30, 2024

@itsramiel But it also creates the need for an expo plugin, as it must modify the MainActivity.kt file on prebuild. Let me have a closer look at the feature and your WIP when I can find a bit of time.

EDIT: works perfectly on my side, I tried on API 29:

Screenshot 2024-10-30 at 23 22 24

@zoontek
Copy link
Owner

zoontek commented Oct 31, 2024

I finally took some time to read the feature documentation and experiment with it. I really dislike the Android API and developer experience—it seems like a mistake to expose it to React Native developers as it currently is.

The goal is to have an in-app language picker that syncs with a device-level language setting (peak UX, thanks Google), so there’s plenty of room for a cleaner, cross-platform API.

But to be honest, I don’t currently have the free time to devote to this, including helping with its design or reviewing it.

@itsramiel
Copy link
Author

Got it.

Thank you for taking the time to check it. Will be closing it for now

@itsramiel itsramiel closed this Oct 31, 2024
@itsramiel itsramiel deleted the feat/get-set-app-locale branch October 31, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for "app languages" on Android
2 participants