]> dev.renevier.net Git - syp.git/commitdiff
i18n and english translation
authorarno <arenevier@fdn.fr>
Tue, 21 Jul 2009 20:06:13 +0000 (22:06 +0200)
committerarno <arenevier@fdn.fr>
Wed, 22 Jul 2009 12:00:32 +0000 (14:00 +0200)
18 files changed:
admin.en.php [new symlink]
admin.fr.php [new symlink]
admin.php
build.sh
inc/i10n/en/syp.php [new file with mode: 0644]
inc/i10n/fr/syp.php [new file with mode: 0644]
inc/i10n/translate.txt [new file with mode: 0644]
inc/i10n/updatelang.php [new file with mode: 0755]
inc/langutils.php [new file with mode: 0644]
inc/templates_admin.php [new file with mode: 0644]
inc/templates_index.php [new file with mode: 0644]
index.en.php [new symlink]
index.fr.php [new symlink]
index.php
js/admin.js
js/syp.js
media/admin.css
syp.cfg

diff --git a/admin.en.php b/admin.en.php
new file mode 120000 (symlink)
index 0000000..c01f82a
--- /dev/null
@@ -0,0 +1 @@
+admin.php
\ No newline at end of file
diff --git a/admin.fr.php b/admin.fr.php
new file mode 120000 (symlink)
index 0000000..c01f82a
--- /dev/null
@@ -0,0 +1 @@
+admin.php
\ No newline at end of file
index b69cc9d0348ca1ecb660ee321ee8657dfec14607..a27141aaafd9f7d93fd9b38f54a8cb11d6cb8e09 100644 (file)
--- a/admin.php
+++ b/admin.php
@@ -2,152 +2,6 @@
 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
    license. */
 
-require_once ("./inc/settings.php");
-require_once ("./inc/db/mysql.php");
-require_once ("./inc/utils.php");
-
-$error = false;
-try {
-    $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
-    $usrtblexists = $connection->users_table_exists ();
-    $itemstblexists = $connection->items_table_exists ();
-} catch (Exception $e) {
-    $error = true;
-}
-if (!$usrtblexists || !$itemstblexists) {
-    $error = true;
-}
-    if ($error) {
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-       "http://www.w3.org/TR/html4/loose.dtd">  
-<html>
-<head>
-      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
-      <title>SYP admin</title>
-      <link rel="stylesheet" href="./media/admin.css" type="text/css">
-</head>
-<body>
-    <p class="error center">SYP n'est pas correctement installé. Veuillez
-    consulter le fichier README.txt et suivez les instructions
-    d'installation.</p>
-</body>
-</html>
-<?php
-    exit ();
-    } // if ($error)
+    require ('inc/langutils.php');
+    require ('inc/templates_admin.php');
 ?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-       "http://www.w3.org/TR/html4/loose.dtd">  
-<html>
-<head>
-      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
-      <title>SYP admin</title>
-
-      <link rel="stylesheet" href="./media/admin.css" type="text/css">
-      <link rel="stylesheet" href="./openlayers/theme/default/style.css" type="text/css">
-
-      <script type="text/javascript">
-        <?php 
-            $bbox = $connection->mbr ();
-            printf ("var sypOrig = [%.18F, %.18F, %.18F, %.18F];\n",
-                    $bbox [0], $bbox [1], $bbox [2], $bbox [3]); 
-        ?>
-      </script>
-      <script src="./js/jquery-1.3.2.js" type="text/javascript"></script>
-      <script src="./openlayers/OpenLayers.js" type="text/javascript"></script>
-      <script src="./js/admin.js" type="text/javascript"></script>
-
-    <noscript>
-    <style type="text/css">
-        #map, #editor, #admin, #login_area {
-            display: none;
-        }
-    </style>
-    </noscript>
-
-</head>
-
-<body>
-
-    <noscript>
-    <p>SYP nécessite javascript pour fonctionner. Veuillez activer les scripts
-       dans votre navigateur.</p>
-    </noscript>
-
-
-    <div id="map"></div>
-
-    <div id="admin" class="center">
-        <input id="newfeature_button" type="button" value="ajouter un emplacement">
-        <p id="server_comm"></p>
-        <p id="instructions"></p>
-    </div>
-
-    <p id="logout"><a href="logout.php">Déconnexion</a></p>
-
-    <div id="editor" class="center">
-        <input id="editor_close" type="image" src="openlayers/theme/default/img/close.gif"
-             title="fermer sans enregistrer" alt="fermer">
-        <form id="feature_update" method="post" enctype="multipart/form-data">
-            <label for="title">titre&nbsp;:</label><br>
-            <input id="title" name="title"><br>
-            <label for="description">description&nbsp;:</label><br>
-            <textarea id="description" name="description" rows="4"></textarea><br>
-            <div><img id="img"></div>
-            <input id="image_delete" type="button" value="supprimer l'image">
-            <div>
-                <label for="image_file">ajouter une image&nbsp;:</label>
-                <input id="image_file" type="file" name="image_file">
-            </div>
-            <br>
-            <div class="center">
-            <input id="validate_editor" type="submit" value="Valider les changements">
-            </div>
-            <input type="hidden" name="request">
-            <input type="hidden" name="lon">
-            <input type="hidden" name="lat">
-            <input type="hidden" name="fid">
-            <input type="hidden" name="keep_img">
-        </form>
-        <form id="feature_delete" method="post">
-            <input id="delete" type="submit" value="Supprimer la fiche">
-            <input type="hidden" name="request" value="del">
-            <input type="hidden" name="fid">
-        </form>
-    </div>
-
-      <div id="login_area"
-        <?php 
-        if ($connection->checkpwdmd5 ("admin", 
-                               $_COOKIE [sprintf ("%sauth", DBPREFIX)])) {
-            echo ' class="hidden"';
-        }
-      ?>>
-     <div id="login_transparency"></div>
-     <div id="login_padding"></div>
-     <div id="login_content">
-        <form id="login_form" method="post">
-            <table>
-                <tr>
-                    <td><label for="password">mot de passe</label></td>
-                    <td style="width: 100%"><input id="password" name="password" type="password"></td>
-                </tr>
-            </table>
-            <p class="center">
-                <input id="login_submit" type="submit" value="Connexion">
-                <input type="hidden" name="request" value="auth">
-            </p>
-            <p id="pwd_throbber" class="throbber center">
-                Connexion en cours
-                <img src="media/pwd_throbber.gif" alt="throbber">
-            </p>
-            <p class="error center" id="login_error"></p>
-        </form>
-     </div>
-     </div>
-
-     <iframe id="api_frame" name="api_frame" src="" frameborder="0" width="0" height="0"></iframe>
-
-</body>
-</html>
index fbbd7ffbc1619611a5882cb402ca87f7a144ad22..5b8711ce2611299c44a9d306c7c8cc1ac3974de6 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -15,7 +15,7 @@ mkdir -p $DESTDIR
 cp -RLp inc/ $DESTDIR/
 
 # other php files
