Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2006, 04:43 PM   PM User | #1
pallabmondal123
New to the CF scene

 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
pallabmondal123 is an unknown quantity at this point
Question Different language conversion

hi,

i am trying to change some text which is written in default language
i,e english language now i am want to change it language
like Deutsch ,English (UK),Italiano,Français etc.Is it possible
with the help of php?.
pallabmondal123 is offline   Reply With Quote
Old 01-03-2006, 09:36 PM   PM User | #2
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
This topic should be in the PHP section, and not the PHP Snippet section. Perhaps you misunderstood this sections name meaning. If you could, change your topic title to include (Move This) or something.

Anyway, you would need to creat seperate files, containing an array of phrases in each language, for example:

PHP Code:
// Array of phrases on language.en.inc
$phrase=array();
$phrase['good_afternoon'] = "Good Afternoon!";
$phrase['good_evening'] = "Good Evening!";
// ... etc. 
PHP Code:
// Array of phrases on language.de.inc
$phrase=array();
$phrase['good_afternoon'] = "Guten Tag!";
$phrase['good_evening'] = "Guten Abend!";
// ... etc. 
And then based by either a $_GET superglobal, or cookies, you would set the default language, like 'de' or 'en' then include the appropriate file... a simple example:

PHP Code:
<?php

$valid_languages 
= array('en''de');
if(isset(
$_GET['lng']) && in_array($_GET['lng'], $valid_languages)) {
  include(
"languages/language.".$_GET['lng'].".inc");
} else {
  include(
"languages/language.en.inc");
}

echo 
$phrase['good_evening'];

?>
Then you could test it by going to http://example.com/index.php?lng=de (Not a working example; an example URL of how it would beb used on your site.)

Last edited by Element; 01-03-2006 at 09:38 PM..
Element is offline   Reply With Quote
Old 01-03-2006, 10:15 PM   PM User | #3
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
Why reinvent the wheel?
http://uk.php.net/gettext
GJay is offline   Reply With Quote
Old 01-03-2006, 11:22 PM   PM User | #4
Diod
New Coder

 
Join Date: Dec 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Diod is an unknown quantity at this point
Because some people use english windows and speak dutch or so i guess
Diod is offline   Reply With Quote
Old 01-03-2006, 11:28 PM   PM User | #5
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
Quote:
Originally Posted by GJay
Why reinvent the wheel?
http://uk.php.net/gettext
Gettext is a PHP extension that must be added or compiled in...it's not enabled by default. You can emulate the functions, but thats slower, and without writing wrapper functions to test for the functions, and if they don't exist emulate them isn't worth the effort in most cases. I prefer to use language files or store the language in the database myself.
__________________
"$question = ( to() ) ? be() : ~be();"
Velox Letum is offline   Reply With Quote
Old 01-03-2006, 11:47 PM   PM User | #6
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
Not having the access to add the extension is a fair point I guess, no idea what diod meant (if it was a reply to me...)
If multi-language is really that important, then the effort of finding a host with it installed would probably be less than doing what was suggested :|
GJay is offline   Reply With Quote
Old 01-03-2006, 11:55 PM   PM User | #7
Diod
New Coder

 
Join Date: Dec 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Diod is an unknown quantity at this point
I mean that if im correct about the function of gettext, is that it checks what language your windows is; But if you have a english windows, then gettext thinks that u r english speaking, while u could be dutch speaking or so
Diod is offline   Reply With Quote
Old 01-04-2006, 12:25 AM   PM User | #8
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
You're not correct
You tell it what language you want to use in the script (so could be based on a DB value, or a $_GET var etc.)
GJay is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:27 AM.


Advertisement
Log in to turn off these ads.