[ghelda-devel] [53] Finally native this time ? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/ghelda-devel Archives
]
Revision: 53
Author: odyx
Date: 2009-07-21 17:23:39 +0200 (Tue, 21 Jul 2009)
Log Message:
-----------
Finally native this time ?
Modified Paths:
--------------
trunk/core/config.php
trunk/init/gettext.php
Added Paths:
-----------
trunk/inc/g_gettext.php
Modified: trunk/core/config.php
===================================================================
--- trunk/core/config.php 2009-07-21 14:44:10 UTC (rev 52)
+++ trunk/core/config.php 2009-07-21 15:23:39 UTC (rev 53)
@@ -34,11 +34,9 @@
$conf['Output']['incrementChar'] = " ";
$conf['localeNames']= array(
- "en.UTF-8" => "english",
- "fr.UTF-8" => "français",
- "vd.UTF-8" => "vaudois",
- "de.UTF-8" => "deutsch",
+ "C" => "english",
+ "fr_CH.utf8" => "français",
);
-?>
\ No newline at end of file
+?>
Added: trunk/inc/g_gettext.php
===================================================================
--- trunk/inc/g_gettext.php (rev 0)
+++ trunk/inc/g_gettext.php 2009-07-21 15:23:39 UTC (rev 53)
@@ -0,0 +1,72 @@
+<?php
+/*
+ * Ghelda - Gestion Hiérarchisée En Ligne D'Adresses
+ * - Online Hierarchical Handling Of Adresses
+ *
+ * Copyright (C) 2009 Didier Raboud
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+function g_setDomain($newDomain)
+{
+ global $g_GT_locale;
+
+ $LocaleDomain = g_setLocaleAndDomain($g_GT_locale,$newDomain);
+
+ return $LocaleDomain[1];
+}
+
+function g_setLocale($newLocale)
+{
+ global $g_GT_domain,$cookieCode,$g_H_Auth;
+
+ // Register it on the user's side
+ setcookie($cookieCode,$newLocale);
+ // And on the server's side
+ $g_H_Auth->setLocale($newLocale);
+
+ $LocaleDomain = g_setLocaleAndDomain($newLocale,$g_GT_domain);
+
+ return $LocaleDomain[0];
+}
+
+function g_getLocale()
+{
+ global $g_GT_locale;
+ return $g_GT_locale;
+}
+
+function g_setLocaleAndDomain($newLocale,$newDomain)
+{
+ global $g_GT_locale,$g_GT_domain;
+
+ // Store the actual locale and domain
+ $g_GT_oldLocale = $g_GT_locale;
+ $g_GT_oldDomain = $g_GT_domain;
+ // Set the new ones
+ $g_GT_locale = $newLocale;
+ $g_GT_domain = $newDomain;
+
+ // gettext setup
+ T_setlocale(LC_MESSAGES, $g_GT_locale);
+ T_bindtextdomain($g_GT_domain, LOCALE_DIR);
+ T_bind_textdomain_codeset($g_GT_domain, substr($g_GT_locale, strpos($g_GT_locale,'.')+1));
+ T_textdomain($g_GT_domain);
+
+ return array($g_GT_oldLocale,$g_GT_oldDomain);
+}
+
+?>
+
Modified: trunk/init/gettext.php
===================================================================
--- trunk/init/gettext.php 2009-07-21 14:44:10 UTC (rev 52)
+++ trunk/init/gettext.php 2009-07-21 15:23:39 UTC (rev 53)
@@ -3,7 +3,7 @@
* Ghelda - Gestion Hiérarchisée En Ligne D'Adresses
* - Online Hierarchical Handling Of Adresses
*
- * Copyright (C) 2008 Didier Raboud
+ * Copyright (C) 2008-2009 Didier Raboud
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -20,55 +20,27 @@
*/
require_once "php-gettext/gettext.inc";
+require_once "inc/g_gettext.php";
// Create the gettext handling environment
define('LOCALE_DIR', realpath('./locale'));
define('LOCALE_DEFAULT','C');
-function g_setDomain($newDomain)
-{
- global $g_GT_locale;
-
- return g_GT_setLocaleDomain($g_GT_locale,$newDomain);
-}
+$g_GT_locale = LOCALE_DEFAULT;
-function g_setLocale($newLocale)
-{
- global $g_GT_domain;
-
- return g_GT_setLocaleDomain($newLocale,$g_GT_domain);
-}
-function g_GT_setLocaleDomain($newLocale,$newDomain)
-{
- global $g_GT_locale,$g_GT_domain;
-
- // Store the actual locale and domain
- $g_GT_oldLocale = $g_GT_locale;
- $g_GT_oldDomain = $g_GT_domain;
- // Set the new ones
- $g_GT_locale = $newLocale;
- $g_GT_domain = $newDomain;
-
- // gettext setup
- T_setlocale(LC_MESSAGES, $g_GT_locale);
- T_bindtextdomain($g_GT_domain, LOCALE_DIR);
- T_bind_textdomain_codeset($g_GT_domain, substr($g_GT_locale, strpos($g_GT_locale,'.')+1));
- T_textdomain($g_GT_domain);
-
- return array($g_GT_oldLocale,$g_GT_oldDomain);
-}
// TODO: Use Pear::HTTP
// Get the list of supported locales
$g_GT_supportedLocales = scandir(LOCALE_DIR,1);
// Strip the "." and ".." entries and add the default one
-$g_GT_supportedLocales = array_diff($g_GT_supportedLocales,array(".","..",".svn",".git","templates"));
+$g_GT_supportedLocales = array_diff($g_GT_supportedLocales,array(".","..",".svn","templates"));
// Strip out cache files
function filtCache($str) { return (substr($str,-1) != '~');}
$g_GT_supportedLocales = array_filter($g_GT_supportedLocales,'filtCache');
$g_GT_supportedLocales[] = LOCALE_DEFAULT;
+
// Get the registered user locale
$g_GT_userLocale = $g_H_Auth->getAuthData('locale');
@@ -94,13 +66,13 @@
// Define the locale
if(isset($g_GT_urlLocale)) {
- $g_GT_locale = $g_GT_urlLocale;
+ $locale = $g_GT_urlLocale;
} elseif (!empty($g_GT_userLocale)) {
- $g_GT_locale = $g_GT_userLocale;
+ $locale = $g_GT_userLocale;
} elseif (isset($g_GT_cookieLocale)) {
- $g_GT_locale = $g_GT_cookieLocale;
+ $locale = $g_GT_cookieLocale;
} else {
- $g_GT_locale = LOCALE_DEFAULT;
+ $locale = LOCALE_DEFAULT;
// Get the language given by the "Accept-Language" HTTP header
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
// Create the list of charsets
@@ -121,9 +93,9 @@
$languages[$lang] = $q;
}
arsort($languages,SORT_NUMERIC);
-
- $charsetsToUpper['utf'] = "UTF-8";
+ $charsetsToUpper['utf'] = "UTF-8";
+
// Assume that both arrays are already sorted in descending order (of q) (THEY ARE NOT) TODO
$i = 0; $found = false;
@@ -132,7 +104,7 @@
$charset = array_key_exists($charset[0],$charsetsToUpper) ? $charsetsToUpper[$charset[0]] : $charset[0];
$localeName = $lang[0].'.'.$charset;
if(array_search($localeName,$g_GT_supportedLocales) !== false) {
- $g_GT_locale = $localeName;
+ $locale = $localeName;
$found = true;
break;
}
@@ -144,20 +116,13 @@
}
// header += "Accept-Language: " + m_request.languages + ";q=0.1\r\n";
-//gold('Emulation ? : ',locale_emulation());
-// Register it on the user's side
-setcookie($cookieCode,$g_GT_locale);
-// And on the server's side
-$g_H_Auth->setLocale($g_GT_locale);
-// ... and the domain
-$g_GT_domain = 'g_core';
-
-// TODO: Use accept-to-gettext.inc
-
// Set the domain
-g_setDomain($g_GT_domain);
+g_setDomain('g_core');
+// Set the locale
+g_setLocale($locale);
+
/*
$coreDomain = g_setDomain("g_plugin123");
echo T_("Intent");
@@ -165,3 +130,4 @@
// */
?>
+