fix(i18n): resolve prompt persistence and language menu behavior
This commit is contained in:
@@ -89,6 +89,7 @@ export function LaunchWindow() {
|
|||||||
systemLocaleSuggestion,
|
systemLocaleSuggestion,
|
||||||
acceptSystemLocaleSuggestion,
|
acceptSystemLocaleSuggestion,
|
||||||
dismissSystemLocaleSuggestion,
|
dismissSystemLocaleSuggestion,
|
||||||
|
resolveSystemLocaleSuggestion,
|
||||||
} = useI18n();
|
} = useI18n();
|
||||||
const suggestedLanguageName = systemLocaleSuggestion ? getLocaleName(systemLocaleSuggestion) : "";
|
const suggestedLanguageName = systemLocaleSuggestion ? getLocaleName(systemLocaleSuggestion) : "";
|
||||||
|
|
||||||
@@ -554,12 +555,15 @@ export function LaunchWindow() {
|
|||||||
side="top"
|
side="top"
|
||||||
sideOffset={6}
|
sideOffset={6}
|
||||||
collisionPadding={6}
|
collisionPadding={6}
|
||||||
className={`w-36 min-w-0 max-h-none overflow-hidden border-white/15 bg-[rgba(24,24,34,0.98)] p-1 text-white shadow-2xl backdrop-blur-xl ${styles.electronNoDrag}`}
|
className={`w-36 min-w-0 max-h-none overflow-y-hidden overflow-x-hidden border-white/15 bg-[rgba(24,24,34,0.98)] p-1 text-white shadow-2xl backdrop-blur-xl ${styles.electronNoDrag}`}
|
||||||
>
|
>
|
||||||
{SUPPORTED_LOCALES.map((loc) => (
|
{SUPPORTED_LOCALES.map((loc) => (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
key={loc}
|
key={loc}
|
||||||
onSelect={() => setLocale(loc)}
|
onSelect={() => {
|
||||||
|
setLocale(loc);
|
||||||
|
resolveSystemLocaleSuggestion();
|
||||||
|
}}
|
||||||
className={`flex items-center justify-between rounded-sm px-2 py-1.5 text-[11px] transition-colors ${loc === locale ? "text-white" : "text-white/90"} focus:bg-white/10 focus:text-white ${styles.electronNoDrag}`}
|
className={`flex items-center justify-between rounded-sm px-2 py-1.5 text-[11px] transition-colors ${loc === locale ? "text-white" : "text-white/90"} focus:bg-white/10 focus:text-white ${styles.electronNoDrag}`}
|
||||||
>
|
>
|
||||||
<span className="truncate">{getLocaleName(loc)}</span>
|
<span className="truncate">{getLocaleName(loc)}</span>
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ interface I18nContextValue {
|
|||||||
systemLocaleSuggestion: Locale | null;
|
systemLocaleSuggestion: Locale | null;
|
||||||
acceptSystemLocaleSuggestion: () => void;
|
acceptSystemLocaleSuggestion: () => void;
|
||||||
dismissSystemLocaleSuggestion: () => void;
|
dismissSystemLocaleSuggestion: () => void;
|
||||||
|
resolveSystemLocaleSuggestion: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SYSTEM_LANGUAGE_PROMPT_SEEN_KEY = "openscreen-system-language-prompt-seen";
|
const SYSTEM_LANGUAGE_PROMPT_SEEN_KEY = "openscreen-system-language-prompt-seen";
|
||||||
@@ -152,12 +153,11 @@ export function I18nProvider({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
const dismissSystemLocaleSuggestion = useCallback(() => {
|
const dismissSystemLocaleSuggestion = useCallback(() => {
|
||||||
setSystemLocaleSuggestion(null);
|
setSystemLocaleSuggestion(null);
|
||||||
try {
|
markPromptAsHandled();
|
||||||
// Persisting default locale avoids showing this prompt again.
|
}, [markPromptAsHandled]);
|
||||||
localStorage.setItem(LOCALE_STORAGE_KEY, DEFAULT_LOCALE);
|
|
||||||
} catch {
|
const resolveSystemLocaleSuggestion = useCallback(() => {
|
||||||
// localStorage may be unavailable
|
setSystemLocaleSuggestion(null);
|
||||||
}
|
|
||||||
markPromptAsHandled();
|
markPromptAsHandled();
|
||||||
}, [markPromptAsHandled]);
|
}, [markPromptAsHandled]);
|
||||||
|
|
||||||
@@ -180,6 +180,7 @@ export function I18nProvider({ children }: { children: ReactNode }) {
|
|||||||
systemLocaleSuggestion,
|
systemLocaleSuggestion,
|
||||||
acceptSystemLocaleSuggestion,
|
acceptSystemLocaleSuggestion,
|
||||||
dismissSystemLocaleSuggestion,
|
dismissSystemLocaleSuggestion,
|
||||||
|
resolveSystemLocaleSuggestion,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
locale,
|
locale,
|
||||||
@@ -188,6 +189,7 @@ export function I18nProvider({ children }: { children: ReactNode }) {
|
|||||||
systemLocaleSuggestion,
|
systemLocaleSuggestion,
|
||||||
acceptSystemLocaleSuggestion,
|
acceptSystemLocaleSuggestion,
|
||||||
dismissSystemLocaleSuggestion,
|
dismissSystemLocaleSuggestion,
|
||||||
|
resolveSystemLocaleSuggestion,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user