Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] LoggingLocalization performance improvement - backport from master #2171

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,7 @@

import org.junit.Assert;
import org.junit.Test;
import org.eclipse.persistence.internal.localization.EclipseLinkLocalization;
import org.eclipse.persistence.internal.localization.LoggingLocalization;

public class LocalizationTest {
Expand All @@ -27,5 +28,7 @@ public void test() {
"EclipseLink, version: EXAMPLE", LoggingLocalization.buildMessage("topLink_version", new Object[] { "EXAMPLE" }));
Assert.assertEquals("LoggingLocalization.buildMessage could not find the correct translation.",
"message_not_exist (There is no English translation for this message.)", LoggingLocalization.buildMessage("message_not_exist"));
Assert.assertEquals("EclipseLinkLocalization.buildMessage could not find the correct translation.",
"somekey1 (There is no English translation for this message.)", EclipseLinkLocalization.buildMessage("AAAAUnknownClass", "somekey1", null, true));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -29,6 +29,9 @@
*/
public abstract class EclipseLinkLocalization {

// Get the current language's NoTranslationForThisLocale message.
private static final String NO_TRANSLATION_MESSAGE = ResourceBundle.getBundle("org.eclipse.persistence.internal.localization.i18n.EclipseLinkLocalizationResource", Locale.getDefault()).getString("NoTranslationForThisLocale");

/**
* Return the message for the given exception class and error number.
*/
Expand Down Expand Up @@ -60,13 +63,18 @@ public static String buildMessage(String localizationClassName, String key, Obje
} catch (java.util.MissingResourceException mre) {
if (translate) {
// Found bundle, but couldn't find translation.
// Get the current language's NoTranslationForThisLocale message.
bundle = ResourceBundle.getBundle("org.eclipse.persistence.internal.localization.i18n.EclipseLinkLocalizationResource", Locale.getDefault());
String noTranslationMessage = bundle.getString("NoTranslationForThisLocale");
return MessageFormat.format(message, arguments) + noTranslationMessage;
}
// Use the current language's NoTranslationForThisLocale message.
if (arguments == null) {
return message + NO_TRANSLATION_MESSAGE;
} else {
return MessageFormat.format(message, arguments) + NO_TRANSLATION_MESSAGE;
} }
}
if (arguments == null) {
return message;
} else {
return MessageFormat.format(message, arguments);
}
return MessageFormat.format(message, arguments);
}

}
Loading