mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
IJPL-149871 i18n: find action in English is not working enabled language pack
GitOrigin-RevId: 1b107c7a9f73a9a48296f65c4aa514936de2c844
This commit is contained in:
committed by
intellij-monorepo-bot
parent
104835460b
commit
4aa7921eca
@@ -273,10 +273,20 @@ public class DynamicBundle extends AbstractBundle {
|
||||
return classLoader != null && baseName != null ? getResourceBundle(classLoader, baseName) : null;
|
||||
}
|
||||
|
||||
private static @NotNull ResourceBundle resolveResourceBundle(@NotNull ClassLoader loader, @NonNls @NotNull String pathToBundle, @NotNull Locale locale) {
|
||||
return Companion.resolveResourceBundleWithFallback(loader, pathToBundle, () -> resolveResourceBundle(DynamicBundle.class.getClassLoader(),
|
||||
loader, pathToBundle, locale,
|
||||
bundleResolver(pathToBundle)));
|
||||
private static @NotNull ResourceBundle resolveResourceBundle(
|
||||
@NotNull ClassLoader loader,
|
||||
@NonNls @NotNull String pathToBundle,
|
||||
@NotNull Locale locale
|
||||
) {
|
||||
return Companion.resolveResourceBundleWithFallback(loader, pathToBundle, () -> {
|
||||
return resolveResourceBundle(
|
||||
DynamicBundle.class.getClassLoader(),
|
||||
loader,
|
||||
pathToBundle,
|
||||
locale,
|
||||
bundleResolver(pathToBundle)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private static @NotNull BiFunction<@NotNull ClassLoader, @NotNull Locale, @NotNull ResourceBundle> bundleResolver(@NonNls @NotNull String pathToBundle) {
|
||||
@@ -327,9 +337,7 @@ public class DynamicBundle extends AbstractBundle {
|
||||
private static @NotNull Locale getResolveLocale() {
|
||||
Locale resolveLocale = getLocale();
|
||||
// we must use Locale.ROOT to get English messages from default bundles
|
||||
if (resolveLocale.equals(Locale.ENGLISH)) return Locale.ROOT;
|
||||
|
||||
return resolveLocale;
|
||||
return resolveLocale.equals(Locale.ENGLISH) ? Locale.ROOT : resolveLocale;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
||||
@@ -53,21 +53,14 @@ object LocalizationUtil {
|
||||
|
||||
fun getLocaleOrNullForDefault(): Locale? {
|
||||
val locale = getLocale()
|
||||
if (Locale.ENGLISH.language == locale.language) {
|
||||
return null
|
||||
}
|
||||
return locale
|
||||
return if (locale.language == Locale.ENGLISH.language) null else locale
|
||||
}
|
||||
|
||||
@Internal
|
||||
@JvmOverloads
|
||||
fun getPluginClassLoader(defaultLoader: ClassLoader? = null): ClassLoader? {
|
||||
val langBundle = findLanguageBundle()
|
||||
if (langBundle == null) {
|
||||
return null
|
||||
}
|
||||
val pluginDescriptor = langBundle.pluginDescriptor
|
||||
return pluginDescriptor?.classLoader ?: defaultLoader
|
||||
val langBundle = findLanguageBundle() ?: return null
|
||||
return langBundle.pluginDescriptor?.classLoader ?: defaultLoader
|
||||
}
|
||||
|
||||
private fun Path.convertToLocalizationFolderUsage(locale: Locale, withRegion: Boolean): Path {
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
package com.intellij.ide.ui.search
|
||||
|
||||
import com.intellij.DynamicBundle
|
||||
import com.intellij.IntelliJResourceBundle
|
||||
import com.intellij._doResolveBundle
|
||||
import com.intellij.ide.plugins.PluginManagerCore.getPluginSet
|
||||
import com.intellij.ide.ui.search.SearchableOptionsRegistrar.AdditionalLocationProvider
|
||||
import com.intellij.l10n.LocalizationUtil
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.util.ArrayUtil
|
||||
@@ -29,6 +31,9 @@ import java.nio.file.Files
|
||||
import java.util.*
|
||||
import java.util.concurrent.CancellationException
|
||||
import java.util.function.Predicate
|
||||
import java.util.stream.Stream
|
||||
|
||||
private val LOG = logger<MySearchableOptionProcessor>()
|
||||
|
||||
internal class MySearchableOptionProcessor(private val stopWords: Set<String>) : SearchableOptionProcessor() {
|
||||
private val cache = HashSet<String>()
|
||||
@@ -136,12 +141,18 @@ private fun getMessageByCoordinate(s: String, classLoader: ClassLoader, locale:
|
||||
val bundlePath = groups[1]!!.value
|
||||
val messageKey = groups[2]!!.value
|
||||
val bundle = try {
|
||||
_doResolveBundle(loader = classLoader, locale = locale, pathToBundle = bundlePath) as IntelliJResourceBundle
|
||||
_doResolveBundle(loader = classLoader, locale = locale, pathToBundle = bundlePath)
|
||||
}
|
||||
catch (_: MissingResourceException) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (bundle !is IntelliJResourceBundle) {
|
||||
// todo we should fix resolveResourceBundleWithFallback and do not try to load bundle if we cannot find it in localization plugin
|
||||
LOG.debug { "Unexpected bundle type due to fallback: ${bundle.javaClass.name}" }
|
||||
continue
|
||||
}
|
||||
|
||||
val resolvedMessage = bundle.getMessageOrNull(messageKey) ?: continue
|
||||
result.append(resolvedMessage)
|
||||
}
|
||||
@@ -162,21 +173,17 @@ private fun processSearchableOptions(processor: MySearchableOptionProcessor) {
|
||||
val fileName = "$classifier-${SearchableOptionsRegistrar.SEARCHABLE_OPTIONS_XML_NAME}.json"
|
||||
val data = classLoader.getResourceAsBytes(fileName, false)
|
||||
if (data != null) {
|
||||
val locale = DynamicBundle.getLocale()
|
||||
val locale = LocalizationUtil.getLocaleOrNullForDefault()
|
||||
val localeSpecificLoader = LocalizationUtil.getPluginClassLoader()
|
||||
try {
|
||||
for (item in decodeFromJsonFormat(data, serializer)) {
|
||||
for (entry in item.entries) {
|
||||
val resolvedHit = getMessageByCoordinate(entry.hit, classLoader, locale).lowercase(locale)
|
||||
processor.putOptionWithHelpId(
|
||||
words = Iterable {
|
||||
SearchableOptionsRegistrarImpl.splitToWordsWithoutStemmingAndStopWords(resolvedHit).iterator()
|
||||
},
|
||||
id = getMessageByCoordinate(item.id, classLoader, locale),
|
||||
groupName = getMessageByCoordinate(item.name, classLoader, locale),
|
||||
hit = getMessageByCoordinate(entry.hit, classLoader, locale),
|
||||
path = entry.path?.let { getMessageByCoordinate(it, classLoader, locale) },
|
||||
)
|
||||
}
|
||||
doRegisterIndex(
|
||||
item = item,
|
||||
classLoader = classLoader,
|
||||
locale = locale,
|
||||
processor = processor,
|
||||
localeSpecificLoader = localeSpecificLoader,
|
||||
)
|
||||
}
|
||||
}
|
||||
catch (e: CancellationException) {
|
||||
@@ -228,6 +235,35 @@ private fun processSearchableOptions(processor: MySearchableOptionProcessor) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun doRegisterIndex(
|
||||
item: ConfigurableEntry,
|
||||
classLoader: ClassLoader,
|
||||
locale: Locale?,
|
||||
processor: MySearchableOptionProcessor,
|
||||
localeSpecificLoader: ClassLoader?,
|
||||
) {
|
||||
for (entry in item.entries) {
|
||||
processor.putOptionWithHelpId(
|
||||
words = Iterable {
|
||||
val h1 = getMessageByCoordinate(entry.hit, classLoader, Locale.ROOT).lowercase(Locale.ROOT)
|
||||
val s1 = SearchableOptionsRegistrarImpl.splitToWordsWithoutStemmingAndStopWords(h1)
|
||||
if (locale == null) {
|
||||
s1.iterator()
|
||||
}
|
||||
else {
|
||||
val h2 = getMessageByCoordinate(entry.hit, localeSpecificLoader!!, locale).lowercase(locale)
|
||||
val s2 = SearchableOptionsRegistrarImpl.splitToWordsWithoutStemmingAndStopWords(h2)
|
||||
Stream.concat(s2, s1).iterator()
|
||||
}
|
||||
},
|
||||
id = getMessageByCoordinate(item.id, localeSpecificLoader ?: classLoader, locale ?: Locale.ROOT),
|
||||
groupName = getMessageByCoordinate(item.name, localeSpecificLoader ?: classLoader, locale ?: Locale.ROOT),
|
||||
hit = getMessageByCoordinate(entry.hit, localeSpecificLoader ?: classLoader, locale ?: Locale.ROOT),
|
||||
path = entry.path?.let { getMessageByCoordinate(it, localeSpecificLoader ?: classLoader, locale ?: Locale.ROOT) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Internal
|
||||
@VisibleForTesting
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
|
||||
@@ -71,7 +71,7 @@ open class AbstractBundle {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
inline fun resolveResourceBundleWithFallback(
|
||||
fun resolveResourceBundleWithFallback(
|
||||
loader: ClassLoader,
|
||||
pathToBundle: String,
|
||||
firstTry: () -> ResourceBundle,
|
||||
@@ -139,7 +139,9 @@ open class AbstractBundle {
|
||||
val isDefault = DefaultBundleService.isDefaultBundle()
|
||||
var bundle = getBundle(isDefault)
|
||||
if (bundle == null) {
|
||||
bundle = resolveResourceBundle(pathToBundle, classLoader)
|
||||
bundle = resolveResourceBundleWithFallback(loader = classLoader, pathToBundle = pathToBundle) {
|
||||
findBundle(pathToBundle = pathToBundle, loader = classLoader, control = IntelliJResourceControl)
|
||||
}
|
||||
val ref = SoftReference(bundle)
|
||||
if (isDefault) {
|
||||
defaultBundle = ref
|
||||
@@ -154,12 +156,6 @@ open class AbstractBundle {
|
||||
@ApiStatus.Internal
|
||||
protected open fun getBundle(isDefault: Boolean): ResourceBundle? = (if (isDefault) defaultBundle else bundle)?.get()
|
||||
|
||||
private fun resolveResourceBundle(pathToBundle: String, loader: ClassLoader): ResourceBundle {
|
||||
return resolveResourceBundleWithFallback(loader = loader, pathToBundle = pathToBundle) {
|
||||
findBundle(pathToBundle = pathToBundle, loader = loader, control = IntelliJResourceControl)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun findBundle(pathToBundle: @NonNls String, loader: ClassLoader, control: ResourceBundle.Control): ResourceBundle {
|
||||
return ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader, control)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user