author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 42338 | a60f280f803c |
permissions | -rw-r--r-- |
19795
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
1 |
/* |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
4 |
* |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
8 |
* |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
14 |
* |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
18 |
* |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
22 |
*/ |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
23 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
24 |
import java.util.*; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
25 |
import java.util.logging.*; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
26 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
27 |
/* |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
28 |
* @test |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
29 |
* @bug 8016127 8024131 |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
30 |
* @summary test logging.properties localized |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36511
diff
changeset
|
31 |
* @modules java.logging/sun.util.logging.resources:open |
19795
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
32 |
* @run main/othervm LocalizedLevelName |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
33 |
*/ |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
34 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
35 |
public class LocalizedLevelName { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
36 |
private static Object[] namesMap = { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
37 |
"SEVERE", Locale.ENGLISH, "Severe", Level.SEVERE, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
38 |
"WARNING", Locale.FRENCH, "Avertissement", Level.WARNING, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
39 |
"INFO", Locale.ITALIAN, "Informazioni", Level.INFO, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
40 |
"SEVERE", Locale.FRENCH, "Grave", Level.SEVERE, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
41 |
"CONFIG", Locale.GERMAN, "Konfiguration", Level.CONFIG, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
42 |
"ALL", Locale.ROOT, "All", Level.ALL, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
43 |
"SEVERE", Locale.ROOT, "Severe", Level.SEVERE, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
44 |
"WARNING", Locale.ROOT, "Warning", Level.WARNING, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
45 |
"CONFIG", Locale.ROOT, "Config", Level.CONFIG, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
46 |
"INFO", Locale.ROOT, "Info", Level.INFO, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
47 |
"FINE", Locale.ROOT, "Fine", Level.FINE, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
48 |
"FINER", Locale.ROOT, "Finer", Level.FINER, |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
49 |
"FINEST", Locale.ROOT, "Finest", Level.FINEST |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
50 |
}; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
51 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
52 |
public static void main(String args[]) throws Exception { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
53 |
Locale defaultLocale = Locale.getDefault(); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
54 |
for (int i=0; i<namesMap.length; i += 4) { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
55 |
final String key = (String) namesMap[i]; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
56 |
final Locale locale = (Locale) namesMap[i+1]; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
57 |
final String expectedTranslation = (String) namesMap[i+2]; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
58 |
final Level level = (Level) namesMap[i+3]; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
59 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
60 |
final String en = getLocalizedMessage(Locale.ENGLISH, key); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
61 |
final String other = getLocalizedMessage(locale, key); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
62 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
63 |
System.out.println(locale + ": " + key + "=" + expectedTranslation |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
64 |
+ ", (Level." + level.getName() + ")"); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
65 |
System.out.println(" => localized(" + Locale.ENGLISH + ", " |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
66 |
+ key + ")=" + en); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
67 |
System.out.println(" => localized(" + locale + ", " + key |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
68 |
+ ")=" + other); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
69 |
if (!key.equals(en.toUpperCase(Locale.ROOT))) { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
70 |
throw new RuntimeException("Expect " + key |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
71 |
+ " equals upperCase(" + en + ")"); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
72 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
73 |
if (!Locale.ENGLISH.equals(locale) && !Locale.ROOT.equals(locale) |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
74 |
&& key.equals(other.toUpperCase(Locale.ROOT))) { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
75 |
throw new RuntimeException("Expect " + key |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
76 |
+ " not equals upperCase(" + other +")"); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
77 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
78 |
if ((Locale.ENGLISH.equals(locale) || Locale.ROOT.equals(locale)) |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
79 |
&& !key.equals(other.toUpperCase(Locale.ROOT))) { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
80 |
throw new RuntimeException("Expect " + key |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
81 |
+ " equals upperCase(" + other +")"); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
82 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
83 |
if (!other.equals(expectedTranslation)) { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
84 |
throw new RuntimeException("Expected \"" + expectedTranslation |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
85 |
+ "\" for '" + locale + "' but got \"" + other + "\""); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
86 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
87 |
Locale.setDefault(locale); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
88 |
final String levelName = level.getLocalizedName(); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
89 |
System.out.println("Level.getLocalizedName() is: " + levelName); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
90 |
if (!levelName.equals(other.toUpperCase(locale))) { |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
91 |
throw new RuntimeException("Expected \"" |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
92 |
+ other.toUpperCase(locale) + "\" for '" |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
93 |
+ locale + "' but got \"" + levelName + "\""); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
94 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
95 |
Locale.setDefault(defaultLocale); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
96 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
97 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
98 |
|
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
99 |
private static final String RBNAME = "sun.util.logging.resources.logging"; |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
100 |
private static String getLocalizedMessage(Locale locale, String key) { |
36511 | 101 |
// this test verifies if the logging.properties in the java.logging module |
102 |
// is localized. |
|
103 |
Module module = java.util.logging.Level.class.getModule(); |
|
104 |
ResourceBundle rb = ResourceBundle.getBundle(RBNAME, locale, module); |
|
19795
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
105 |
return rb.getString(key); |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
106 |
} |
6c628e165476
8016127: NLS: logging.properties translatability recommendation
dfuchs
parents:
diff
changeset
|
107 |
} |