Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
summ: You, and $\{otherCount\} others, reviewed '$\{title\}' and rated it $\{rate\}.

MyPanel.html:

Code Block
<span wicket:id="summary">Text that will be replaced.</span>

...

Code Block
summ.short: Thanks!
summ.long: You, and $\{otherCount\} others, reviewed '$\{title\}' and rated it $\{rate\}. Thanks!

MyPanel.html:

Code Block
<span wicket:id="summary">Text that will be replaced.</span>

...

Code Block
// summary.getMsgPrefs().getStyle() returns "short" or "long"
add(new Label("summary", new StringResourceModel("summ.$\{msgPrefs.style\}", this, new Model(summary))));

...

Code Block
add(new Label("summary", getString("summ.$\{msgPrefs.style\}", new Model(summary))));.${msgPrefs.style}", new Model(summary))));

Putting wicket components into the message

If you want to translate a components text containing additional Wicket components (e.g. Links) you can use wicket:message-tag in combination with a container around it. Example a form component label related to a checkbox (label for) containing a link:

Java:

Code Block

final FormComponentLabel termsAndConditionsCheckLabel = new FormComponentLabel("termsAndConditionsCheckLabel", acceptedTerms);
form.add(termsAndConditionsCheckLabel);

final Link terms = new Link("terms") {
  @Override
  public void onClick() {
    setResponsePage(TermsOfUsePage.class);
  }
};
termsAndConditionsCheckLabel.add(terms);

final Label termsOfUse = new Label("terms_of_use", new ResourceModel("terms_of_use"));
termsOfUse.setRenderBodyOnly(true);
terms.add(termsOfUse);

Markup (HTML):

Code Block

<label wicket:id="termsAndConditionsCheckLabel">
  <wicket:message key="termsAndConditionsCheckLabel">I am 18 years old and agree with the <a href="#" wicket:id="terms"><span wicket:id="terms_of_use">terms of use</span></a> and conditions.</wicket:message>
</label>

Messages (in ....properties.xml):

Code Block

<entry key="termsAndConditionsCheckLabel">I am 18 years old and agree with the ${terms_of_use} and conditions.</entry>
<entry key="terms_of_use">Terms of Use</entry>

The trouble with property files

...

Code Block
summ: You, and $\{othersLink\}, reviewed $\{titleLink\} and rated it $\{rate\}.
others: $\{otherCount\} others

MyPanel.html:

Code Block
<wicket:message key="summ">Text that will be replaced.
<span wicket:id="rate">rate</span>
<a href="#" wicket:id="titleLink">
<span wicket:id="titleLabel">label</span></a>
<a href="#" wicket:id="othersLink">
<span wicket:id="othersLabel">label<</span></a>
</wicket:message>

...

Code Block
// Note, we directly add the embedded components
// rate, othersLink and titleLink

add(new Label("rate", new PropertyModel(summary, "rate")));

Link othLink = new Link("othersLink") \{ .... \}
add(othLink);
othLink.add(new Label("othersLabel", new StringResourceModel(
"others", this, new Model(summary))));

ExternalLink titleLink = new ExternalLink(
"titleLink", summary.getTitleUrl());
add(titleLink);
titleLink.add(new Label("titleLabel",
new PropertyModel(summary, "title")));

...

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="Required">ข้อมูลใน $\{label\} เป็นที่ต้องการ.</entry>
</properties>

...