]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/TranslateCommand.java
d291e9d414b3d4ce0111b3edf1c1ff85963b9294
[gigi.git] / src / org / cacert / gigi / output / template / TranslateCommand.java
1 package org.cacert.gigi.output.template;
2
3 import java.io.PrintWriter;
4 import java.util.Collection;
5 import java.util.Map;
6
7 import org.cacert.gigi.localisation.Language;
8 import org.cacert.gigi.util.HTMLEncoder;
9
10 /**
11  * Wraps a String that needs to be translated before it is printed to the user.
12  */
13 public final class TranslateCommand implements Translatable {
14
15     private final String raw;
16
17     /**
18      * Creates a new TranslateCommand that wraps the given String.
19      * 
20      * @param raw
21      *            the String to be translated.
22      */
23     public TranslateCommand(String raw) {
24         this.raw = raw;
25     }
26
27     @Override
28     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
29         out.print(HTMLEncoder.encodeHTML(l.getTranslation(raw)));
30     }
31
32     /**
33      * Gets the raw, untranslated String.
34      * 
35      * @return the raw, untranslated String.
36      */
37     public String getRaw() {
38         return raw;
39     }
40
41     @Override
42     public void addTranslations(Collection<String> s) {
43         s.add(raw);
44     }
45 }