Skip to content

Conversation

Stefterv
Copy link
Collaborator

@Stefterv Stefterv commented Oct 15, 2025

As part of the Jetpack Compose UI, we would like to have a reactive component that we can use to read and set Processing's Locale live. This PR will improve on the existing functionality and adds testing.

Part of #1280

Changed the setLocale parameter in the Locale class to be nullable and updated its usage to safely invoke it. This allows for more flexible instantiation when a setLocale function is not required.
@Stefterv Stefterv requested a review from catilac October 15, 2025 09:43
Replaces the call to locale.setLocale with locale.set in LocaleKtTest to match the updated API for changing the locale.
@Stefterv Stefterv marked this pull request as ready for review October 15, 2025 09:58
@Stefterv Stefterv changed the base branch from main to welcome-screen October 16, 2025 08:38
Copy link
Collaborator

@catilac catilac left a comment

Choose a reason for hiding this comment

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

looks good! i left a couple questions for my own learning and curiosity

Comment on lines -17 to +31
val locale = java.util.Locale.getDefault()
load(ClassLoader.getSystemResourceAsStream("PDE.properties"))
load(ClassLoader.getSystemResourceAsStream("PDE_${locale.language}.properties") ?: InputStream.nullInputStream())
load(ClassLoader.getSystemResourceAsStream("PDE_${locale.toLanguageTag()}.properties") ?: InputStream.nullInputStream())
load(ClassLoader.getSystemResourceAsStream("PDE_${language}.properties") ?: InputStream.nullInputStream())
loadResourceUTF8("PDE.properties")
loadResourceUTF8("PDE_${locale.language}.properties")
loadResourceUTF8("PDE_${locale.toLanguageTag()}.properties")
loadResourceUTF8("PDE_${language}.properties")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is so nice

Comment on lines +125 to +128
CompositionLocalProvider(LocalLayoutDirection provides dir) {
CompositionLocalProvider(LocalLocale provides locale) {
content()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah cool! So this is like how things are composable? People can pass in a block that will be wrapped by this Locale work

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly, if you want access to localised strings you do

LocaleProvider {
  val locale = LocalLocale.current
  val localizedString = locale["someKey"]
}

And the beatiful things about these contexts is that if you want to display say something in Spanish within the English interface, you can override the LocalLocale with a CompositionLocalProvider. In that case its not super helpful but there's a lot of other cases where its very much is

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.

2 participants