]> WPIA git - gigi.git/blobdiff - 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
index 7b7014e0775feb537428ed1e2c41af8222072d5c..6532d94682e7cbff6cb100788106b9f5f56293d1 100644 (file)
@@ -1,25 +1,50 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.HTMLEncoder;
 
-public final class TranslateCommand implements Outputable {
+/**
+ * Wraps a String that needs to be translated before it is printed to the user.
+ */
+public final class TranslateCommand implements Translatable {
 
     private final String raw;
 
+    /**
+     * Creates a new TranslateCommand that wraps the given String.
+     * 
+     * @param raw
+     *            the String to be translated.
+     */
     public TranslateCommand(String raw) {
         this.raw = raw;
     }
 
     @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-        out.print(HTMLEncoder.encodeHTML(l.getTranslation(raw)));
+        String translation = l.getTranslation(raw);
+        if (vars.containsKey(Outputable.OUT_KEY_PLAIN)) {
+            out.print(translation);
+        } else {
+            out.print(HTMLEncoder.encodeHTML(translation));
+        }
     }
 
+    /**
+     * Gets the raw, untranslated String.
+     * 
+     * @return the raw, untranslated String.
+     */
     public String getRaw() {
         return raw;
     }
+
+    @Override
+    public void addTranslations(Collection<String> s) {
+        s.add(raw);
+    }
 }