Suppose I have a simple code like this:
public class ExternalizeStringDemo {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
Now, I want to externalize the greeting, perhaps to facilitate internationalization/localization/etc. Using Eclipse, I can use the String Externalization wizard (Source/Externalize Strings), and configure it like this:
I can proceed with the wizard and it will propose these changes:
- Create file
Personal Toys/src/Messages.java
- Create file
Personal Toys/src/messages.properties
- Edit
ExternalizeStringDemo.java
"Hello World"
becomesMessages.getString("DEMO_GREETING")
My question is simple: can I ask Eclipse to externalize the access to use the key as field names instead? That is, I want the access to be e.g. Messages.DEMO_GREETING
.
Note: if the [Substitution pattern]
is simple ${key}
, then the generated code is Messages."DEMO_GREETING"
, which is not a valid Java code.
If this is not possible, then what's the next best thing? (I'm thinking Eclipse regex find/replace?).