[PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread Jeff Benetti
I'm a noob so keep the comments to a noob's level please.

I am doing a website and my client wants the bulk of the text to be
bilingual (French and English).  The last site I did used php and mysql so I
am getting comfortable with that technology.  Typically I am using a single
php file and my menu constantly points to the same file with different id
options example index.php?id=30 and I want to use the same idea to choose
a language example index.php?lang=frid=30.  Pretty straight forward for
many of you folks but before I start reinventing the wheel I wondered if
anyone could offer any suggestions.  I have a couple of approaches in mind.

1: Session vars, I have never used this but it seems straight forward.
Drawbacks?
2: Cookies again not too big a deal, never used cookies either but it
doesn't seem to be mystifying however the fact that the user can turn
cookies off makes me not want to go this route.
3: Use the mysql database and log each ip address and record the preference
and maybe the last time on the site.  I am leaning in this direction because
I think it is the most robust but will it be slow?  First I have to get the
ip then I have to check to see if it is in my data base and then get the
language preference.  It would be great to have a standardized function that
I could use on all of my sites.  I live in a bilingual country (Canada) so
this could be a real selling point for my services.

Any any and all comments are welcome, it will be a learning curve no matter
which route I take so a little advice on the best direction pros cons would
be great.

And of course knowing that I will have many many thousands of people on my
site (hee hee) which option will perform best once I start accumulating
vistors.  That's one problem I see with the mysql solution, I think it may
start to be slow unless I start purging vistors who have not shown up in a
while or limit the number of entries.

Thanks,
Jeff

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread Jason Pruim


On Nov 27, 2007, at 8:37 AM, Jeff Benetti wrote:


I'm a noob so keep the comments to a noob's level please.

I am doing a website and my client wants the bulk of the text to be
bilingual (French and English).  The last site I did used php and  
mysql so I
am getting comfortable with that technology.  Typically I am using a  
single
php file and my menu constantly points to the same file with  
different id
options example index.php?id=30 and I want to use the same idea to  
choose
a language example index.php?lang=frid=30.  Pretty straight  
forward for
many of you folks but before I start reinventing the wheel I  
wondered if
anyone could offer any suggestions.  I have a couple of approaches  
in mind.




I'm actually in the process of planning this as well... English and  
Spanish...



1: Session vars, I have never used this but it seems straight forward.
Drawbacks?


Sessions are easy enough to use, just make sure that you are setting  
the variable in the right place... On a site I did the stored variable  
was always 1 behind what I wanted it to be... I moved the setting of  
the variable, and it worked :)


2: Cookies again not too big a deal, never used cookies either but it
doesn't seem to be mystifying however the fact that the user can turn
cookies off makes me not want to go this route.
3: Use the mysql database and log each ip address and record the  
preference
and maybe the last time on the site.  I am leaning in this direction  
because
I think it is the most robust but will it be slow?  First I have to  
get the
ip then I have to check to see if it is in my data base and then get  
the
language preference.  It would be great to have a standardized  
function that
I could use on all of my sites.  I live in a bilingual country  
(Canada) so

this could be a real selling point for my services.


I don't know much about using mysql for storing IP's in canada... But  
in the US, all IP's except for businesses are dynamic, they could  
change every time a user would go to a site.. I could see that causing  
issues...





Any any and all comments are welcome, it will be a learning curve no  
matter
which route I take so a little advice on the best direction pros  
cons would

be great.

And of course knowing that I will have many many thousands of people  
on my
site (hee hee) which option will perform best once I start  
accumulating
vistors.  That's one problem I see with the mysql solution, I think  
it may
start to be slow unless I start purging vistors who have not shown  
up in a

while or limit the number of entries.


I'm currently planning to store the text of the pages on my site in a  
database, so that I can very easily just change the language  
preference, and get the english, or spanish out of the database. I  
also think it will help speed up the site for when I have my thousands  
of users a second :)


When you start doing it, let me know your experiences... I plan to  
actually start coding (If me and the site owner can see eye to eye on  
some stuff...) in january.



--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread Andrés Robinet
We use something similar to the following

define('DEFAULT_LANG_ID', 'en');

