]> 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 377c841bcd04615f1415a263acfdc280840fe81c..6532d94682e7cbff6cb100788106b9f5f56293d1 100644 (file)
@@ -1,20 +1,50 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
-import org.cacert.gigi.Language;
-import org.cacert.gigi.output.Outputable;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.util.HTMLEncoder;
 
-public final class TranslateCommand implements Outputable {
-       private final String raw;
+/**
+ * Wraps a String that needs to be translated before it is printed to the user.
+ */
+public final class TranslateCommand implements Translatable {
 
-       public TranslateCommand(String raw) {
-               this.raw = raw;
-       }
+    private final String raw;
 
-       @Override
-       public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-               out.print(l.getTranslation(raw));
-       }
-}
\ No newline at end of file
+    /**
+     * 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) {
+        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);
+    }
+}