Tum
Tum

Reputation: 3652

Can a Key String in properties file become a variable in another Key String (GWT)?

in Gwt, we can set message constants at properties file like this

passWordErr={0} must contain Upper case
passWordBox=Please enter {0} Here. {0} must contain Upper case

in the interface MyMessages, we have:

public interface MyMessages extends Messages{
    String passWordErr (String field);
    String passWordBox (String field);
}

As you can see, in the properties file we got the duplicated text "{0} must contain Upper case". So if we change it, we need to change in 2 places & that is not good.

So my question is:

Can a Key String in properties file become a variable in another Key String (GWT)?

Something like this:

passWordErr={0} must contain Upper case
passWordBox=Please enter {0} Here. + passWordErr({0})

Upvotes: 1

Views: 76

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

No, you cannot do that. More importantly, there is no need to do that.

In your example, instead of

passWordErr={0} must contain upper case
passWordBox=Please enter {0} here. {0} must contain Upper case

it should be

passWordErr={0} must contain upper case.
passWordBox=Please enter {0} here.

Then, when you need to show a message, you can simply concatenate both messages:

Window.alert(myMessages.passWordBox("password") + " " + myMessages.passWordErr("password"));

Upvotes: 2

Related Questions