]> WPIA git - gigi.git/commitdiff
Merge "fix: pootle does not like translations in line number 0"
authorBenny Baumann <BenBE1987@gmx.net>
Fri, 10 Jun 2016 15:39:46 +0000 (17:39 +0200)
committerGerrit Code Review <gigi-system@dogcraft.de>
Fri, 10 Jun 2016 15:39:46 +0000 (17:39 +0200)
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
src/org/cacert/gigi/pages/wot/AssuranceForm.java
src/org/cacert/gigi/util/AuthorizationContext.java
util-testing/org/cacert/gigi/localisation/TranslationCollectingVisitor.java
util-testing/org/cacert/gigi/localisation/TranslationCollector.java

index 1a700961b34345d7ed715761aa6c9d43a8ca50d1..a85952f658d5afacbf89e8c5687e6fb4ad89985a 100644 (file)
@@ -75,7 +75,8 @@ public class SupportUserDetailsForm extends Form {
                 Language l = Language.getInstance(user.getTargetUser().getPreferredLocale());
                 StringBuffer body = new StringBuffer();
                 body.append(l.getTranslation("Hi,") + "\n\n");
-                body.append(l.getTranslation("A password reset was triggered. Please enter the required text sent to you by support on this page: \nhttps://"));
+                body.append(l.getTranslation("A password reset was triggered. Please enter the required text sent to you by support on this page:"));
+                body.append("\n\nhttps://");
                 body.append(ServerConstants.getWwwHostNamePortSecure() + PasswordResetPage.PATH);
                 body.append("?id=");
                 body.append(id);
index 6a9956d5539aee0a85bdb51e23b6ddaf1a3479aa..cf60f75bc0eb8cc7ed322aeed13cfd3d5f03e476 100644 (file)
@@ -153,7 +153,8 @@ public class AssuranceForm extends Form {
                     Language l = Language.getInstance(assuree.getPreferredLocale());
                     StringBuffer body = new StringBuffer();
                     body.append(l.getTranslation("Hi,") + "\n\n");
-                    body.append(l.getTranslation("A password reset was triggered. If you did a password reset by assurance, please enter your secret password using this form: \nhttps://"));
+                    body.append(l.getTranslation("A password reset was triggered. If you did a password reset by assurance, please enter your secret password using this form:"));
+                    body.append("\n\nhttps://");
                     body.append(ServerConstants.getWwwHostNamePortSecure() + PasswordResetPage.PATH);
                     body.append("?id=");
                     body.append(id);
index 6e4bd8bf4c1ec885f51ccf7f7caa661f568e6231..dfd591e41fc0450f463a24b3a3ccd5317f94ca8b 100644 (file)
@@ -1,6 +1,7 @@
 package org.cacert.gigi.util;
 
 import java.io.PrintWriter;
+import java.util.Arrays;
 import java.util.Map;
 
 import org.cacert.gigi.GigiApiException;
@@ -10,6 +11,7 @@ import org.cacert.gigi.dbObjects.Organisation;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.SprintfCommand;
 
 public class AuthorizationContext implements Outputable {
 
@@ -60,21 +62,27 @@ public class AuthorizationContext implements Outputable {
         return getSupporterTicketId() != null && isInGroup(Group.SUPPORTER);
     }
 
+    private static final SprintfCommand sp = new SprintfCommand("Logged in as {0} via {1}.", Arrays.asList("${username}", "${loginMethod}"));
+
+    private static final SprintfCommand inner = new SprintfCommand("{0} (on behalf of {1})", Arrays.asList("${user}", "${target}"));
+
     @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
         out.println("<div>");
-        out.println(l.getTranslation("Logged in as"));
-        out.println(": ");
-
-        if (target != actor) {
-            out.println(((Organisation) target).getName() + " (" + actor.getName().toString() + ")");
-        } else {
-            out.println(actor.getName().toString());
-        }
-
-        out.println(l.getTranslation("with"));
-        ((Outputable) vars.get("loginMethod")).output(out, l, vars);
-        out.println();
+        vars.put("username", new Outputable() {
+
+            @Override
+            public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+                if (target != actor) {
+                    vars.put("user", ((Organisation) target).getName().toString());
+                    vars.put("target", actor.getName().toString());
+                    inner.output(out, l, vars);
+                } else {
+                    out.println(actor.getName().toString());
+                }
+            }
+        });
+        sp.output(out, l, vars);
         out.println("</div>");
         if (supporterTicketId != null) {
             out.println("<div>");
index 472789d8750e147e6dc15022e607cbc3f9ef963a..c52a6d2e0f9fd14b81a995432920d0545e49e8f6 100644 (file)
@@ -1,4 +1,6 @@
 package org.cacert.gigi.localisation;
+import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.Method;
 
 import org.eclipse.jdt.internal.compiler.ASTVisitor;
@@ -123,12 +125,19 @@ public final class TranslationCollectingVisitor extends ASTVisitor {
                                        lineEnds.length - 1);
 
                        String content = new String(((StringLiteral) e).source());
-                       translationCollector.add(
-                                       content,
-                                       new String(unit.compilationResult.fileName)
-                                                       .substring(translationCollector.base
-                                                                       .getAbsolutePath().length() + 1)
-                                                       + ":" + lineNumber);
+                       File f0 = new File(new String(unit.compilationResult.fileName))
+                                       .getAbsoluteFile();
+                       File f2 = translationCollector.base.getAbsoluteFile();
+                       try {
+                               System.out.println(f0.getCanonicalPath());
+                               System.out.println(f2.getCanonicalPath());
+                               translationCollector.add(content, f0.getCanonicalPath()
+                                               .substring(f2.getCanonicalPath().length() + 1)
+                                               + ":"
+                                               + lineNumber);
+                       } catch (IOException e1) {
+                               e1.printStackTrace();
+                       }
                        return;
                }
 
index 2b8ca7e71823e9e4216d0ce6f989f4d16478fdae..25a0e8d5d0292066969d6634f5c90d70ca698804 100644 (file)
@@ -89,6 +89,9 @@ public class TranslationCollector {
        }
 
        public void add(String text, String line) {
+           if(text.contains("\r") || text.contains("\n")){
+               throw new Error("Malformed translation in " + line);
+           }
                TranslationEntry i = translations.get(text);
                if (i == null) {
                        translations.put(text, new TranslationEntry(text, line));
@@ -221,7 +224,7 @@ public class TranslationCollector {
                                add(string,
                                                file.getAbsolutePath().substring(
                                                                base.getAbsolutePath().length() + 1)
-                                                               + ":0");
+                                                               + ":1");
                        }
                }
        }