From 0feade23ffa41ac299b252a93be4da11bc2a16b7 Mon Sep 17 00:00:00 2001 From: arno Date: Tue, 21 Jul 2009 22:06:13 +0200 Subject: [PATCH] i18n and english translation --- admin.en.php | 1 + admin.fr.php | 1 + admin.php | 150 +------------------------------- build.sh | 2 +- inc/i10n/en/syp.php | 116 +++++++++++++++++++++++++ inc/i10n/fr/syp.php | 185 ++++++++++++++++++++++++++++++++++++++++ inc/i10n/translate.txt | 25 ++++++ inc/i10n/updatelang.php | 156 +++++++++++++++++++++++++++++++++ inc/langutils.php | 89 +++++++++++++++++++ inc/templates_admin.php | 173 +++++++++++++++++++++++++++++++++++++ inc/templates_index.php | 56 ++++++++++++ index.en.php | 1 + index.fr.php | 1 + index.php | 49 +---------- js/admin.js | 48 +++++------ js/syp.js | 10 ++- media/admin.css | 26 +++++- syp.cfg | 2 + 18 files changed, 866 insertions(+), 225 deletions(-) create mode 120000 admin.en.php create mode 120000 admin.fr.php create mode 100644 inc/i10n/en/syp.php create mode 100644 inc/i10n/fr/syp.php create mode 100644 inc/i10n/translate.txt create mode 100755 inc/i10n/updatelang.php create mode 100644 inc/langutils.php create mode 100644 inc/templates_admin.php create mode 100644 inc/templates_index.php create mode 120000 index.en.php create mode 120000 index.fr.php diff --git a/admin.en.php b/admin.en.php new file mode 120000 index 0000000..c01f82a --- /dev/null +++ b/admin.en.php @@ -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 index 0000000..c01f82a --- /dev/null +++ b/admin.fr.php @@ -0,0 +1 @@ +admin.php \ No newline at end of file diff --git a/admin.php b/admin.php index b69cc9d..a27141a 100644 --- 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) { -?> - - - - - SYP admin - - - -

SYP n'est pas correctement installé. Veuillez - consulter le fichier README.txt et suivez les instructions - d'installation.

- - - - - - - - SYP admin - - - - - - - - - - - - - - - - - - -
- -
- -

-

-
- -

Déconnexion

- -
- -
-
-
-
-
-
- -
- - -
-
-
- -
- - - - - -
-
- - - -
-
- -
checkpwdmd5 ("admin", - $_COOKIE [sprintf ("%sauth", DBPREFIX)])) { - echo ' class="hidden"'; - } - ?>> -
-
-
-
- - - - - -
-

- - -

-

- Connexion en cours - throbber -

-

-
-
-
- - - - - diff --git a/build.sh b/build.sh index fbbd7ff..5b8711c 100755 --- 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 index 0000000..843a97c --- /dev/null +++ b/inc/i10n/en/syp.php @@ -0,0 +1,116 @@ + "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 syp" + => "", + + "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 index 0000000..acc6b69 --- /dev/null +++ b/inc/i10n/fr/syp.php @@ -0,0 +1,185 @@ + "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 syp" + => + "propulsé par syp" + , + + "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 :" + , + + "description:" + => + "description :" + , + + "delete image" + => + "supprimer l'image" + , + + "add an image:" + => + "ajouter une image :" + , + + "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 index 0000000..47ec572 --- /dev/null +++ b/inc/i10n/translate.txt @@ -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 index 0000000..3133e84 --- /dev/null +++ b/inc/i10n/updatelang.php @@ -0,0 +1,156 @@ +#!/usr/bin/php + \"" . 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, "?>"); // diff --git a/inc/langutils.php b/inc/langutils.php new file mode 100644 index 0000000..5ac4a37 --- /dev/null +++ b/inc/langutils.php @@ -0,0 +1,89 @@ + 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, "$lang_name"); + } else { + array_push ($links, "$lang_name"); + } + } + echo "
" . join("", $links) . "
\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 index 0000000..eda657d --- /dev/null +++ b/inc/templates_admin.php @@ -0,0 +1,173 @@ +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) { +?> + + + + + <?php ptrans('SYP admin')?> + + + +

+ + + + + + + + <?php ptrans('SYP admin');?> + + + + + + + + + + + + + + + + + + + + +
+ +
+ +

+

+
+ +
+ +
+
+
+
+
+
+ +
+ + +
+
+
+ +
+ + + + + +
+
+ + + +
+
+ +
checkpwdmd5 ("admin", + $_COOKIE [sprintf ("%sauth", DBPREFIX)])) { + echo ' class="hidden"'; + } + ?>> +
+
+
+
+ + + + + +
+

+ + +

+

+ + throbber +

+

+
+
+
+ + + + + diff --git a/inc/templates_index.php b/inc/templates_index.php new file mode 100644 index 0000000..2d59926 --- /dev/null +++ b/inc/templates_index.php @@ -0,0 +1,56 @@ +connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); +} catch (Exception $e) { +} + +$bbox = $connection->mbr (); +?> + + + + <?php echo defined ("SITETITLE") ? SITETITLE : "SYP"?> + + + + + + + + + + + + + + + +
+
+ + + diff --git a/index.en.php b/index.en.php new file mode 120000 index 0000000..0012f7d --- /dev/null +++ b/index.en.php @@ -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 index 0000000..0012f7d --- /dev/null +++ b/index.fr.php @@ -0,0 +1 @@ +index.php \ No newline at end of file diff --git a/index.php b/index.php index 4b640a3..b07a6e4 100644 --- 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'); ?> - - - - <?php echo defined ("SITETITLE") ? SITETITLE : "SYP"?> - - - - - - - - - - - - - - - -
-
- - - diff --git a/js/admin.js b/js/admin.js index c7be3db..25e3e8c 100644 --- a/js/admin.js +++ b/js/admin.js @@ -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; } }, diff --git a/js/syp.js b/js/syp.js index 3228e62..7e69fb7 100644 --- 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 syp']; + var attributions = [SypStrings.propulsedByLink]; if (this.map && this.map.layers) { for(var i=0, len=this.map.layers.length; i/**/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 cf97679..cb484e5 100644 --- 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] -- 2.39.2