function getLanguageId() {
  // Allow for language id override in $_GET, $_POST and $_COOKIE
  $req_lang_id = $_REQUEST['lang_id'];
  // Retrieve the one stored in the session if any
  $sess_lang_id = $_SESSION['lang_id'];
  // $lang_id will contain the lang id retrieved from request (overrides
session),
  // or from session or a default one
  $lang_id = isset($req_lang_id) ? $req_lang_id : (isset($sess_lang_id) ?
$sess_lang_id : DEFAULT_LANG_ID);
  // Save it for next time
  $_SESSION['lang_id'] = $lang_id;
  return $lang_id;
}

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-diy.com

 -Original Message-
 From: Jason Pruim [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, November 27, 2007 11:15 AM
 To: Jeff Benetti
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Newbie asks about multi-lingual website strategies
 
 
 On Nov 27, 2007, at 8:37 AM, Jeff Benetti wrote:
 
  I'm a noob so keep the comments to a noob's level please.
 
  I am doing a website and my client wants the bulk of the text to be
  bilingual (French and English).  The last site I did used php and
  mysql so I
  am getting comfortable with that technology.  Typically I am using a
  single
  php file and my menu constantly points to the same file with
  different id
  options example index.php?id=30 and I want to use the same idea to
  choose
  a language example index.php?lang=frid=30.  Pretty straight
  forward for
  many of you folks but before I start reinventing the wheel I
  wondered if
  anyone could offer any suggestions.  I have a couple of approaches
  in mind.
 
 
 I'm actually in the process of planning this as well... English and
 Spanish...
 
  1: Session vars, I have never used this but it seems straight
 forward.
  Drawbacks?
 
 Sessions are easy enough to use, just make sure that you are setting
 the variable in the right place... On a site I did the stored variable
 was always 1 behind what I wanted it to be... I moved the setting of
 the variable, and it worked :)
 
  2: Cookies again not too big a deal, never used cookies either but it
  doesn't seem to be mystifying however the fact that the user can turn
  cookies off makes me not want to go this route.
  3: Use the mysql database and log each ip address and record the
  preference
  and maybe the last time on the site.  I am leaning in this direction
  because
  I think it is the most robust but will it be slow?  First I have to
  get the
  ip then I have to check to see if it is in my data base and then get
  the
  language preference.  It would be great to have a standardized
  function that
  I could use on all of my sites.  I live in a bilingual country
  (Canada) so
  this could be a real selling point for my services.
 
 I don't know much about using mysql for storing IP's in canada... But
 in the US, all IP's except for businesses are dynamic, they could
 change every time a user would go to a site.. I could see that causing
 issues...
 
 
 
  Any any and all comments are welcome, it will be a learning curve no
  matter
  which route I take so a little advice on the best direction pros
  cons would
  be great.
 
  And of course knowing that I will have many many thousands of people
  on my
  site (hee hee) which option will perform best once I start
  accumulating
  vistors.  That's one problem I see with the mysql solution, I think
  it may
  start to be slow unless I start purging vistors who have not shown
  up in a
  while or limit the number of entries.
 
 I'm currently planning to store the text of the pages on my site in a
 database, so that I can very easily just change the language
 preference, and get the english, or spanish out of the database. I
 also think it will help speed up the site for when I have my thousands
 of users a second :)
 
 When you start doing it, let me know your experiences... I plan to
 actually start coding (If me and the site owner can see eye to eye on
 some stuff...) in january.
 
 
 --
 
 Jason Pruim
 Raoset Inc.
 Technology Manager
 MQC Specialist
 3251 132nd ave
 Holland, MI, 49424
 www.raoset.com
 [EMAIL PROTECTED]
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread Jochem Maas
your all missing something, namely that the browser can tell you what
it's preferred language is (which you can use to select a language in the event
no language has yet been determined for the current session).

you do this by parsing the value of the HTTP_ACCEPT_LANGUAGE request header.
HTTP_ACCEPT_LANGUAGE is in the form: en-us,en,fr,nl,nl-be;q=0.5

?php

// following if statement exists for testing this code on the command line
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us,en,fr,nl,nl-be;q=0.5';

$lLangs = explode(',', preg_replace('#;.*$#', '', 
$_SERVER['HTTP_ACCEPT_LANGUAGE']));
$sLangs = array_unique(array_map('substr', $lLangs, array_fill(0, 
count($lLangs), 0), array_fill(0, count($lLangs), 2)));

var_dump($lLangs, $sLangs);