-cp -p admin.php api.php index.php items.php logout.php wizard.php $DESTDIR/
+cp -p admin.*php index.*php api.php items.php logout.php wizard.php $DESTDIR/
 
 # media
 cp -RLp media/ $DESTDIR/
diff --git a/inc/i10n/en/syp.php b/inc/i10n/en/syp.php
new file mode 100644 (file)
index 0000000..843a97c
--- /dev/null
@@ -0,0 +1,116 @@
+<?php
+    $translations['en'] = array(
+        // your name
+        "_translator_name" => "arno renevier",
+
+        // your email
+        "_translator_mail" => "arno@renevier.net",
+
+        // your language name in your language. It will be used to link to
+        // pages in your languages from pages in other
+        "_language_name" => "english",
+
+        /* starts translation */
+
+        "SYP needs javascript. Please activate scripts in your browser."
+          => "",
+
+        "propulsed by <a href=\\\"http://syp.renevier.net\\\">syp</a>"
+          => "",
+
+        "There is no image registered on this site."
+          => "",
+
+        "SYP admin"
+          => "",
+
+        "SYP is not correctly installed. Please read README.txt file and follow\n" .
+        "       installation instructions."
+          => "",
+
+        "add a place"
+          => "",
+
+        "You can move an item by drag & droping it."
+          => "",
+
+        "To modify an item data, select matching marker."
+          => "",
+
+        "Click on the map to add a marker."
+          => "",
+
+        "There was a server error."
+          => "",
+
+        "Item was not registered on the server."
+          => "",
+
+        "No change was made."
+          => "",
+
+        "Server did not understood request. That's probably caused by a bug in SYP."
+          => "",
+
+        "Image was too big and was not accepted by server."
+          => "",
+
+        "Password is not correct."
+          => "",
+
+        "File does not look like an image."
+          => "",
+
+        "Server reply was inconsistent."
+          => "",
+
+        "There was an unknown error."
+          => "",
+
+        "Removal took place correctly."
+          => "",
+
+        "Save took place correctly."
+          => "",
+
+        "Logout"
+          => "",
+
+        "close without saving"
+          => "",
+
+        "close"
+          => "",
+
+        "title:"
+          => "",
+
+        "description:"
+          => "",
+
+        "delete image"
+          => "",
+
+        "add an image:"
+          => "",
+
+        "Validate changes"
+          => "",
+
+        "Delete item"
+          => "",
+
+        "password"
+          => "",
+
+        "Connection"
+          => "",
+
+        "Connecting"
+          => "",
+
+        "This feature is not enabled on demo site"
+          => "",
+
+    )
+?>
diff --git a/inc/i10n/fr/syp.php b/inc/i10n/fr/syp.php
new file mode 100644 (file)
index 0000000..acc6b69
--- /dev/null
@@ -0,0 +1,185 @@
+<?php
+    $translations['fr'] = array(
+        // your name
+        "_translator_name" => "arno renevier",
+
+        // your email
+        "_translator_mail" => "arno@renevier.net",
+
+        // your language name in your language. It will be used to link to
+        // pages in your languages from pages in other
+        "_language_name" => "français",
+
+        /* starts translation */
+
+
+        "SYP needs javascript. Please activate scripts in your browser."
+          =>
+        "SYP a besoin de javascript pour fonctionner. Veuillez activer les scripts dans votre navigateur."
+          ,
+
+        "propulsed by <a href=\\\"http://syp.renevier.net\\\">syp</a>"
+          =>
+        "propulsé par <a href=\\\"http://syp.renevier.net\\\">syp</a>"
+          ,
+
+        "There is no image registered on this site."
+          =>
+        "Il n'y a aucune image enregistrée sur le site."
+          ,
+
+        "SYP admin"
+          =>
+        "administration de SYP"
+          ,
+
+        "SYP is not correctly installed. Please read README.txt file and follow\n" .
+        "       installation instructions."
+          =>
+        "SYP n'est pas correctement installé. Veuillez\n" .
+        "       consulter le fichier README.txt et suivez les instructions\n" .
+        "       d'installation."
+          ,
+
+        "add a place"
+          =>
+        "ajouter un emplacement"
+          ,
+
+        "You can move an item by drag & droping it."
+          =>
+        "Vous pouvez déplacer le marqueur en le glissant-déposant."
+          ,
+
+        "To modify an item data, select matching marker."
+          =>
+        "Pour modifier les données d'un item, sélectionnez le marqueur correspondant."
+          ,
+
+        "Click on the map to add a marker."
+          =>
+        "Cliquez sur la carte pour ajouter un marqueur."
+          ,
+
+        "There was a server error."
+          =>
+        "Il s'est produit une erreur serveur."
+          ,
+
+        "Item was not registered on the server."
+          =>
+        "La fiche n'était pas référencée sur le serveur"
+          ,
+
+        "No change was made."
+          =>
+        "Aucun changement n'a été effectué."
+          ,
+
+        "Server did not understood request. That's probably caused by a bug in SYP."
+          =>
+        "Le serveur n'a pas compris la requête. Il s'agit probablement d'un bug dans SYP."
+          ,
+
+        "Image was too big and was not accepted by server."
+          =>
+        "L'image est trop grande et n'a pas été acceptée par le serveur."
+          ,
+
+        "Password is not correct."
+          =>
+        "Le mot de passe n'est pas correct."
+          ,
+
+        "File does not look like an image."
+          =>
+        "Le fichier ne semble pas être une image."
+          ,
+
+        "Server reply was inconsistent."
+          =>
+        "Le serveur a fait une réponse incohérente"
+          ,
+
+        "There was an unknown error."
+          =>
+        "Il s'est produit une erreur inconnue."
+          ,
+
+        "Removal took place correctly."
+          =>
+        "La suppression s'est déroulée correctement."
+          ,
+
+        "Save took place correctly."
+          =>
+        "La sauvegarde s'est déroulée correctement."
+          ,
+
+        "Logout"
+          =>
+        "Déconnexion"
+          ,
+
+        "close without saving"
+          =>
+        "fermer sans enregistrer"
+          ,
+
+        "close"
+          =>
+        "fermer"
+          ,
+
+        "title:"
+          =>
+        "titre&nbsp;:"
+          ,
+
+        "description:"
+          =>
+        "description&nbsp;:"
+          ,
+
+        "delete image"
+          =>
+        "supprimer l'image"
+          ,
+
+        "add an image:"
+          =>
+        "ajouter une image&nbsp;:"
+          ,
+
+        "Validate changes"
+          =>
+        "Valider les changements"
+          ,
+
+        "Delete item"
+          =>
+        "Supprimer la fiche"
+          ,
+
+        "password"
+          =>
+        "mot de passe"
+          ,
+
+        "Connection"
+          =>
+        "Connexion"
+          ,
+
+        "Connecting"
+          =>
+        "Connexion en cours"
+          ,
+
+        "This feature is not enabled on demo site"
+          =>
+        "Cette fonctionnalité est désactivée sur le site de démonstration"
+          ,
+
+    )
+?>
diff --git a/inc/i10n/translate.txt b/inc/i10n/translate.txt
new file mode 100644 (file)
index 0000000..47ec572
--- /dev/null
@@ -0,0 +1,25 @@
+how to add a language:
+----------------------
+If you want to add language xy, run 
+$ ./updatelang.php xy
+then, translate all strings in xy/syp.php
+
+how to update a language:
+-------------------------
+If you want to update language xy, run 
+$ ./updatelang.php xy
+then, translate empty strings xy/syp.php
+
+how to remove a language:
+-------------------------
+If you want to remove language xy, remove xy directory, and unlink symbolic
+links in root directory:
+$ rm -r xy/
+$ rm ../../*.xy.php
+
+*******************
+* IMPORTANT NOTES *
+*******************
+
+- you can split a translated string in several lines, but it must stay a php string:
+  use a dot (".") to tell the php interpreter that string is not finished.
diff --git a/inc/i10n/updatelang.php b/inc/i10n/updatelang.php
new file mode 100755 (executable)
index 0000000..3133e84
--- /dev/null
@@ -0,0 +1,156 @@
+#!/usr/bin/php
+<?php
+
+// only execute from command line
+if (!(isset ($argc)) || !(isset ($argv))) {
+    exit (0);
+}
+
+$ROOTDIR="../../";
+$SCRIPTS=array("admin"); // scripts in rootdir we need to link to
+
+function usage() {
+    global $argv;
+    return ("Usage: " . $argv[0] . " [lang1] [lang2]\n");
+}
+
+function warn($str) { // writes string to stderr
+    error ($str);
+}
+
+function error($str) { // writes string to stderr
+    $stderr = fopen ('php://stderr', 'w');
+    fwrite ($stderr, $str);
+    fclose ($stderr); 
+}
+
+function main($argv, $argc, $rootdir, $scripts) {
+    $options = getopt("h");
+    if (isset ($options ['h'])) {
+        print usage ();
+        return 0;
+    }
+
+    if ($argc <= 1) { // update all existing langs
+        foreach (scandir (".") as $entry) {
+            if (is_dir ($entry) && !($entry[0] == ".") && !($entry == "en")) {
+                updatelang ($entry, $rootdir, $scripts);
+            }
+        }
+    } else {
+        foreach (array_slice ($argv, 1) as $item) {
+            updatelang ($item, $rootdir, $scripts); 
+        }
+    }
+
+    return 0;
+}
+
+function escape_newline ($str, $tab) {
+    return str_replace("\n", "\\n\" .\n$tab$tab\"", $str);
+}
+function escape_slash ($str) {
+    $res = str_replace("\\", "\\\\", $str);
+    $res = str_replace("\"", "\\\"", $res);
+    return $res;
+}
+
+function escape_all ($str, $tab) {
+    $str = escape_slash ($str);
+    $str = escape_newline ($str, $tab);
+    return $str;
+}
+
+function updatelang($lang, $rootdir, $scripts) {
+    if (!preg_match ('/^[a-zA-Z]{2,3}(-[a-zA-Z]{2,3})?$/', $lang)) {
+        warn ("$lang is not a valid lang format.\n");
+        return false;
+    }
+    if ($lang == "en") {
+        warn ("en is reference language. It must be managed manually.\n");
+        return false;
+    }
+    
+    if (!is_dir ($lang)) {
+        if (!mkdir ($lang)) {
+            error ("could not create $lang directory.\n");
+            return false;
+        }
+    }
+
+    require ("en/syp.php");
+    if (is_file ("$lang/syp.php")) {
+        require ("$lang/syp.php");
+    }
+
+    $translator_name = $translations[$lang]["_translator_name"];
+    $translator_mail = $translations[$lang]["_translator_mail"];
+    $language_name   = $translations[$lang]["_language_name"];
+
+    $tab = str_repeat (" ", 4);
+
+    $tmpname = tempnam ("", "");
+    $output = fopen($tmpname, "w");
+
+    fwrite ($output, "<?php\n");
+
+    fwrite ($output, "$tab" . "\$translations['" . $lang . "'] = array(\n");
+    fwrite ($output, "$tab$tab" . "// your name\n");
+    fwrite ($output, "$tab$tab" . "\"_translator_name\" => \"" . escape_slash ($translator_name) . "\",\n");
+    fwrite ($output, "\n");
+
+    fwrite ($output, "$tab$tab" . "// your email\n");
+    fwrite ($output, "$tab$tab" . "\"_translator_mail\" => \"" . escape_slash ($translator_mail) . "\",\n");
+    fwrite ($output, "\n");
+
+    fwrite ($output, "$tab$tab" . "// your language name in your language. It will be used to link to\n");
+    fwrite ($output, "$tab$tab" . "// pages in your languages from pages in other\n");
+    fwrite ($output, "$tab$tab" . "\"_language_name\" => \"" . escape_slash ($language_name) . "\",\n");
+    fwrite ($output, "\n");
+
+    fwrite ($output, "$tab$tab" . "/* starts translation */\n");
+    fwrite ($output, "\n");
+    fwrite ($output, "\n");
+
+    foreach ($translations['en'] as $key => $value) {
+        if ($key[0] == "_") {
+            continue;
+        }
+        $value = $translations[$lang][$key];
+
+        fwrite ($output, "$tab$tab" . "\"" . escape_all ($key, $tab) . "\"" . "\n");
+        fwrite ($output, "$tab$tab  " . "=>\n");
+        fwrite ($output, "$tab$tab" . "\"" . escape_all ($value, $tab) . "\"" . "\n");
+        fwrite ($output, "$tab$tab  " . ",\n");
+        fwrite ($output, "\n");
+    }
+
+    fwrite ($output, "$tab" . ")\n");
+    fwrite ($output, "?>"); // <?php <- fixes vim syntax
+
+    fclose($output);
+
+    if (!rename ($tmpname, "$lang/syp.php")) {
+        error ("could not move $tmpname to $lang/sys.php");
+        unlink ($tmpname);
+        return false;
+    }
+    if (!chmod ("$lang/syp.php", 0644)) {
+        error ("could not set permissions to $lang/sys.php");
+        return false;
+    }
+    
+    foreach ($scripts as $script) {
+        $link = $rootdir . "/"  . $script . "." . $lang . ".php";
+        $target = $script . ".php";
+        if (!file_exists ($link)) {
+            if (!symlink ($target, $link)) {
+                error ("could not link $target to $link");
+            }
+        }
+    }
+    return true;
+}
+
+exit (main($argv, $argc, $ROOTDIR, $SCRIPTS));
+?>
diff --git a/inc/langutils.php b/inc/langutils.php
new file mode 100644 (file)
index 0000000..5ac4a37
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
+   license. */
+
+    $language_list = Array ();
+
+function ptrans ($str) {
+    echo trans ($str);
+}
+
+function trans ($str) {
+    global $translations, $lang;
+
+    $res = $translations[$lang][$str];
+    if (!isset ($res) || strlen ($res) == 0) {
+        return $str;
+    } else {
+        return $res;
+    }
+}
+
+function parse_accept_language () {
+    global $translations;
+    $possibilities = array();
+    if (isset ($_SERVER ['HTTP_ACCEPT_LANGUAGE'])) {
+        // set to lower case now
+        $accepts = explode (',',
+                        strtolower ($_SERVER ['HTTP_ACCEPT_LANGUAGE']));
+        foreach ($accepts as $acc) {
+            if (preg_match ('/^\s*([a-zA-Z-]+)\s*$/', $acc, $matches)) {
+                $possibilities [$matches [1]] = 1.0;
+            }
+            if (preg_match ('/^\s*([a-zA-Z-]+)\s*;\s*q\s*=\s*([0-9\.]+)\s*$/', 
+                            $acc, $matches)) {
+                $val = floatval ($matches [2]);
+                if ($val > 1.0) {
+                    $val = 1.0;
+                }
+                $possibilities [$matches [1]] = $val;
+            }
+        }
+        arsort ($possibilities);
+        foreach ($possibilities as $lang => $value) {
+            if (isset ($translations [$lang])) {
+                return $lang;
+            }
+        }
+    }
+    return "en"; // nothing found; default to english
+}
+
+function other_languages ($current_lang) {
+ $script = pathinfo ($_SERVER ["SCRIPT_NAME"], PATHINFO_FILENAME);
+    $dotpos = strpos ($script, '.');
+    if ($dotpos !== false) {
+        $script = substr ($script, 0, $dotpos);
+    }
+    
+    global $translations;
+    $links = Array ();
+    foreach ($translations as $lang => $obj) {
+        $lang_name = $obj ["_language_name"];
+        if ($lang == $current_lang) {
+            array_push ($links, "<a>$lang_name</a>");
+        } else  {
+            array_push ($links, "<a href=\"$script.$lang.php\" title=\"$lang_name\" lang=\"$lang\" hreflang=\"$lang\">$lang_name</a>");
+        }
+    }                                                                                                                      
+    echo "<div id=\"other-language\">" . join("", $links) . "</div>\n";
+}
+
+// load languages
+foreach (scandir ("inc/i10n/") as $entry) {
+    if (is_dir ("inc/i10n/$entry") && ($entry [0] != ".")) {
+        $target = "inc/i10n/$entry/syp.php";
+        if (is_file ($target)) {
+            include $target;
+        }
+    }
+}
+
+// detects language                                                                                                         
+$fname = pathinfo ($_SERVER ["SCRIPT_NAME"], PATHINFO_FILENAME);                                                            
+$lang = ltrim (strstr ($fname, '.'), '.');
+if ((!isset ($lang)) ||
+    (strlen ($lang) == 0) ||
+    (!isset ($translations [$lang]))) {
+    $lang = parse_accept_language ();
+}
diff --git a/inc/templates_admin.php b/inc/templates_admin.php
new file mode 100644 (file)
index 0000000..eda657d
--- /dev/null
@@ -0,0 +1,173 @@
+<?php
+/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
+   license. */
+
+require_once ("./inc/settings.php");
+require_once ("./inc/db/mysql.php");
+require_once ("./inc/utils.php");
+
+$error = false;
+try {
+    $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
+    $usrtblexists = $connection->users_table_exists ();
+    $itemstblexists = $connection->items_table_exists ();
+} catch (Exception $e) {
+    $error = true;
+}
+if (!$usrtblexists || !$itemstblexists) {
+    $error = true;
+}
+    if ($error) {
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+       "http://www.w3.org/TR/html4/loose.dtd">  
+<html>
+<head>
+      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
+      <title><?php ptrans('SYP admin')?></title>
+      <link rel="stylesheet" href="./media/admin.css" type="text/css">
+</head>
+<body>
+    <p class="error center"><?php ptrans('SYP is not correctly installed. Please read README.txt file and follow
+       installation instructions.')?></p>
+</body>
+</html>
+<?php
+    exit ();
+    } // if ($error)
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+       "http://www.w3.org/TR/html4/loose.dtd">  
+<html>
+<head>
+      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
+      <title><?php ptrans('SYP admin');?></title>
+
+      <link rel="stylesheet" href="./media/admin.css" type="text/css">
+      <link rel="stylesheet" href="./openlayers/theme/default/style.css" type="text/css">
+
+      <script type="text/javascript">
+        var SypStrings = {
+            AddItem: "<?php ptrans('add a place')?>",
+            DragDropHowto: "<?php ptrans('You can move an item by drag & droping it.')?>",
+            SelectHowto: "<?php ptrans('To modify an item data, select matching marker.')?>",
+            AddHowto: "<?php ptrans('Click on the map to add a marker.')?>",
+            ServerError: "<?php ptrans('There was a server error.')?>",
+            UnreferencedError: "<?php ptrans('Item was not registered on the server.')?>",
+            NochangeError: "<?php ptrans('No change was made.')?>",
+            RequestError: "<?php ptrans('Server did not understood request. That\'s probably caused by a bug in SYP.')?>",
+            ToobigError: "<?php ptrans('Image was too big and was not accepted by server.')?>",
+            UnauthorizedError: "<?php ptrans('Password is not correct.')?>",
+            NotimageError: "<?php ptrans('File does not look like an image.')?>",
+            UnconsistentError: "<?php ptrans('Server reply was inconsistent.')?>",
+            UnknownError: "<?php ptrans('There was an unknown error.')?>",
+            DelSucces: "<?php ptrans('Removal took place correctly.')?>",
+            UpdateSucces: "<?php ptrans('Save took place correctly.')?>"
+        };
+
+        <?php 
+            $bbox = $connection->mbr ();
+            printf ("var sypOrig = [%.18F, %.18F, %.18F, %.18F];\n",
+                    $bbox [0], $bbox [1], $bbox [2], $bbox [3]); 
+        ?>
+
+      </script>
+      <script src="./js/jquery-1.3.2.js" type="text/javascript"></script>
+      <script src="./openlayers/OpenLayers.js" type="text/javascript"></script>
+      <script src="./js/admin.js" type="text/javascript"></script>
+
+    <noscript>
+    <style type="text/css">
+        #map, #editor, #admin, #login_area {
+            display: none;
+        }
+    </style>
+    </noscript>
+
+</head>
+
+<body>
+
+    <noscript>
+    <p><?php ptrans('SYP needs javascript. Please activate scripts in your browser.')?></p>
+    </noscript>
+
+    <div id="header">
+    <?php other_languages($lang) ?>
+    <p id="logout"><a href="logout.php"><?php ptrans('Logout')?></a></p>
+    </div>
+
+
+    <div id="map"></div>
+
+    <div id="admin" class="center">
+        <input id="newfeature_button" type="button" value="<?php ptrans('add a place')?>">
+        <p id="server_comm"></p>
+        <p id="instructions"></p>
+    </div>
+
+    <div id="editor" class="center">
+        <input id="editor_close" type="image" src="openlayers/theme/default/img/close.gif"
+             title="<?php ptrans('close without saving')?>" alt="<?php ptrans('close')?>">
+        <form id="feature_update" method="post" enctype="multipart/form-data">
+            <label for="title"><?php ptrans('title:')?></label><br>
+            <input id="title" name="title"><br>
+            <label for="description"><?php ptrans('description:')?></label><br>
+            <textarea id="description" name="description" rows="4"></textarea><br>
+            <div><img id="img"></div>
+            <input id="image_delete" type="button" value="<?php ptrans('delete image')?>">
+            <div>
+                <label for="image_file"><?php ptrans('add an image:')?></label>
+                <input id="image_file" type="file" name="image_file">
+            </div>
+            <br>
+            <div class="center">
+            <input id="validate_editor" type="submit" value="<?php ptrans('Validate changes')?>">
+            </div>
+            <input type="hidden" name="request">
+            <input type="hidden" name="lon">
+            <input type="hidden" name="lat">
+            <input type="hidden" name="fid">
+            <input type="hidden" name="keep_img">
+        </form>
+        <form id="feature_delete" method="post">
+            <input id="delete" type="submit" value="<?php ptrans('Delete item')?>">
+            <input type="hidden" name="request" value="del">
+            <input type="hidden" name="fid">
+        </form>
+    </div>
+
+      <div id="login_area"
+        <?php 
+        if ($connection->checkpwdmd5 ("admin", 
+                               $_COOKIE [sprintf ("%sauth", DBPREFIX)])) {
+            echo ' class="hidden"';
+        }
+      ?>>
+     <div id="login_transparency"></div>
+     <div id="login_padding"></div>
+     <div id="login_content">
+        <form id="login_form" method="post">
+            <table>
+                <tr>
+                    <td><label for="password"><?php ptrans('password')?></label></td>
+                    <td style="width: 100%"><input id="password" name="password" type="password"></td>
+                </tr>
+            </table>
+            <p class="center">
+                <input id="login_submit" type="submit" value="<?php ptrans('Connection')?>">
+                <input type="hidden" name="request" value="auth">
+            </p>
+            <p id="pwd_throbber" class="throbber center">
+                <?php ptrans('Connecting')?>
+                <img src="media/pwd_throbber.gif" alt="throbber">
+            </p>
+            <p class="error center" id="login_error"></p>
+        </form>
+     </div>
+     </div>
+
+     <iframe id="api_frame" name="api_frame" src="" frameborder="0" width="0" height="0"></iframe>
+
+</body>
+</html>
diff --git a/inc/templates_index.php b/inc/templates_index.php
new file mode 100644 (file)
index 0000000..2d59926
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
+   license. */
+
+require_once ("./inc/settings.php");
+require_once ("./inc/db/mysql.php");
+
+try {
+    $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
+} catch (Exception $e) {
+}
+
+$bbox = $connection->mbr ();
+?>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
+    <title><?php echo defined ("SITETITLE") ? SITETITLE : "SYP"?></title>
+    <link rel="stylesheet" href="./openlayers/theme/default/style.css" type="text/css">
+    <link rel="stylesheet" href="./media/syp.css" type="text/css">
+
+    <script type="text/javascript">
+        var SypStrings = {
+            language: "<?php echo $lang ?>",
+            propulsedByLink: "<?php ptrans('propulsed by <a href=\"http://syp.renevier.net\">syp</a>')?>",
+            noImageRegistered: "<?php ptrans('There is no image registered on this site.')?>"
+        };
+        <?php
+            printf ("var sypOrig = [%.18F, %.18F, %.18F, %.18F];\n",
+                    $bbox [0], $bbox [1], $bbox [2], $bbox [3]);
+        ?>
+    </script>
+    <script src="./openlayers/OpenLayers.js" type="text/javascript"></script>
+    <script src="./js/syp.js" type="text/javascript"></script>
+
+    <noscript>
+    <style type="text/css">
+        #map {
+            display: none;
+        }
+    </style>
+    </noscript>
+
+    </head>
+
+    <body onload="SYP.init();">
+
+        <noscript>
+            <p><?php ptrans('SYP needs javascript. Please activate scripts in your browser.')?></p>
+        </noscript>
+
+        <div id="map"></div>
+        <div id="message"></div>
+
+</body>
+</html>
diff --git a/index.en.php b/index.en.php
new file mode 120000 (symlink)
index 0000000..0012f7d
--- /dev/null
@@ -0,0 +1 @@
+index.php
\ No newline at end of file
diff --git a/index.fr.php b/index.fr.php
new file mode 120000 (symlink)
index 0000000..0012f7d
--- /dev/null
@@ -0,0 +1 @@
+index.php
\ No newline at end of file
index 4b640a3f3bb1d657e0c9a21df3809b1f7916d9b9..b07a6e44a3483bdd51cdf2852473212fbc6def86 100644 (file)
--- a/index.php
+++ b/index.php
@@ -2,51 +2,6 @@
 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
    license. */
 
