From 1180c6dc56dba2b3938119584044c69c8de62725 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 27 Jun 2002 08:47:27 +0000 Subject: [PATCH] New languages system - get_string() in moodlelib. --- lang/en/help.picture.php | 17 ------- lang/en/help.text.php | 41 --------------- lang/en/strings.php | 12 +++++ lib/moodlelib.php | 91 ++++++++++++++++++++++++++++++++++ theme/standard/footer.html | 7 +-- theme/standardblue/footer.html | 7 +-- 6 files changed, 111 insertions(+), 64 deletions(-) delete mode 100644 lang/en/help.picture.php delete mode 100644 lang/en/help.text.php create mode 100644 lang/en/strings.php diff --git a/lang/en/help.picture.php b/lang/en/help.picture.php deleted file mode 100644 index 026cfcbb544..00000000000 --- a/lang/en/help.picture.php +++ /dev/null @@ -1,17 +0,0 @@ -

Uploading a picture

- -

You can upload a picture from your computer to this server, and this picture will be used in various places to represent you. -

For this reason, the best images to use are a close-up of your face, but you can use any image you like. -

The picture must be in JPG or PNG format (ie the names will usually end in .jpg or .png). -

You can get a picture file using one of four methods: - -

    -
  1. Using a digital camera, your photos will most likely already be on your computer in the right format. -
  2. You can use a scanner to scan a printed photograph. Make sure you save it as JPG or PNG format. -
  3. If you're artistic, you might draw a picture using a paint program. -
  4. Lastly, you can "steal" images from the web. http://images.google.com is a superb place to search for images. Once you find one, you can "right-click" on them with the mouse and choose "Save this image..." from the menu (different computers may vary slightly). -
- -

To upload the image, click the "Browse" button on this editing page, and select the image from your hard disk. -

Then click "Update my Profile" at the bottom - the image file will be cropped to a square and resized down to 100x100 pixels. -

When you are taken back to your profile page, the image might not appear to have changed. If this is so, just use the "Reload" button in your browser. diff --git a/lang/en/help.text.php b/lang/en/help.text.php deleted file mode 100644 index eb48fda494b..00000000000 --- a/lang/en/help.text.php +++ /dev/null @@ -1,41 +0,0 @@ -

Help on writing text

- -Writing text in Moodle works pretty much the way you would expect, but you also have the ability to include "smilies", "URL addresses" and some HTML tags in your text. - -

Smilies (emoticons)

- - -

URLs

- - -

HTML tags

- - - diff --git a/lang/en/strings.php b/lang/en/strings.php new file mode 100644 index 00000000000..90b97856538 --- /dev/null +++ b/lang/en/strings.php @@ -0,0 +1,12 @@ + diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 7fd6c0928f8..ba4fdb12f11 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1090,6 +1090,97 @@ function get_directory_list( $rootdir ) { return $dirs; } +/// STRING TRANSLATION //////////////////////////////////////// + +function get_string($identifier, $module="", $a="", $b="", $c="") { +// Return the translated string specified by $identifier as +// for $module. Uses the same format files as STphp. +// $a, $b and $c are optional variables that may be used +// within translation strings + + global $CFG, $USER; + + if (isset($USER->lang)) { // User language can override site language + $lang = $USER->lang; + } else { + $lang = $CFG->lang; + } + + if ($module == "" or $module == "moodle") { + $langpath = "$CFG->dirroot/lang"; + } else { + $langpath = "$CFG->dirroot/mod/$module/lang"; + } + + $langfile = "$langpath/$lang/strings.php"; + + if (!file_exists($langfile)) { // try English instead + $langfile = "$langpath/en/strings.php"; + if (!file_exists($langfile)) { + return "ERROR: No translation file found"; + } + } + + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + + eval($result); + return $resultstring; + + } else { + if ($lang == "en") { + return "ERROR: Translation string '$identifier' is missing!"; + + } else { // Try looking in the english file. + $langfile = "$langpath/en/strings.php"; + if (!file_exists($langfile)) { + return "ERROR: No translation file found"; + } + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + eval($result); + return $resultstring; + } else { + return "ERROR: Translation string '$identifier' is missing!"; + } + } + } +} + + +function get_string_variable_list($string) { +// This function is only used from get_string_from_file(). + if (empty ($string)) + return; + + // Match on all variables in $string + $count = preg_match_all("/\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/", + $string, $matches); + + // Return array of matches ($matches[0] is most useful) + return $matches; +} + + +function get_string_from_file($identifier, $langfile, $destination) { +// This function is only used from get_string(). + include ($langfile); + + if (!isset ($string[$identifier])) { + return false; + } + + $value = "sprintf(\"".$string[$identifier]."\");"; + $variables = get_string_variable_list($value); + if (empty($variables[0])) + return "$destination = $value"; + else { + foreach ($variables[0] as $variable) { + $variablecheck .= "if (!isset ($variable))\n" . + "die (\"Variable specified in translation " . + "not set.\");\n"; + } + return "$variablecheck $destination = $value"; + } +} /// ENCRYPTION //////////////////////////////////////////////// diff --git a/theme/standard/footer.html b/theme/standard/footer.html index 5645faa7d15..a90488d001a 100644 --- a/theme/standard/footer.html +++ b/theme/standard/footer.html @@ -4,10 +4,11 @@

id) { - echo "You are logged in as $USER->firstname $USER->lastname."; - echo "(wwwroot/login/logout.php\">Logout)"; + echo get_string("loggedinas", "moodle", "$USER->firstname $USER->lastname"); + echo " (wwwroot/login/logout.php\">".get_string("logout").")"; } else { - echo "You are not logged in. wwwroot/login/\">Log in here."; + echo get_string("loggedinnot", "moodle"); + echo " (wwwroot/login/\">".get_string("login").")"; } ?>

diff --git a/theme/standardblue/footer.html b/theme/standardblue/footer.html index 5645faa7d15..a90488d001a 100644 --- a/theme/standardblue/footer.html +++ b/theme/standardblue/footer.html @@ -4,10 +4,11 @@

id) { - echo "You are logged in as $USER->firstname $USER->lastname."; - echo "(wwwroot/login/logout.php\">Logout)"; + echo get_string("loggedinas", "moodle", "$USER->firstname $USER->lastname"); + echo " (wwwroot/login/logout.php\">".get_string("logout").")"; } else { - echo "You are not logged in. wwwroot/login/\">Log in here."; + echo get_string("loggedinnot", "moodle"); + echo " (wwwroot/login/\">".get_string("login").")"; } ?>