From 13a6cb55f8b89beed55077454eafed3d211ac2c3 Mon Sep 17 00:00:00 2001 From: Vera Petrenkova Date: Mon, 7 Oct 2024 13:49:31 +0200 Subject: [PATCH] IJPL-163439 Synchronize localization settings from the registry at app closing GitOrigin-RevId: c5d6d60e2081f1b9cc9b55bcdb1990e0b0181680 --- .../intellij/ide/LanguageBundleListener.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/LanguageBundleListener.kt b/platform/platform-impl/src/com/intellij/ide/LanguageBundleListener.kt index c0961893540b..0bdc399aa77b 100644 --- a/platform/platform-impl/src/com/intellij/ide/LanguageBundleListener.kt +++ b/platform/platform-impl/src/com/intellij/ide/LanguageBundleListener.kt @@ -3,8 +3,13 @@ package com.intellij.ide import com.intellij.DynamicBundle import com.intellij.l10n.LocalizationStateService +import com.intellij.l10n.LocalizationUtil +import com.intellij.openapi.application.PathManager import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.openapi.util.registry.EarlyAccessRegistryManager import com.intellij.util.text.DateTimeFormatManager +import java.nio.file.Files +import java.nio.file.NoSuchFileException private class LanguageBundleListener : AppLifecycleListener { override fun appStarted() { @@ -12,7 +17,37 @@ private class LanguageBundleListener : AppLifecycleListener { (it as PersistentStateComponent<*>).initializeComponent() it.resetLocaleIfNeeded() } + EarlyAccessRegistryManager.syncAndFlush() DynamicBundle.clearCache() DateTimeFormatManager.getInstance().resetFormats() } + + + /** + * Reads the early access registry file and updates the registry settings related to localization. + * This ensures that any changes made externally (e.g., via Toolbox) to the localization settings are accurately reflected. + * */ + override fun appClosing() { + val earlyAccessRegistryFile = PathManager.getConfigDir().resolve(EarlyAccessRegistryManager.fileName) + val lines = try { + Files.lines(earlyAccessRegistryFile) + } + catch (_: NoSuchFileException) { + return + } + lines.use { lineStream -> + val iterator = lineStream.iterator() + while (iterator.hasNext()) { + val key = iterator.next() + if (!iterator.hasNext()) { + break + } + val value = iterator.next() + if (key == LocalizationUtil.LOCALIZATION_KEY) { + EarlyAccessRegistryManager.setString(LocalizationUtil.LOCALIZATION_KEY, value) + break + } + } + } + } }