-require_once ("./inc/settings.php");
-require_once ("./inc/db/mysql.php");
-
-try {
-    $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
-} catch (Exception $e) {
-}
-
-$bbox = $connection->mbr ();
+    require ('inc/langutils.php');
+    require ('inc/templates_index.php');
 ?>
-<html>
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
-    <title><?php echo defined ("SITETITLE") ? SITETITLE : "SYP"?></title>
-    <link rel="stylesheet" href="./openlayers/theme/default/style.css" type="text/css">
-    <link rel="stylesheet" href="./media/syp.css" type="text/css">
-
-    <script type="text/javascript">
-        <?php
-            printf ("var sypOrig = [%.18F, %.18F, %.18F, %.18F];\n",
-                    $bbox [0], $bbox [1], $bbox [2], $bbox [3]);
-        ?>
-    </script>
-    <script src="./openlayers/OpenLayers.js" type="text/javascript"></script>
-    <script src="./js/syp.js" type="text/javascript"></script>
-
-    <noscript>
-    <style type="text/css">
-        #map {
-            display: none;
-        }
-    </style>
-    </noscript>
-
-    </head>
-
-    <body onload="SYP.init();">
-
-        <noscript>
-            <p>SYP nécessite javascript pour fonctionner. Veuillez activer les
-                scripts dans votre navigateur.</p>
-        </noscript>
-
-        <div id="map"></div>
-        <div id="message"></div>
-
-</body>
-</html>
index c7be3dbb00abedaf53790952a4459e23bee1ea39..25e3e8c83c770ac0c8d5438da04fab9aeb4d0bd4 100644 (file)
@@ -123,7 +123,7 @@ var Admin = {
         this.moveFeatureControl.deactivate();
         this.selFeatureControl.activate();
         this.checkForFeatures();
-        $("#newfeature_button").show().val("ajouter un emplacement");
+        $("#newfeature_button").show().val(SypStrings.AddItem);
         $("#newfeature_button").unbind("click").click(function () {
             Admin.addNewFeature();
         });
@@ -230,7 +230,7 @@ var Admin = {
         this.currentFeature = feature;
         this.currentFeatureLocation = new OpenLayers.Pixel(feature.geometry.x, feature.geometry.y);
         $("#editor").show();
-        $("#instructions").text("Vous pouvez déplacer le marqueur en effectuant un glisser-déposer.");
+        $("#instructions").text(SypStrings.DragDropHowto);
         $("#title").val(feature.attributes.name);
         var fullDesc = $(feature.attributes.description).parent();
         $("#description").val(fullDesc.find('p').text());
@@ -250,7 +250,7 @@ var Admin = {
 
     checkForFeatures: function () {
         if (this.dataLayer.features.length != 0) {
-            $("#instructions").text("Pour modifier les données d'une image, sélectionnez le marqueur correspondant.");
+            $("#instructions").text(SypStrings.SelectHowto);
         }
     },
 
@@ -269,7 +269,7 @@ var Admin = {
         $("#newfeature_button").val("annuler");
         $("#newfeature_button").unbind("click").click(cancel);
 
-        $("#instructions").text("Cliquez sur la carte pour ajouter un marqueur.");
+        $("#instructions").text(SypStrings.AddHowto);
         this.selFeatureControl.deactivate();
         this.addFeatureControl.activate();
         FeatureMgr.reset();
@@ -395,7 +395,7 @@ var FeatureMgr = {
 
     ajaxReply: function (data) {
         if (!data) {
-            this.commError("Il s'est produit une erreur serveur.");
+            this.commError(SypStrings.ServerError);
             return;
         }
 
@@ -410,34 +410,34 @@ var FeatureMgr = {
                         Admin.reset();
                     break;
                     case "server":
-                        this.commError("Il s'est produit une erreur serveur.");
+                        this.commError(SypStrings.ServerError);
                         $("title").focus();
                     break;
                     case "unreferenced":
-                        this.commError("La fiche n'était pas référencée sur le serveur.");
+                        this.commError(SypStrings.UnreferencedError);
                         Admin.reloadLayer(Admin.dataLayer);
                         Admin.closeEditor();
                     break;
                     case "nochange":
-                        this.commError("Aucun changement n'a été effectué.");
+                        this.commError(SypStrings.NochangeError);
                         Admin.closeEditor();
                     break;
                     case "request":
-                        this.commError("Le serveur n'a pas compris la requête. Il s'agit probablement d'un bug dans SYP.");
+                        this.commError(SypStrings.RequestError);
                         $("title").focus();
                     break;
                     case "toobig":
-                        this.commError("L'image est trop grande et n'a pas été acceptée par le serveur.");
+                        this.commError(SypStrings.ToobigError);
                         $("#image_file").parent().html($("#image_file").parent().html());
                         $("#image_file").focus();
                     break;
                     case "notimage":
-                        this.commError("Le fichier ne semble pas être une image.");
+                        this.commError(SypStrings.NotimageError);
                         $("#image_file").parent().html($("#image_file").parent().html());
                         $("#image_file").focus();
                     break;
                     default:
-                        this.commError("Il s'est produit une erreur inconnue.");
+                        this.commError(SypStrings.UnknownError);
                         $("title").focus();
                     break;
                 }
@@ -445,7 +445,7 @@ var FeatureMgr = {
             case "success":
                 switch (xml.documentElement.getAttribute("request")) {
                     case "del":
-                        this.commSuccess("La suppression s'est déroulée correctement.");
+                        this.commSuccess(SypStrings.DelSucces);
                         var someFeature = false;
                         var self = this;
                         $.each($(xml).find("FEATURE,feature"), function () {
@@ -462,7 +462,7 @@ var FeatureMgr = {
                              }
                         });
                         if (someFeature == false) {
-                            this.commError("Le serveur a fait une réponse incohérente.");
+                            this.commError(SypStrings.UnconsistentError);
                         } else {
                             Admin.closeEditor();
                         }
@@ -503,20 +503,20 @@ var FeatureMgr = {
                         });
 
                         if (someFeature == false) {
-                            this.commError("Le serveur a fait une réponse incohérente.");
+                            this.commError(SypStrings.UnconsistentError);
                         } else {
-                            this.commSuccess("La sauvegarde s'est déroulée correctement.");
+                            this.commSuccess(SypStrings.UpdateSucces);
                             Admin.closeEditor();
                         }
 
                     break;
                     default:
-                        this.commError("Le serveur a fait une réponse incohérente.");
+                        this.commError(SypStrings.UnconsistentError);
                    break;
                 }
             break;
             default:
-                this.commError("Le serveur a fait une réponse incohérente.");
+                this.commError(SypStrings.UnconsistentError);
             break;
         }
     },
@@ -637,7 +637,7 @@ var pwdMgr = {
         }, 0);
 
         if (!data) {
-            this.commError("Il s'est produit une erreur serveur.");
+            this.commError(SypStrings.ServerError);
             $("#login_error").show();
             window.setTimeout(function() {
                     $("#password").focus().select();
@@ -650,16 +650,16 @@ var pwdMgr = {
             case "error":
                 switch (xml.documentElement.getAttribute("reason")) {
                     case "server":
-                        this.commError("Il s'est produit une erreur serveur.");
+                        this.commError(SypStrings.ServerError);
                     break;
                     case "unauthorized":
-                        this.commError("Le mot de passe n'est pas correct.");
+                        this.commError(SypStrings.UnauthorizedError);
                     break;
                     case "request":
-                        this.commError("Le serveur n'a pas compris la requête. Il s'agit probablement d'un bug dans SYP.");
+                        this.commError(SypStrings.RequestError);
                     break;
                     default:
-                        this.commError("Il s'est produit une erreur inconnue.");
+                        this.commError(SypStrings.UnknownError);
                     break;
                 }
                 $("#login_error").show();
@@ -672,7 +672,7 @@ var pwdMgr = {
                 $("#login_area").hide();
             break;
             default:
-                this.commError("Le serveur a fait une réponse incohérente.");
+                this.commError(SypStrings.UnconsistentError);
             break;
         }
     },
index 3228e62b5a7aeecbf70bb1f94c615b1b8aa13f94..7e69fb75ae61b6b930101cdfce0fdf535a07aabd 100644 (file)
--- a/js/syp.js
+++ b/js/syp.js
@@ -3,7 +3,7 @@
 
 OpenLayers.Control.SypAttribution = OpenLayers.Class (OpenLayers.Control.Attribution, {
     updateAttribution: function() {
-        var attributions = ['propulsed by <a href="http://syp.renevier.net">syp</a>'];
+        var attributions = [SypStrings.propulsedByLink];
         if (this.map && this.map.layers) {
             for(var i=0, len=this.map.layers.length; i<len; i++) {
                 var layer = this.map.layers[i];
@@ -111,7 +111,7 @@ var SYP = {
     checkForFeatures: function() {
         var features = this.dataLayer.features;
         if (features.length == 0) {
-            var message = "Il n'y a aucune image enregistrée sur le site.";
+            var message = SypStrings.noImageRegistered;
             this.Utils.displayUserMessage(message, "warn");
         }
     },
@@ -201,6 +201,12 @@ var SYP = {
     }
 };
 
+// if possible, determine language with HTTP_ACCEPT_LANGUAGE instead of
+// navigator.language
+if (OpenLayers.Lang[SypStrings.language]) {
+    OpenLayers.Lang.setCode(SypStrings.language);
+}
+
 // avoid alerts
 OpenLayers.Console.userError = function(error) { 
     SYP.Utils.displayUserMessage(error, "error");
index 9cbbf7b833de210855c2c258b877d470f5f0ee32..c3815136684d4ff15e906ae180537d7fed274439 100644 (file)
@@ -5,13 +5,32 @@
 
 
 /*
- * misc
+ * header
  */
 
+#header {
+    height: 2em;
+}
 #logout {
     float: right;
     margin: 0px 10px 0px 0px;
 }
+#other-language {
+    float: left;
+    margin-top: 1px;
+}
+#other-language a:hover {
+    background-color: #BBBBFF;
+}
+#other-language a {
+    position: relative; /* needed to display top and bottom borders in ie */
+    text-decoration: none;
+    padding-left: 10px;
+    padding-right: 10px;
+    padding-top: 3px;
+    padding-bottom: 3px;
+    border: #BBBBFF 1px solid;
+}
 
 /*
  * map
@@ -19,7 +38,7 @@
 
 #map {
     position: absolute;
-    top: 4px;
+    top: 2em;
     left: 4px;
     height: 50%;
     width: 50%;
@@ -74,8 +93,9 @@ html>/**/body #img { /* hide from ie7 */
  */
 
 #admin {
+    margin-top: 3em;
     position: fixed;
-    top: 53%;
+    top: 50%;
     width: 50%;
 }
 
diff --git a/syp.cfg b/syp.cfg
index cf9767979eac9f0b581d700d028c12e8788f27eb..cb484e5cd1d62f9f92a1697c696143ee59aa6163 100644 (file)
--- a/syp.cfg
+++ b/syp.cfg
@@ -29,5 +29,7 @@ OpenLayers/Tile/Image.js
 OpenLayers/Tile/WFS.js
 OpenLayers/Request/XMLHttpRequest.js
 OpenLayers/Layer/SphericalMercator.js
+OpenLayers/Lang/en.js
+OpenLayers/Lang/fr.js
 
 [exclude]