aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-10 20:41:18 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-10 20:41:18 +0000
commit042c524bab3ab401c99ed40c0df1641201f16f07 (patch)
tree9d148bb84c612f449a2360b255f81f89ecf125b6
parentc8c9a9fd02d4d971652d0c1facab9da26d2fab1c (diff)
downloadelgg-042c524bab3ab401c99ed40c0df1641201f16f07.tar.gz
elgg-042c524bab3ab401c99ed40c0df1641201f16f07.tar.bz2
Languages! There's a little more to do, but ...
git-svn-id: https://code.elgg.org/elgg/trunk@147 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--actions/login.php4
-rw-r--r--actions/logout.php4
-rw-r--r--engine/lib/languages.php97
-rw-r--r--languages/en.php19
4 files changed, 120 insertions, 4 deletions
diff --git a/actions/login.php b/actions/login.php
index cb25b1f0c..7323f1d4d 100644
--- a/actions/login.php
+++ b/actions/login.php
@@ -25,9 +25,9 @@
// Set the system_message as appropriate
if ($result) {
- system_message("You have been logged in.");
+ system_message(elgg_echo('login'));
} else {
- system_message("We couldn't log you in. Make sure your details are correct and please try again.");
+ system_message(elgg_echo('loginerror'));
}
?> \ No newline at end of file
diff --git a/actions/logout.php b/actions/logout.php
index fd550c5a4..273e8be48 100644
--- a/actions/logout.php
+++ b/actions/logout.php
@@ -17,9 +17,9 @@
// Set the system_message as appropriate
if ($result) {
- system_message("You have been logged out.");
+ system_message(elgg_echo('logout'));
} else {
- system_message("We couldn't log you out. We're not sure why, to be honest. Try again?");
+ system_message(elgg_echo('logouterror'));
}
?> \ No newline at end of file
diff --git a/engine/lib/languages.php b/engine/lib/languages.php
new file mode 100644
index 000000000..3161932fd
--- /dev/null
+++ b/engine/lib/languages.php
@@ -0,0 +1,97 @@
+<?php
+
+ /**
+ * Elgg language module
+ * Functions to manage language and translations.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Add a translation.
+ *
+ * Translations are arrays in the Zend Translation array format, eg:
+ *
+ * $english = array('message1' => 'message1', 'message2' => 'message2');
+ * $german = array('message1' => 'Nachricht1','message2' => 'Nachricht2');
+ *
+ * @param string $country_code Standard country code (eg 'en', 'nl', 'es')
+ * @param array $language_array Formatted array of strings
+ * @return true|false Depending on success
+ */
+
+ function add_translation($country_code, $language_array) {
+
+ global $CONFIG;
+ if (!isset($CONFIG->translations))
+ $CONFIG->translations = array();
+
+ $country_code = strtlower($country_code);
+ $country_code = trim($country_code);
+ if (is_array($language_array) && sizoef($language_array) > 0 && $country_code != "") {
+
+ if (!isset($CONFIG->translations[$country_code])) {
+ $CONFIG->translations[$country_code] = $language_array;
+ } else {
+ $CONFIG->translations[$country_code] = array_merge($CONFIG->translations[$country_code],$language_array);
+ }
+ return true;
+
+ }
+ return false;
+
+ }
+
+ /**
+ * Given a message shortcode, returns an appropriately translated full-text string
+ *
+ * @param string $message_key The short message code
+ * @param string $language Optionally, the standard language code (defaults to the site default, then English)
+ * @return string Either the translated string, or the original English string, or an empty string
+ */
+ function elgg_echo($message_key, $language = "") {
+
+ global $CONFIG;
+
+ if (empty($language))
+ $language = $CONFIG->language;
+
+ if (isset($CONFIG->translations[$country_code][$message_key])) {
+ return $CONFIG->translations[$country][$message_key];
+ } else if (isset($CONFIG->translations["en"][$message_key])) {
+ return $CONFIG->translations["en"][$message_key];
+ }
+
+ return "";
+
+ }
+
+ /**
+ * Function to load translation files on system boot. Parameters are standard event API parameters, but unused.
+ *
+ * @param unknown_type $event
+ * @param unknown_type $object_type
+ * @param unknown_type $object
+ */
+ function load_translations($event, $object_type, $object) {
+
+ global $CONFIG;
+ if ($handle = opendir($CONFIG->path . "languages/")) {
+ while ($language = readdir($handle)) {
+ if (!in_array($language,array('.','..','.svn','CVS')) && !is_dir($CONFIG->path . "/languages/" . $language)) {
+ //@include($CONFIG->path . "languages/" . $language);
+ }
+ echo $language;
+ }
+ }
+
+ }
+
+ register_event_handler("init","system","load_translations");
+
+?> \ No newline at end of file
diff --git a/languages/en.php b/languages/en.php
new file mode 100644
index 000000000..e0bc35523
--- /dev/null
+++ b/languages/en.php
@@ -0,0 +1,19 @@
+<?php
+
+ $english = array(
+
+ /**
+ * Sessions
+ */
+
+ 'login' => "You have been logged in.",
+ 'loginerror' => "We couldn't log you in. Make sure your details are correct and please try again.",
+
+ 'logout' => "You have been logged out.",
+ 'logouterror' => "We couldn't log you out. We're not sure why, to be honest. Try again?",
+
+ );
+
+ add_translation("en",$english);
+
+?> \ No newline at end of file