@@ -146,17 +146,23 @@ export const SUPPORTED_LANGUAGES = {
146146let current : SupportedI18nLanguage | undefined ;
147147
148148export const getCurrent = ( ) : SupportedI18nLanguage => {
149- const savedLocale = settings . restore < SupportedI18nLanguage | undefined > ( SettingsType . LOCALE ) ;
150- const savedOverride = settings . restore < boolean | undefined > ( SettingsType . LOCALE_OVERRIDE ) ;
151-
152- // If the override flag is missing, assume the user wanted an override only when the saved value differs
153- // from the current system locale. This keeps existing manual choices intact while allowing auto language
154- // to track OS changes.
155149 const systemLocale = getSystemLocale ( ) ;
156- const hasUserOverride =
157- typeof savedOverride === 'boolean' ? savedOverride : Boolean ( savedLocale && savedLocale !== systemLocale ) ;
158150
159- current = savedLocale && hasUserOverride ? parseLocale ( savedLocale ) : systemLocale ;
151+ if ( ! current ) {
152+ const savedLocale = settings . restore < SupportedI18nLanguage | undefined > ( SettingsType . LOCALE ) ;
153+ const savedOverride = settings . restore < boolean | undefined > ( SettingsType . LOCALE_OVERRIDE ) ;
154+ const hasUserOverride =
155+ typeof savedOverride === 'boolean' ? savedOverride : Boolean ( savedLocale && savedLocale !== systemLocale ) ;
156+
157+ current = savedLocale && hasUserOverride ? parseLocale ( savedLocale ) : systemLocale ;
158+ return current ;
159+ }
160+
161+ // If there’s no override and the system locale changed, update the cache
162+ const hasOverride = settings . restore < boolean | undefined > ( SettingsType . LOCALE_OVERRIDE ) === true ;
163+ if ( ! hasOverride && current !== systemLocale ) {
164+ current = systemLocale ;
165+ }
160166 return current ;
161167} ;
162168
@@ -188,7 +194,7 @@ export const getText = (
188194
189195export const setLocale = ( locale : string ) : void => {
190196 current = parseLocale ( locale ) ;
191- settings . save ( SettingsType . LOCALE , current ) ;
197+
192198 const systemLocale = getSystemLocale ( ) ;
193199 const isOverride = current !== systemLocale ;
194200
0 commit comments