- String[] parts = l.getTranslation(text).split("%s");
- String[] myvars = store.toArray(new String[store.size()]);
- out.print(parts[0]);
- for (int j = 1; j < parts.length; j++) {
- Template.outputVar(out, l, vars, myvars[j - 1].substring(1));
- out.print(parts[j]);
+ String parts = l.getTranslation(text);
+ Matcher m = replacant.matcher(parts);
+ int pos = 0;
+ while (m.find()) {
+ out.print(HTMLEncoder.encodeHTML(parts.substring(pos, m.start())));
+ String var = store[Integer.parseInt(m.group(1))];
+ if (var.startsWith("$!")) {
+ Template.outputVar(out, l, vars, var.substring(3, var.length() - 1), true);
+ } else if (var.startsWith("!'")) {
+ out.print(var.substring(2));
+ } else if (var.startsWith("$")) {
+ Template.outputVar(out, l, vars, var.substring(2, var.length() - 1), false);
+ } else {
+ throw new Error("Processing error in template.");
+ }
+ pos = m.end();
+
+ }
+ out.print(HTMLEncoder.encodeHTML(parts.substring(pos)));
+ }
+
+ @Override
+ public void addTranslations(Collection<String> s) {
+ s.add(text);
+ }
+
+ /**
+ * Creates a simple {@link SprintfCommand} wrapped in a {@link Scope} to fit
+ * in now constant variables into this template.
+ *
+ * @param msg
+ * the message (to be translated) with <code>{0},{1},...</code>
+ * as placeholders.
+ * @param vars
+ * the variables to put into the placeholders.
+ * @return the constructed {@link Outputable}
+ */
+ public static Outputable createSimple(String msg, String... vars) {
+ HashMap<String, Object> scope = new HashMap<>();
+ String[] store = new String[vars.length];
+ for (int i = 0; i < vars.length; i++) {
+ scope.put("autoVar" + i, vars[i]);
+ store[i] = "${autoVar" + i + "}";