]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/TranslateCommand.java
add: an non-HTML-encoding mode for templates for e.g. producing emails
[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         String translation = l.getTranslation(raw);
30         if (vars.containsKey(Outputable.OUT_KEY_PLAIN)) {
31             out.print(translation);
32         } else {
33             out.print(HTMLEncoder.encodeHTML(translation));
34         }
35     }
36
37     /**
38      * Gets the raw, untranslated String.
39      * 
40      * @return the raw, untranslated String.
41      */
42     public String getRaw() {
43         return raw;
44     }
45
46     @Override
47     public void addTranslations(Collection<String> s) {
48         s.add(raw);
49     }
50 }