Hi! Here is my solution to globalization. It works good, if you only need a few languages It uses simple markup for html and php strings.
Hope this helps. usages: require_once( 'localize.inc"); // see belo 1. loc( "en|In English|ru|In Russian|fr|Franci... i don't speak this language actually :)", "ru" /*this argument can be skipped*/); Use this notation, if you work with internal strings, such as SQL or PHP strings. It's quite simple even for non-programmers (editors and translators) to use this markup. 2. localize( "<p>Following text is in your language: <glob>en|In English|ru|In Russian</glob></p>, "en" ); Use this notation for HTML 3. print(localize(implode( "", file("myfile_globalized.html")), $_REQUEST['locale'])); you can now call this file: http://localhost/site/myfile.php?locale=en do not send a file name in arguments, because it violates sequrity example of globalized file: ------------------------------------ <html> <head> <title><glob>en|My Document - English|ru|My Document - Russian</glob></title> </head> <body> <a href="<glob>en|english.htm|ru|russian.htm</glob>"><glob>en|In English|ru|In Russian</glob></a> </body> </html> ------------------------------------ These <glob> tags are not well formed xml tags! Current limitation is that <glob></glob> tag cannot span multiple lines I'm using "UTF-8 without signature" encoding for all my html and php files ------------------------------------------------------- localize.inc <?php $default_locale = "en"; function defLocale() { global $default_locale; return $default_locale; } // add other locales, as you need $supported_loc = explode(" ", "ru en" ); function search_loc($ag_str) { global $supported_loc; while( list($k, $al) = each( $supported_loc ) ) { if ( preg_match( "/". $al ."/", $ag_str ) ) return $k; } return null; } function setup_user_locale() { session_start(); global $default_locale; global $supported_loc; session_start(); // session_destroy(); // for debug purposes $key = null; global $lang_changed; if ( isset($_SESSION['lang']) && isset($_REQUEST['lang']) && ( $_SESSION['lang'] != $_REQUEST['lang'] ) ) $lang_changed = TRUE; else $lang_changed = FALSE; if ( isset( $_REQUEST['lang'] ) ) { if ( $_REQUEST['lang']!= '') { $key = search_loc( $_REQUEST['lang'] ); $_SESSION['lang']=$_REQUEST['lang']; } } if ( isset( $_SESSION['lang'] ) & ! isset( $key ) ) { if ( $_SESSION['lang']!= '' ) { $key = search_loc( $_SESSION['lang'] ); } } if ( ! isset($key) ) { $key = search_loc( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); } if ( isset($key) ) $default_locale = $supported_loc[ $key ]; else $default_locale = "en"; } function loc_try( $in, $required_locale = null ) { global $default_locale; if ( ! $required_locale ) { $required_locale = $default_locale; } $out = ""; // $myPattern = '/('. $required_locale .'\|)([^(\|<)]+)/'; $myPattern = '/('. $required_locale .'\|)([^(\|)]+)/'; preg_match( $myPattern, $in, $matches ); return (count($matches) == 0) ? null : $matches[2]; } $all_language_dog = "en|text is not translated to your language|ru|????? ?? ????????? ?? ??? ????"; // USAGE: loc( "en|In English|ru|In Russian" ); // function loc( $in, $required_locale = null ) { global $all_language_dog; $good = loc_try($in,$required_locale); if ( ! $good ) { $last_chance = loc_try( $in, "en" ); return ($last_chance) ? $last_chance : loc( $all_language_dog, $required_locale ); } else { return $good; } } // syntax: localize( "<glob>en|In English|ru|In Russian</glob>" ); // this function is useful for entire html/xml files // contents of myfile.php // // require( 'localize.inc' ); // print(localize(implode( "", file("myfile_globalized.html")), $_REQUEST['locale']));// // // USAGE: http://www.qqq.org/myfile_localized.php?&locale=ru function localize( $str, $required_locale = null ) { global $default_locale; if ( ! $required_locale ) { $required_locale = $default_locale; } return preg_replace( "/(<glob>)(.+)(<\/glob>)/eU", "loc('\\2','$required_locale')", $str ); } setup_user_locale(); ?> ------------------------------------------------------------ end of localize.inc ------------------------------------------ localize_test.php <?php // ?? ?????? require( "localize.inc" ); function mix_query( $new_disasm ) { $old_disasm = array(); parse_str( $_SERVER['QUERY_STRING'], $old_disasm ); $super_query = array_merge( $old_disasm, $new_disasm ); $out = array(); foreach( $super_query as $key => $val ) { if ( $val != "" ) array_push( $out, $key . '=' . $val ); } $out = implode( "&", $out ); return $out; } function mix_path( $new_disasm ) { return path() . '?' . mix_query( $new_disasm ); } function path() { $p = parse_url( $_SERVER['PATH_INFO'] ); return $p['path']; } function switch_language() { global $supported_loc; $language_name = array( "en" => "English", "ru" => "Russian" ); ?> <table border="0" cellpadding=0 cellspacing=0> <tr> <td bgcolor="white"> language </td> <?php foreach ( $supported_loc as $loc ) { ?> <td bgcolor="<?php print( ($loc == defLocale() )? "c0c0c0" : "d0d0d0" ); ?>"> <?php print ( ( $loc == defLocale() ) ? ":[".$language_name[$loc]."]:" : "<a href=\"". mix_path( array( 'lang' => $loc ) ) ."\">". "::" .$language_name[$loc]."::"."</a>" ); ?> </td> <?php } ?> </tr> </table> <?php } ?> <html> <head><title><?php print ( loc( "en|English|ru|Russian" ) ); ?></title> </head> <body> <pre> <?php switch_language(); ?> </pre> <?php print ( localize( "This is in English.<font color=\"green\"><glob>en|And this is in <b>your</b> requested language|ru|Russian Bla bla bla</glob></font>. Yeah" ) ); ?> </body> </html> ------------------------------------------- end localize_test.php "Steve Vernon" <[EMAIL PROTECTED]> wrote in message 000001c29558$78490ff0$2cfd87d9@extreme">news:000001c29558$78490ff0$2cfd87d9@extreme... > Hmmmm, > This seems to be harder than I thought! > > Thanks everyone for there help! > > Carl this IBM international thing is very interesting, and many thanks > for telling me about it. Just think it is a lot of work, especially since I > want my site to be on in January, not sure I can manage this with my other > tasks. I will try and research it and maybe use it in the future. > > Im probably going to use the Get Text, that Moriyoshi mentioned. Thanks! > > Basically Im an ameture at this international stuff, Iv'e never worked > on an international project and no idea where to start. I could really do > with some advice. > > I am hosting my site in Germany, and need to know what to tell the > server admin people. What should I tell them about MySQL and Apache and PHP > set up please (on linux). > > And for my website, I assumed that you just alter the doctype say from > <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"> (im using 3.2 but had > this to hand!) to the equivalent French one. Is this wrong? Do I need to > specfy character sets and encoding?? > > Many Thanks, > > Steve > > > Steve, > > > > A couple of years ago I developed extensions for PHP that sound like what > > you want. It used ICU http://oss.software.ibm.com/icu/ to provide the > i18n > > services for PHP. > > > > First it also provided an override to the Apache mod_mime services to > allow > > it to work like other web servers and allow you to put different language > > web pages in different subdirectories rather than require a language type > on > > each page. You can have it override just certain types such as .php pages > > only. > > > > This way you can have: > > > > ../site/en/contents/page.php > > ../site/fr/contents/page.php > > > > or full locales > > > > ../site/en-uk/contents/page.php > > ../site/en-us/contents/page.php > > ../site/en-ca/contents/page.php > > ../site/fr-fr/contents/page.php > > ../site/fr-ca/contents/page.php > > > > It sets the locale on a per transaction bases. It will not only work with > > Unicode with ICU but it will also work in code pages. > > > > You can have a terminal using Shift-JIS and Japanese pages in EUC and > access > > a UTF-8 database. The same code will work with any code page or Unicode. > > > > You can see code that I derived from the ICU interface portion of the code > > at http://www.xnetinc.com/xiua/ > > > > The PHP changes also included a way to support charset more dynamically. > > > > Carl > > > > > > > > > > > > > > > > > > > -----Original Message----- > > > From: Steve Vernon [mailto:[EMAIL PROTECTED]] > > > Sent: Sunday, November 24, 2002 7:20 AM > > > To: [EMAIL PROTECTED] > > > Subject: [PHP-I18N] Multiple Languages > > > > > > > > > Hiya, > > > I'm working on my first international PHP project, which is a > > > site that > > > displays differently in different languages. So I guess this is > > > the place to > > > ask adive. > > > > > > Ive done the code with flags etc so people can select the > > > country and so > > > the language. But im not sure about the best way to handle the text and > > > things such as meta tages. > > > > > > My origional idea was to have multiple include files named > > > like uk.php, > > > french.php with seperate variables for the text parts, or do sommat in > XML > > > which is basically the same. > > > > > > I cant find any sources on the net about best ways to do a site like > > > this. > > > > > > Help! > > > > > > Thanks, > > > > > > Steve > > > > > > > > > -- > > > PHP Internationalization Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > -- > > PHP Internationalization Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP Internationalization Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php