Andrés Robinet wrote:
 We use something similar to the following
 
 define('DEFAULT_LANG_ID', 'en');
 
 function getLanguageId() {
   // Allow for language id override in $_GET, $_POST and $_COOKIE
   $req_lang_id = $_REQUEST['lang_id'];
   // Retrieve the one stored in the session if any
   $sess_lang_id = $_SESSION['lang_id'];
   // $lang_id will contain the lang id retrieved from request (overrides
 session),
   // or from session or a default one
   $lang_id = isset($req_lang_id) ? $req_lang_id : (isset($sess_lang_id) ?
 $sess_lang_id : DEFAULT_LANG_ID);
   // Save it for next time
   $_SESSION['lang_id'] = $lang_id;
   return $lang_id;
 }
 
 Rob
 
 
 Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
 | TEL 954-607-4207 | FAX 954-337-2695
 Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
 bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-diy.com
 
 -Original Message-
 From: Jason Pruim [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, November 27, 2007 11:15 AM
 To: Jeff Benetti
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Newbie asks about multi-lingual website strategies


 On Nov 27, 2007, at 8:37 AM, Jeff Benetti wrote:

 I'm a noob so keep the comments to a noob's level please.

 I am doing a website and my client wants the bulk of the text to be
 bilingual (French and English).  The last site I did used php and
 mysql so I
 am getting comfortable with that technology.  Typically I am using a
 single
 php file and my menu constantly points to the same file with
 different id
 options example index.php?id=30 and I want to use the same idea to
 choose
 a language example index.php?lang=frid=30.  Pretty straight
 forward for
 many of you folks but before I start reinventing the wheel I
 wondered if
 anyone could offer any suggestions.  I have a couple of approaches
 in mind.

 I'm actually in the process of planning this as well... English and
 Spanish...

 1: Session vars, I have never used this but it seems straight
 forward.
 Drawbacks?
 Sessions are easy enough to use, just make sure that you are setting
 the variable in the right place... On a site I did the stored variable
 was always 1 behind what I wanted it to be... I moved the setting of
 the variable, and it worked :)
 2: Cookies again not too big a deal, never used cookies either but it
 doesn't seem to be mystifying however the fact that the user can turn
 cookies off makes me not want to go this route.
 3: Use the mysql database and log each ip address and record the
 preference
 and maybe the last time on the site.  I am leaning in this direction
 because
 I think it is the most robust but will it be slow?  First I have to
 get the
 ip then I have to check to see if it is in my data base and then get
 the
 language preference.  It would be great to have a standardized
 function that
 I could use on all of my sites.  I live in a bilingual country
 (Canada) so
 this could be a real selling point for my services.
 I don't know much about using mysql for storing IP's in canada... But
 in the US, all IP's except for businesses are dynamic, they could
 change every time a user would go to a site.. I could see that causing
 issues...


 Any any and all comments are welcome, it will be a learning curve no
 matter
 which route I take so a little advice on the best direction pros
 cons would
 be great.

 And of course knowing that I will have many many thousands of people
 on my
 site (hee hee) which option will perform best once I start
 accumulating
 vistors.  That's one problem I see with the mysql solution, I think
 it may
 start to be slow unless I start purging vistors who have not shown
 up in a
 while or limit the number of entries.
 I'm currently planning to store the text of the pages on my site in a
 database, so that I can very easily just change the language
 preference, and get the english, or spanish out of the database. I
 also think it will help speed up the site for when I have my thousands
 of users a second :)

 When you start doing it, let me know your experiences... I plan to
 actually start coding (If me and the site

Re: [PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread tedd

At 9:37 AM -0400 11/27/07, Jeff Benetti wrote:

Any any and all comments are welcome, it will be a learning curve no matter
which route I take so a little advice on the best direction pros cons would
be great.


Thanks,
Jeff


Jeff:

If it were me, I wouldn't use any problematic browser detects schemes 
(they don't work) or any of that high-thought stuff -- it's beyond me.


I would simply use a click here for English/French/Whatever link 
and then pull all the language specific stuff from the dB. Then throw 
the user's choice in a session and carry-on -- simple.


It wouldn't be any different than a php style sheet switcher, like this:

http://sperling.com/examples/styleswitch1/

Instead of green/red/blue/black, why not English/French/Spanish/German?

HTH's

Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread Jochem Maas
tedd wrote:
 At 9:37 AM -0400 11/27/07, Jeff Benetti wrote:
 Any any and all comments are welcome, it will be a learning curve no
 matter
 which route I take so a little advice on the best direction pros cons
 would
 be great.


 Thanks,
 Jeff
 
 Jeff:
 
 If it were me, I wouldn't use any problematic browser detects schemes
 (they don't work) or any of that high-thought stuff -- it's beyond me.

whether it's beyond you or not only you can judge, but I disagree that it's
problematic. I should note that I recommend using browser language preference
detection (as per my previous post) as a means to initially select a [hopefully]
suitable language BUT that this should be done in addition to offer the user
an explicit mechanism for language selection.

 
 I would simply use a click here for English/French/Whatever link and
 then pull all the language specific stuff from the dB. Then throw the
 user's choice in a session and carry-on -- simple.
 
 It wouldn't be any different than a php style sheet switcher, like this:
 
 http://sperling.com/examples/styleswitch1/
 
 Instead of green/red/blue/black, why not English/French/Spanish/German?
 
 HTH's
 
 Cheers,
 
 tedd
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie asks about multi-lingual website strategies

2007-11-27 Thread tedd

At 11:05 PM +0100 11/27/07, Jochem Maas wrote:

tedd wrote:

  If it were me, I wouldn't use any problematic browser detects schemes

 (they don't work) or any of that high-thought stuff -- it's beyond me.


whether it's beyond you or not only you can judge, but I disagree that it's
problematic. I should note that I recommend using browser language preference
detection (as per my previous post) as a means to initially select a 
[hopefully]

suitable language BUT that this should be done in addition to offer the user
an explicit mechanism for language selection.


My beyond me statement was meant in jest, but browser sniffing is 
notorious for being inaccurate and the practice is highly 
controversial.


http://en.wikipedia.org/wiki/Browser_sniffing

If you're going to permit the user to select his language, then what 
difference does it make what language you choose first? IMO, you 
would be better off to keep a record of the languages chosen and then 
present to a new user the highest ranking one first.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php