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

Read message bundles in UTF-8 and fall back to 8859-1 in org.eclipse.osgi.util.NLS #709

Merged
merged 1 commit into from
Dec 10, 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
Expand Up @@ -14,6 +14,8 @@

package org.eclipse.osgi.tests.util;

import static org.junit.Assert.assertEquals;

import org.eclipse.osgi.util.NLS;
import org.junit.Test;

Expand All @@ -24,4 +26,37 @@ public void testEmptyMessageBug200296() {
NLS.bind("", Integer.valueOf(0));
}

@Test
public void testPropertiesLatin1() {
assertEquals("Lorem ipsum dolor sit amet", MessagesLatin1.key_ascii);
assertEquals("ÀÅÆÇÈÊËÌÍÏÐÑÒÓÖ×ØÙÚÜÝÞßàâäåæçèéëìíïðñòõö÷øùúüýþ", MessagesLatin1.key_latin1);
}

@Test
public void testPropertiesUtf8() {
assertEquals("Ḽơᶉëᶆ ȋṕšᶙṁ", MessagesUtf8.key_en);
assertEquals("顾客很高兴", MessagesUtf8.key_ch);
assertEquals("고객은 매우 행복합니다", MessagesUtf8.key_ko);
assertEquals("Клиент очень доволен", MessagesUtf8.key_ru);
}

public static class MessagesLatin1 extends NLS {
public static String key_ascii;
public static String key_latin1;

static {
NLS.initializeMessages("org.eclipse.osgi.tests.util.nls.messages_latin1", MessagesLatin1.class);
}
}

public static class MessagesUtf8 extends NLS {
public static String key_en;
public static String key_ch;
public static String key_ko;
public static String key_ru;

static {
NLS.initializeMessages("org.eclipse.osgi.tests.util.nls.messages_utf8", MessagesUtf8.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
key_ascii=Lorem ipsum dolor sit amet
# This is a comment
key_latin1=ÀÅÆÇÈÊËÌÍÏÐÑÒÓÖ×ØÙÚÜÝÞßàâäåæçèéëìíïðñòõö÷øùúüýþ
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
key_en=Ḽơᶉëᶆ ȋṕšᶙṁ
# This is a comment これはコメントです
key_ch=顾客很高兴
key_ko=고객은 매우 행복합니다
key_ru=Клиент очень доволен
4 changes: 2 additions & 2 deletions bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Export-Package: org.eclipse.core.runtime.adaptor;x-friends:="org.eclipse.core.ru
org.eclipse.osgi.storage.bundlefile;x-internal:=true,
org.eclipse.osgi.storage.url.reference;x-internal:=true,
org.eclipse.osgi.storagemanager;version="1.0",
org.eclipse.osgi.util;version="1.2.0",
tjwatson marked this conversation as resolved.
Show resolved Hide resolved
org.eclipse.osgi.util;version="1.3",
org.osgi.dto;version="1.1.1",
org.osgi.framework;version="1.10",
org.osgi.framework.connect;version="1.0";uses:="org.osgi.framework.launch",
Expand Down Expand Up @@ -107,7 +107,7 @@ Bundle-Activator: org.eclipse.osgi.internal.framework.SystemBundleActivator
Bundle-Description: %systemBundle
Bundle-Copyright: %copyright
Bundle-Vendor: %eclipse.org
Bundle-Version: 3.22.100.qualifier
Bundle-Version: 3.23.0.qualifier
Bundle-Localization: systembundle
Bundle-DocUrl: http://www.eclipse.org
Eclipse-ExtensibleAPI: true
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.22.100-SNAPSHOT</version>
<version>3.23.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<!-- The actual TCKs are executed in the org.eclipse.osgi.tck module because of reference to other service implementations -->
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.supplement
Bundle-Version: 1.11.100.qualifier
Bundle-Version: 1.12.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.equinox.log;version="1.1",
Expand All @@ -17,7 +17,7 @@ Export-Package: org.eclipse.equinox.log;version="1.1",
org.eclipse.osgi.service.runnable;version="1.1",
org.eclipse.osgi.service.urlconversion;version="1.0",
org.eclipse.osgi.storagemanager;version="1.0",
org.eclipse.osgi.util;version="1.1"
org.eclipse.osgi.util;version="1.3"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.osgi.framework,
org.osgi.framework.hooks.resolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.internal.util.SupplementDebug;
Expand Down Expand Up @@ -138,6 +139,16 @@ public static String bind(String message, Object[] bindings) {
* org/eclipse/example/nls/messages_en.properties
* org/eclipse/example/nls/messages.properties
* </pre>
* <p>
* The properties files are read using the default encoding for resource bundles:
* <ul>
* <li>In Java 8, resource files are read using ISO-8859-1 character encoding. Characters outside
* its range must be represented using Unicode escape sequences (e.g., <code>&#92;uXXXX</code>).</li>
* <li>In Java 11 and later, resource files are initially read using UTF-8 character encoding. If a
* resource cannot be successfully read in UTF-8, it will be read from the start in ISO-8859-1
* character encoding.</li>
* </ul>
* </p>
*
* @param baseName the base name of a fully qualified message properties file.
* @param clazz the class where the constants will exist
Expand Down Expand Up @@ -347,7 +358,10 @@ static void load(final String bundleName, Class<?> clazz) {
continue;
try {
final MessagesProperties properties = new MessagesProperties(fields, bundleName, isAccessible);
properties.load(input);
final PropertyResourceBundle bundle = new PropertyResourceBundle(input);
for (String key : bundle.keySet()) {
properties.put(key, bundle.getString(key));
}
} catch (IOException e) {
log(SEVERITY_ERROR, "Error loading " + variant, e); //$NON-NLS-1$
} finally {
Expand Down
Loading