Skip to content

Commit 8466ee1

Browse files
authored
Instant Locale Updatee (#1384)
Keep track of locale updates within the Process so that when the user changes the locale, that is immediately reflected within the app and later within other instances of Processing when the watch file kicks off the reload
1 parent 4edb29a commit 8466ee1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/src/processing/app/ui/theme/Locale.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Locale(language: String = "", val setLocale: ((java.util.Locale) -> Unit)?
6262
* ```
6363
*/
6464
val LocalLocale = compositionLocalOf<Locale> { error("No Locale Set") }
65+
var LastLocaleUpdate by mutableStateOf(0L)
6566

6667
/**
6768
* This composable function sets up a locale provider that manages application localization.
@@ -101,7 +102,11 @@ fun LocaleProvider(content: @Composable () -> Unit) {
101102
}
102103

103104
val update = watchFile(languageFile)
104-
var code by remember(languageFile, update) { mutableStateOf(languageFile.readText().substring(0, 2)) }
105+
var code by remember(languageFile, update, LastLocaleUpdate) {
106+
mutableStateOf(
107+
languageFile.readText().substring(0, 2)
108+
)
109+
}
105110
remember(code) {
106111
val locale = java.util.Locale(code)
107112
java.util.Locale.setDefault(locale)
@@ -111,6 +116,7 @@ fun LocaleProvider(content: @Composable () -> Unit) {
111116
Messages.log("Setting locale to ${locale.language}")
112117
languageFile.writeText(locale.language)
113118
code = locale.language
119+
LastLocaleUpdate = System.currentTimeMillis()
114120
}
115121

116122

0 commit comments

Comments
 (0)