|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.tridas.io.I18n
public class I18n
Provide localization strings.
Java's ResourceBundles are intended to do this, but they don't provide the level of support that most other libraries do.
For example, suppose you have a "Copy" menuitem.
JMenuItem copy = new JMenuItem("Copy");Of course, you should internationalize this. But you want to change the text, the mnemonic, and the keyboard accelerator. If you only had ResourceBundle to work with, you might end up with 3 lines of translation for every word in your program. Plus, you'd have to know the name of the I18n file you used, each time you wanted to use it. Most other libraries (like Powerplant on Mac and Win95 resources) let you put them all in one line, which makes the translator's job much easier. That's what this class does.
Now, all you have to say is:
copy = &Copy [accel C]
There are several things going on here:
KeyStroke.getKeyStroke(I18n.getKeyStroke("copy"))to get a Swing KeyStroke object.
This is convenient, but it gets even better: normally, you don't even have to mess with keystrokes and mnemonics. You can simply use the Builder factory to do the dirty work for you:
JMenuItem copy = Builder.makeMenuItem("copy");Of course, if you just want the text (for making a printout, for example), you should still use I18n.getText().
Not all keys must have a keystroke, or a mnemonic. Note that those methods can return nulls.
These methods get their values from the resource bundle called "TextBundle". That is, the file is called "TextBundle.properties", or some variant, like "TextBundle_de_DE.properties".
ResourceBundle
Method Summary | |
---|---|
static KeyStroke |
getKeyStroke(String key)
Get the keystroke string for this key. |
static Integer |
getMnemonic(String key)
Get the mnemonic character this key. |
static Integer |
getMnemonicPosition(String key)
Get the position of the mnemonic character in the string Used for setDisplayedMnemonicIndex |
static String |
getText(String key)
Get the text for this key. |
static String |
getText(String key,
ArrayList<String> replace)
Look up translation key, and return with each {0} style placeholder replaced with item in array |
static String |
getText(String argKey,
String... argReplacing)
Created by Daniel, easier way of using an arbitrary number of replacing strings. |
static String |
getText(String key,
String replace)
Look up translation key, and replace {0} with the second parameter |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String getText(String key)
For example, if the localization file has the line
copy = &Copy [accel C]
, the string "Copy" is returned.
key
- the key to look up in the localization file
public static String getText(String key, ArrayList<String> replace)
key
- replace
-
public static String getText(String argKey, String... argReplacing)
argKey
- argReplacing
-
public static String getText(String key, String replace)
key
- replace
-
public static KeyStroke getKeyStroke(String key)
For example, if the localization file has the line
copy = &Copy [accel C]
, the string "control C" is returned (or on
the Mac, "meta C").
If the string has no [keystroke] listed, null is returned.
key
- the key to look up in the localization file
public static Integer getMnemonic(String key)
For example, if the localization file has the line
copy = &Copy [accel C]
, the character "C" is returned.
If the string has no &mnemonic listed, null is returned.
key
- the key to look up in the localization file
public static Integer getMnemonicPosition(String key)
key
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |