]> git.agnieray.net Git - galette.git/commitdiff
Add a __() function
authorJohan Cwiklinski <johan@x-tnd.be>
Sat, 17 Sep 2016 19:56:40 +0000 (21:56 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 17 Oct 2016 20:43:00 +0000 (22:43 +0200)
A function which translate without adding
the "not translated" stuff; usefull to
translate routes.

galette/includes/i18n.inc.php
galette/includes/routes/main.routes.php
galette/lang/xgettext.py

index 5b4b59f60895715e9f8cce54a9712f130e82992b..d9a5428494389f904dd63844d5f4fc282bce7ed4 100644 (file)
@@ -294,44 +294,57 @@ if ((isset($loc) && $loc!=$language) || $disable_gettext) {
     }
 }
 
-if (!function_exists('_T')) {
-    /**
-     * Translate a string
-     *
-     * @param string $chaine The string to translate
-     *
-     * @return Translated string (if available) ; $chaine otherwise
-     */
-    function _T($chaine)
-    {
-        global $language, $disable_gettext, $installer;
-        if ($disable_gettext === true && isset($GLOBALS['lang'])) {
-            $trans = $chaine;
-            if (isset($GLOBALS['lang'][$chaine])
-                && $GLOBALS['lang'][$chaine] != ''
-            ) {
-                $trans = $GLOBALS['lang'][$chaine];
+/**
+ * Translate a string
+ *
+ * @param string  $string The string to translate
+ * @param boolean $nt     Indicate not translated strings; defaults to true
+ *
+ * @return Translated string (if available) ; $chaine otherwise
+ */
+function _T($string, $nt = true)
+{
+    global $language, $disable_gettext, $installer;
+    if ($disable_gettext === true && isset($GLOBALS['lang'])) {
+        if (isset($GLOBALS['lang'][$string])
+            && $GLOBALS['lang'][$string] != ''
+        ) {
+            $trans = $GLOBALS['lang'][$string];
+        } else {
+            $trans = false;
+            if (!isset($installer) || $installer !== true) {
+                $trans = getDynamicTranslation(
+                    $string,
+                    $language
+                );
+            }
+            if ($trans) {
+                $GLOBALS['lang'][$string] = $trans;
             } else {
-                $trans = false;
-                if (!isset($installer) || $installer !== true) {
-                    $trans = getDynamicTranslation(
-                        $chaine,
-                        $language
-                    );
-                }
-                if ($trans) {
-                    $GLOBALS['lang'][$chaine] = $trans;
-                } else {
-                    $trans = $chaine . ' (not translated)';
+                $trans = $string;
+                if ($nt === true) {
+                    $trans .= ' (not translated)';
                 }
             }
-            return $trans;
-        } else {
-            return _($chaine);
         }
+        return $trans;
+    } else {
+        return _($chaine);
     }
 }
 
+/**
+ * Translate a string, without displaying not translated
+ *
+ * @param string $string The string to translate
+ *
+ * @return Translated string (if available), verbatim string otherwise
+ */
+function __($string)
+{
+    return _T($string, false);
+}
+
 /**********************************************
 * some constant strings found in the database *
 **********************************************/
index e5809da0558c5bcb1f1429c12df48ac364780e1f..da998b57bb1c963c4bf1f1f4efe9f176c6021cc1 100644 (file)
@@ -83,7 +83,7 @@ $app->get(
 
 //system informations
 $app->get(
-    '/sysinfos',
+    __("/system-informations"),
     function ($request, $response, $args = []) {
         $sysinfos = new SysInfos();
         $sysinfos->grab();
index b40d10e8ee08da7ccf9b0c807e059fc77aaacbdd..63b0ec89303116c864e0800a309272cd3714c3ca 100755 (executable)
@@ -30,7 +30,7 @@ import sys
 import re
 
 # pattern definition
-translatable= re.compile("_T\((\"[^\"]*\")\)")
+translatable= re.compile("_(T|_)\((\"[^\"]*\")\)")
 tpl_translatable= re.compile("_T\ string=(\"[^\"]*\")")
 
 # constants string
@@ -53,13 +53,14 @@ for inputFileName in sys.argv[1:] :
       # search translatable strings
       matchs =  translatable.findall(line)
       for match in matchs:
-          if dico.has_key(match):
-            if dico[match][-1:] == "\n":
-              dico[match] += startLoc + location()
+          trans = match[1]
+          if dico.has_key(trans):
+            if dico[trans][-1:] == "\n":
+              dico[tans] += startLoc + location()
             else :
-              dico[match] += nextLoc + location() + "\n"
+              dico[trans] += nextLoc + location() + "\n"
           else :
-            dico[match] = startLoc + location()
+            dico[trans] = startLoc + location()
       tpl_matchs =  tpl_translatable.findall(line)
       for tpl_match in tpl_matchs:
           if dico.has_key(tpl_match):
@@ -70,11 +71,14 @@ for inputFileName in sys.argv[1:] :
           else :
             dico[tpl_match] = startLoc + location()
 
+print dico
 #
-outFile = open("messages.po",'w')
+#outFile = open("messages.po",'w')
 for k, v in dico.iteritems():
-   outFile.write(v)
-   if v[-1:] != "\n" :
-     outFile.write("\n")
-   outFile.write("msgid " + k + "\nmsgstr \"\"\n\n")
-outFile.close()
+    print v
+    print "msgid " + k + "\nmsgstr \"\"\n\n"
+#   outFile.write(v)
+#   if v[-1:] != "\n" :
+#     outFile.write("\n")
+#   outFile.write("msgid " + k + "\nmsgstr \"\"\n\n")
+#outFile.close()