mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
Fix display names
X-SVN-Rev: 449
This commit is contained in:
parent
e78b52c1ee
commit
7982010620
4 changed files with 62 additions and 10 deletions
icu4j/src/com/ibm
icu
test/translit
text
|
@ -73,6 +73,14 @@ public class TransliteratorTest extends IntlTest {
|
|||
logln("Elapsed time: " + ms + " ms");
|
||||
}
|
||||
|
||||
public void TestDisplayName() {
|
||||
String ID;
|
||||
for (Enumeration e = Transliterator.getAvailableIDs(); e.hasMoreElements(); ) {
|
||||
ID = (String) e.nextElement();
|
||||
logln(ID + " -> " + Transliterator.getDisplayName(ID));
|
||||
}
|
||||
}
|
||||
|
||||
public void TestSimpleRules() {
|
||||
/* Example: rules 1. ab>x|y
|
||||
* 2. yc>z
|
||||
|
|
|
@ -198,7 +198,7 @@ import java.text.MessageFormat;
|
|||
* <p>Copyright © IBM Corporation 1999. All rights reserved.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.2 $ $Date: 1999/12/20 19:02:27 $
|
||||
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.3 $ $Date: 1999/12/20 20:48:06 $
|
||||
*/
|
||||
public abstract class Transliterator {
|
||||
/**
|
||||
|
@ -285,7 +285,14 @@ public abstract class Transliterator {
|
|||
* transliterator. The ID is appended to this to form the key.
|
||||
* The resource bundle value should be a String.
|
||||
*/
|
||||
private static final String RB_DISPLAY_NAME_PREFIX = "T:";
|
||||
private static final String RB_DISPLAY_NAME_PREFIX = "%Translit%%";
|
||||
|
||||
/**
|
||||
* Prefix for resource bundle key for the display name for a
|
||||
* transliterator SCRIPT. The ID is appended to this to form the key.
|
||||
* The resource bundle value should be a String.
|
||||
*/
|
||||
private static final String RB_SCRIPT_DISPLAY_NAME_PREFIX = "%Translit%";
|
||||
|
||||
/**
|
||||
* Resource bundle key for display name pattern.
|
||||
|
@ -616,8 +623,8 @@ public abstract class Transliterator {
|
|||
* display to the user in the default locale. See {@link
|
||||
* #getDisplayName(Locale)} for details.
|
||||
*/
|
||||
public final String getDisplayName() {
|
||||
return getDisplayName(Locale.getDefault());
|
||||
public final static String getDisplayName(String ID) {
|
||||
return getDisplayName(ID, Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -638,10 +645,12 @@ public abstract class Transliterator {
|
|||
* localized.
|
||||
* @see java.text.MessageFormat
|
||||
*/
|
||||
public String getDisplayName(Locale inLocale) {
|
||||
public static String getDisplayName(String ID, Locale inLocale) {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(
|
||||
RB_LOCALE_ELEMENTS, inLocale);
|
||||
|
||||
// Use display name for the entire transliterator, if it
|
||||
// exists.
|
||||
try {
|
||||
return bundle.getString(RB_DISPLAY_NAME_PREFIX + ID);
|
||||
} catch (MissingResourceException e) {}
|
||||
|
@ -657,6 +666,15 @@ public abstract class Transliterator {
|
|||
? new Object[] { new Integer(1), ID }
|
||||
: new Object[] { new Integer(2), ID.substring(0, i),
|
||||
ID.substring(i+1) };
|
||||
|
||||
// Use display names for the scripts, if they exist
|
||||
for (int j=1; j<=((i<0)?1:2); ++j) {
|
||||
try {
|
||||
args[j] = bundle.getString(RB_SCRIPT_DISPLAY_NAME_PREFIX +
|
||||
(String) args[j]);
|
||||
} catch (MissingResourceException e) {}
|
||||
}
|
||||
|
||||
// Format it using the pattern in the resource
|
||||
return format.format(args);
|
||||
} catch (MissingResourceException e2) {}
|
||||
|
|
|
@ -73,6 +73,14 @@ public class TransliteratorTest extends IntlTest {
|
|||
logln("Elapsed time: " + ms + " ms");
|
||||
}
|
||||
|
||||
public void TestDisplayName() {
|
||||
String ID;
|
||||
for (Enumeration e = Transliterator.getAvailableIDs(); e.hasMoreElements(); ) {
|
||||
ID = (String) e.nextElement();
|
||||
logln(ID + " -> " + Transliterator.getDisplayName(ID));
|
||||
}
|
||||
}
|
||||
|
||||
public void TestSimpleRules() {
|
||||
/* Example: rules 1. ab>x|y
|
||||
* 2. yc>z
|
||||
|
|
|
@ -198,7 +198,7 @@ import java.text.MessageFormat;
|
|||
* <p>Copyright © IBM Corporation 1999. All rights reserved.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.2 $ $Date: 1999/12/20 19:02:27 $
|
||||
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.3 $ $Date: 1999/12/20 20:48:06 $
|
||||
*/
|
||||
public abstract class Transliterator {
|
||||
/**
|
||||
|
@ -285,7 +285,14 @@ public abstract class Transliterator {
|
|||
* transliterator. The ID is appended to this to form the key.
|
||||
* The resource bundle value should be a String.
|
||||
*/
|
||||
private static final String RB_DISPLAY_NAME_PREFIX = "T:";
|
||||
private static final String RB_DISPLAY_NAME_PREFIX = "%Translit%%";
|
||||
|
||||
/**
|
||||
* Prefix for resource bundle key for the display name for a
|
||||
* transliterator SCRIPT. The ID is appended to this to form the key.
|
||||
* The resource bundle value should be a String.
|
||||
*/
|
||||
private static final String RB_SCRIPT_DISPLAY_NAME_PREFIX = "%Translit%";
|
||||
|
||||
/**
|
||||
* Resource bundle key for display name pattern.
|
||||
|
@ -616,8 +623,8 @@ public abstract class Transliterator {
|
|||
* display to the user in the default locale. See {@link
|
||||
* #getDisplayName(Locale)} for details.
|
||||
*/
|
||||
public final String getDisplayName() {
|
||||
return getDisplayName(Locale.getDefault());
|
||||
public final static String getDisplayName(String ID) {
|
||||
return getDisplayName(ID, Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -638,10 +645,12 @@ public abstract class Transliterator {
|
|||
* localized.
|
||||
* @see java.text.MessageFormat
|
||||
*/
|
||||
public String getDisplayName(Locale inLocale) {
|
||||
public static String getDisplayName(String ID, Locale inLocale) {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(
|
||||
RB_LOCALE_ELEMENTS, inLocale);
|
||||
|
||||
// Use display name for the entire transliterator, if it
|
||||
// exists.
|
||||
try {
|
||||
return bundle.getString(RB_DISPLAY_NAME_PREFIX + ID);
|
||||
} catch (MissingResourceException e) {}
|
||||
|
@ -657,6 +666,15 @@ public abstract class Transliterator {
|
|||
? new Object[] { new Integer(1), ID }
|
||||
: new Object[] { new Integer(2), ID.substring(0, i),
|
||||
ID.substring(i+1) };
|
||||
|
||||
// Use display names for the scripts, if they exist
|
||||
for (int j=1; j<=((i<0)?1:2); ++j) {
|
||||
try {
|
||||
args[j] = bundle.getString(RB_SCRIPT_DISPLAY_NAME_PREFIX +
|
||||
(String) args[j]);
|
||||
} catch (MissingResourceException e) {}
|
||||
}
|
||||
|
||||
// Format it using the pattern in the resource
|
||||
return format.format(args);
|
||||
} catch (MissingResourceException e2) {}
|
||||
|
|
Loading…
Add table
Reference in a new issue