i18n officially ready for prime time.

This commit is contained in:
Mike Macgirvin 2010-10-06 17:40:58 -07:00
parent 9f0cedad8e
commit c7c3db8c54
4 changed files with 52 additions and 5 deletions

View file

@ -169,6 +169,15 @@ class App {
}} }}
// retrieve the App structure
// useful in functions which require it but don't get it passed to them
if(! function_exists('get_app')) {
function get_app() {
global $a;
return $a;
}};
// Multi-purpose function to check variable state. // Multi-purpose function to check variable state.
// Usage: x($var) or $x($array,'key') // Usage: x($var) or $x($array,'key')
@ -269,19 +278,21 @@ function replace_macros($s,$r) {
// load string tranlsation table for alternate language // load string tranlsation table for alternate language
// not yet implemented
if(! function_exists('load_translation_table')) { if(! function_exists('load_translation_table')) {
function load_translation_table($lang) { function load_translation_table($lang) {
global $a; global $a;
if(file_exists("view/$lang/strings.php"))
include("view/$lang/strings.php");
}} }}
// translate string if translation exists // translate string if translation exists
if(! function_exists('t')) { if(! function_exists('t')) {
function t($s) { function t($s) {
global $a;
$a = get_app();
if($a->strings[$s]) if($a->strings[$s])
return $a->strings[$s]; return $a->strings[$s];

View file

@ -1,6 +1,27 @@
<?php <?php
// Included here for completeness, but this is a very dangerous operation.
// It is the caller's responsibility to confirm the requestor's intent and
// authorisation to do this.
function user_remove($uid) {
q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
if($uid == get_uid()) {
unset($_SESSION['authenticated']);
unset($_SESSION['uid']);
killme();
}
}
function contact_remove($id) { function contact_remove($id) {

View file

@ -6,11 +6,15 @@ $a = new App;
$debug_text = ''; // Debugging functions should never be used on production systems. $debug_text = ''; // Debugging functions should never be used on production systems.
// Setup the database. // Setup the language and database.
$install = ((file_exists('.htconfig.php')) ? false : true); $install = ((file_exists('.htconfig.php')) ? false : true);
@include(".htconfig.php"); @include(".htconfig.php");
if(x($lang))
load_translation_table($lang);
require_once("dba.php"); require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install); $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data);

View file

@ -10,7 +10,11 @@ tinymce, simplepie, and the HTML parsers.
In order for extract to do its job, every use of the t() translation function In order for extract to do its job, every use of the t() translation function
must be preceded by one space. The string also can not contain parentheses. If must be preceded by one space. The string also can not contain parentheses. If
parens are required in a string, please use hex escapes. parens are required in a string which requires translation, please use hex escapes.
\x28 = (
\x29 = )
strings.php - a recent run of the strings program. This provides output that strings.php - a recent run of the strings program. This provides output that
is suitable for direct inclusion in the program once the app has been is suitable for direct inclusion in the program once the app has been
@ -19,7 +23,14 @@ initialised.
There are also translatable strings in the various files in the view There are also translatable strings in the various files in the view
directory. By setting $lang = 'something' in .htconfig.php, the application directory. By setting $lang = 'something' in .htconfig.php, the application
will search for view/something/filename prior to the English version in will search for view/something/filename prior to the English version in
view/filename when loading templates and view files. view/filename when loading templates and view files. The translated string table
should be placed in view/$lang/strings.php for automatic inclusion.
You are not restricted to using known languages. You may also use this to
translate the software into "pirate", "surfer" or merely to replace certain
text which you don't care for.