Date: 11/03/99
- Next message: kk: "[PHPLIB-DEV] cvs commit"
- Previous message: kk: "[PHPLIB-DEV] cvs commit"
- Next in thread: kk: "[PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: negro
Date: Wed Nov 3 14:47:29 1999
Modified files:
php-lib/unsup/i18n/language.inc
Log message:
Added some comments and provided a better handling of the global variable
used to change the current language.
Index: php-lib/unsup/i18n/language.inc
diff -u php-lib/unsup/i18n/language.inc:1.1 php-lib/unsup/i18n/language.inc:1.2
--- php-lib/unsup/i18n/language.inc:1.1 Tue Nov 2 12:11:16 1999
+++ php-lib/unsup/i18n/language.inc Wed Nov 3 14:46:58 1999
@@ -3,19 +3,23 @@
## Copyright (c) 1999 Internet Images Srl
## Massimiliano Masserelli
##
-## $Id: language.inc,v 1.1 1999/11/02 11:11:16 negro Exp $
+## $Id: language.inc,v 1.2 1999/11/03 13:46:58 negro Exp $
##
class Language {
var $classname = "Language";
var $persistent_slots = array("CurrentLanguage", "AcceptedLanguages");
- var $CurrentLanguage;
- var $AcceptedLanguages = array(); # hashed array "short"=>"locale"
+ var $CurrentLanguage; ## Holds the current language
+ var $AcceptedLanguages = array(); ## Hashed array of allowed locales
+ ## in the form "short"=>"locale"
+ ## (ie: "en"=>"en-US")
- var $clangdir = "lang"; # Dir with compiled language files (dbm format)
+ var $clangdir = "./lang"; # Dir with compiled language files (dbm format)
var $debuglevel = 0;
+ var $language_selection = "LangSel"; ## Name of a global var used to
+ ## select the current language.
function init($default, $accepted) {
$this->AcceptedLanguages = array();
@@ -54,9 +58,18 @@
}
function Check() {
- global $LangSel;
- if (($LangSel) && ($LangSel != $this->CurrentLanguage)) {
- if ($this->SetLanguage($LangSel)) {
+ global $QUERY_STRING;
+ $lsn = $this->language_selection;
+ if (! empty($QUERY_STRING)) {
+ if ($nq = ereg_replace(
+ "(^|&)".quotemeta(urlencode($this->language_selection))."=[a-z]+(&|$)",
+ "\\1", $QUERY_STRING)) {
+ $QUERY_STRING = ereg_replace("(^&)|(&$)", "", $nq);
+ }
+ }
+ global $$lsn;
+ if (($$lsn) && ($$lsn != $this->CurrentLanguage)) {
+ if ($this->SetLanguage($$lsn)) {
if ($this->dbhandle) {
dbmclose($this->dbhandle);
unset($this->dbhandle);
@@ -71,6 +84,7 @@
return true;
}
+ ## This methods returns a string translated in current locale
function String($keyword) {
if (($this->Check()) && ($string = dbmfetch($this->dbhandle, $keyword))) {
return $string;
@@ -79,10 +93,12 @@
}
}
+ ## Shorthand
function f($keyword) {
return $this->String($keyword);
}
+ ## Shorthand
function p($keyword) {
printf("%s", $this->String($keyword));
return true;
@@ -95,24 +111,39 @@
return true;
}
+ ## Sets the current locale for using in locale-enabled PHP3 functions
function setlocale() {
$this->Check();
return setlocale(LC_ALL, $this->AcceptedLanguages[$this->CurrentLanguage]);
}
+ ## Resets the standard locale in order to avoid problems with logging
+ ## and other locale related undesiderable behaviours. See the PHP3
+ ## bug database for further informations.
function resetlocale() {
return setlocale(LC_ALL, "C");
}
}
- function _($keyword) {
- global $lang;
- return $lang->f($keyword);
- }
+ ##
+ ## Global functions, to minimize the impact on the readability of the
+ ## HTML code. The _() mimics the GNU gettext suggested macro, _P()
+ ## is used to print the string, and is to be used mostly in "plain"
+ ## HTML code.
+ ##
+ ## Those functions are provided as example, and are commented out
+ ## to avoid pollution of the name space. You are encouraged to
+ ## uncomment them or provide similar shorthands in your code.
+ ##
+
+ #function _($keyword) {
+ # global $lang;
+ # return $lang->f($keyword);
+ #}
- function _P($keyword) {
- global $lang;
- return $lang->p($keyword);
- }
+ #function _P($keyword) {
+ # global $lang;
+ # return $lang->p($keyword);
+ #}
?>
-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.
- Next message: kk: "[PHPLIB-DEV] cvs commit"
- Previous message: kk: "[PHPLIB-DEV] cvs commit"
- Next in thread: kk: "[PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

