开发者

removing obsolete keys from messages.properties generated by string externalizing

开发者 https://www.devze.com 2023-01-17 16:10 出处:网络
I am using \"Externalize Strings\" widget of Eclipse. On externalizing strings, a messages.properties file is generated with key value pairs.

I am using "Externalize Strings" widget of Eclipse. On externalizing strings, a messages.properties file is generated with key value pairs.

Say the messages.properties looks like this:

Test_msg1=Add
Test_msg2=Remove
Test_msg3=Include

Say I have a file Test.java with code:

String add = Messages.getString("Test_msg1");
String remove = Messages.getString("Te开发者_开发知识库st_msg2");
String include = Messages.getString("Test_msg3");

Next, if I edit Test.java file and remove the two strings "remove" and "include" then I would want the messages.properties file to be updated such that Test_msg2 and Test_msg3 are removed. Is there a way to do this ? Or do I have to edit messages.properties file manually everytime I delete a string from a huge java file?

Thanks, Sony


When you externalize strings from java file via 'Externalize dialog', you should get a Message.java and message.properties like below,

public class Message extends NLS {
    private static final String BUNDLE_NAME = "com.xxx.ui.internal.Message"; //$NON-NLS-1$
    //Generic Strings:
    public static String Str1;
    public static String Str2;

    static {
    loadMessages();
}
public static void loadMessages() {
    NLS.initializeMessages(BUNDLE_NAME, Message.class);
}
}

Str1=Add
Str2=Remove

If no java code uses the string "Str1", you would find them and remove them via right clicking the Message.java or message.properties, then clicking the context menu item 'source' - 'find broken externalized strings'.

0

精彩评论

暂无评论...
验证码 换一张
取 消