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

Cleanup LocaleManager #21541

Merged
merged 12 commits into from
Dec 19, 2024

Conversation

nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Dec 17, 2024

This PR does two things:

  • Cleanup LocaleManager by removing unused code and fixing warnings
  • Convert LocaleMananger to Kotlin

These actions will make it easier to eventually do away with storing the app language in our shared preferences, enabling the system to be in charge of the language.

I left as much logic unchanged as possible, but I did need to make minor modifications to createSortedLanguageDisplayStrings to get it to work. This change can be tested two ways:

Test 1:

  • My Site > Site Settings
  • Tap Language
  • Verify the language picker appears correctly

Test 2:

  • On a pre-API 13 device, go to App Settings
  • Tap the Interface Language
  • Verify the language picker appears correctly

@nbradbury nbradbury changed the title Nick/cleanup locale manager Cleanup LocaleManager Dec 17, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Dec 17, 2024

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@nbradbury nbradbury changed the base branch from trunk to feature/per-app-language-prefs December 17, 2024 18:52
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Dec 17, 2024

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21541-980b8d6
Commit980b8d6
Direct Downloadjetpack-prototype-build-pr21541-980b8d6.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Dec 17, 2024

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21541-980b8d6
Commit980b8d6
Direct Downloadwordpress-prototype-build-pr21541-980b8d6.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.48%. Comparing base (92d71de) to head (980b8d6).
Report is 13 commits behind head on feature/per-app-language-prefs.

Additional details and impacted files
@@                        Coverage Diff                         @@
##           feature/per-app-language-prefs   #21541      +/-   ##
==================================================================
+ Coverage                           39.44%   39.48%   +0.03%     
==================================================================
  Files                                2118     2117       -1     
  Lines                               99550    99464      -86     
  Branches                            15312    15296      -16     
==================================================================
  Hits                                39269    39269              
+ Misses                              56800    56714      -86     
  Partials                             3481     3481              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nbradbury nbradbury marked this pull request as ready for review December 18, 2024 12:20
Copy link
Contributor

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @nbradbury !

I have reviewed and tested this PR as per the instructions, everything works as expected, great job Kotlinizing LocalManager! 🌟 x 🌟 ^ 🌟

PS: I especially like the fact that you add nullability annotations on the Java side before the conversion, kudos. 💯


I have left one questions (❓), a couple of suggestions (💡) and some minor (🔍) comments for you to consider. I am going to approve this PR anyway, since none is blocking. I am NOT going to merge this PR yet to give you some time to apply any of my suggestions. However, feel free to ignore them and merge the PR yourself.

for (i in entryStrings.indices) {
// now, we can split the sorted array to extract the display string and the language code
val split =
entryStrings[i].split("__".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Question (❓): How come this String[] split = entryStrings.get(i).split("__"); Java related code got replace with this Kotlin related code that seems that much more involved (toRegex() + dropLastWhile { ... } + toTypedArray()). I am sure there is a good reason, I just want to understand it better... 😊
  2. Minor (🔍): Consider splitting this logic into multiple lines for readability purposes:
            val split = entryStrings[i]
                .split("__".toRegex())
                .dropLastWhile { it.isEmpty() }
                .toTypedArray()

@nbradbury
Copy link
Contributor Author

PS: I especially like the fact that you add nullability annotations on the Java side before the conversion, kudos. 💯

Thanks for noticing that! I actually attempted the conversion without addressing the nullability issues and it was a disaster :)

I've implemented most of your thoughtful suggestions but left some as-is because #21542 removes some of that code.

@nbradbury nbradbury merged commit b9e2deb into feature/per-app-language-prefs Dec 19, 2024
22 checks passed
@nbradbury nbradbury deleted the nick/cleanup-locale-manager branch December 19, 2024 13:40
@ParaskP7
Copy link
Contributor

I've implemented most of your thoughtful suggestions but left some as-is because #21542 removes some of that code.

Thanks for applying the suggestions @nbradbury and noted about #21542 ! 🥇

Thanks for noticing that! I actually attempted the conversion without addressing the nullability issues and it was a disaster :)

😄 I could imagine, Kotlin is as smart as it gets, but it isn't AI or God, the more we help it the better the result! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants