Page 1 of 1
Internationalization
Posted: Wed Sep 24, 2003 12:56 pm
by mlitton
Is there a good way too switch between languages in PHP? Like if I wan't a date to be viewed in several different languages.
I've already designed such a class myself but it isn't all that
-- Mike
Posted: Wed Sep 24, 2003 3:29 pm
by qads
u could set all the date formats in diffrenet langs in a array and when u need to switch just call that array with a key, e.g.
Code: Select all
<?php
$dates[lang1] = date("d/m/y", time());
$dates[lang2] = date("m/d/y", time());
$dates[lang3] = date("y/m/y", time());
?>
when u need it, use the key, .e.g. if u need lang1 then use
Posted: Wed Sep 24, 2003 4:04 pm
by volka
unless lang1, lang2, lang3 are
defines use
Code: Select all
$dates['lang1'] = ...;
echo $dates['lang1'];
?>
see also:
http://php.net/manual/en/language.types.array.php#language.types.array.donts
Posted: Wed Sep 24, 2003 6:18 pm
by Cruzado_Mainfrm
actually the date format is not language dependant

you can save all the date formats in a db, array or file, then
make a dropdown or something like that where u can select what date format you want to use

Posted: Fri Sep 26, 2003 12:03 pm
by m3rajk
Cruzado_Mainfrm wrote:actually the date format is not language dependant

you can save all the date formats in a db, array or file, then
make a dropdown or something like that where u can select what date format you want to use

i did somehting like that. i came up with 76 different formats... i save the person's preference in a tinyint and use an array to get it....
Code: Select all
# time display choices (for misc options control panel)
$tdc=array('0'=>'08/15/2003 22:02:27', '1'=>'08/15/2003 10:02:27', '2'=>'08/15/2003 10:02:27 PM', '3'=>'08/15/2003 10:02:27 pm', '4'=>'Fri Aug 15 2003 22:02:27', '5'=>'Fri Aug 15 2003 10:02:27 PM', '6'=>'Fri Aug 15 2003 10:02:27 pm', '7'=>'08-15-2003 22:02:27', '8'=>'08-15-2003 10:02:27', '9'=>'08-15-2003 10:02:27 PM', '10'=>'08-15-2003 10:02:27 pm', '11'=>'8/15/2003 22:02:27', '12'=>'8/15/2003 10:02:27', '13'=>'8/15/2003 10:02:27 PM', '14'=>'8/15/2003 10:02:27 pm', '15'=>'8-15-2003 22:02:27', '16'=>'8-15-2003 10:02:27', '17'=>'8-15-2003 10:02:27 PM', '18'=>'8-15-2003 10:02:27 pm', '19'=>'08/15/2003 22:02', '20'=>'08/15/2003 10:02', '21'=>'08/15/2003 10:02 PM', '22'=>'08/15/2003 10:02 pm', '23'=>'Fri Aug 15 2003 22:02', '24'=>'Fri Aug 15 2003 10:02 PM', '25'=>'Fri Aug 15 2003 10:02 pm', '26'=>'08-15-2003 22:02', '27'=>'08-15-2003 10:02', '28'=>'08-15-2003 10:02 PM', '29'=>'08-15-2003 10:02 pm', '30'=>'8/15/2003 22:02', '31'=>'8/15/2003 10:02', '32'=>'8/15/2003 10:02 PM', '33'=>'8/15/2003 10:02 pm', '34'=>'8-15-2003 22:02', '35'=>'8-15-2003 10:02', '36'=>'8-15-2003 10:02 PM', '37'=>'8-15-2003 10:02 pm', '38'=>'08/15/03 22:02:27', '39'=>'08/15/03 10:02:27', '40'=>'08/15/03 10:02:27 PM', '41'=>'08/15/03 10:02:27 pm', '42'=>'Fri Aug 15 03 22:02:27', '43'=>'Fri Aug 15 03 10:02:27 PM', '44'=>'Fri Aug 15 03 10:02:27 pm', '45'=>'08-15-03 22:02:27', '46'=>'08-15-03 10:02:27', '47'=>'08-15-03 10:02:27 PM', '48'=>'08-15-03 10:02:27 pm', '49'=>'8/15/03 22:02:27', '50'=>'8/15/03 10:02:27', '51'=>'8/15/03 10:02:27 PM', '52'=>'8/15/03 10:02:27 pm', '53'=>'8-15-03 22:02:27', '54'=>'8-15-03 10:02:27', '55'=>'8-15-03 10:02:27 PM', '56'=>'8-15-03 10:02:27 pm', '57'=>'08/15/03 22:02', '58'=>'08/15/03 10:02', '59'=>'08/15/03 10:02 PM', '60'=>'08/15/03 10:02 pm', '61'=>'Fri Aug 15 03 22:02', '62'=>'Fri Aug 15 03 10:02 PM', '63'=>'Fri Aug 15 03 10:02 pm', '64'=>'08-15-03 22:02', '65'=>'08-15-03 10:02', '66'=>'08-15-03 10:02 PM', '67'=>'08-15-03 10:02 pm', '68'=>'8/15/03 22:02', '69'=>'8/15/03 10:02', '70'=>'8/15/03 10:02 PM', '71'=>'8/15/03 10:02 pm', '72'=>'8-15-03 22:02', '73'=>'8-15-03 10:02', '74'=>'8-15-03 10:02 PM', '75'=>'8-15-03 10:02 pm');
crap. i just realized i missed at least 76 choices... all mine do mdy... well maybe not 76, but i don't have any dmy or ydm or ymd....
Posted: Fri Sep 26, 2003 12:58 pm
by Leviathan
As a better idea, why not store your date and time formats seperately and let the user pick both? It drastically cuts down the number of combinations you can have.
Posted: Fri Sep 26, 2003 3:38 pm
by JAM
Just adding ideas...
Or just let them type "M Y D" or whatever as they want it themselves, combined with preview for easier understanding and effect?
If it's more than dates, time, currency etc., I'd use seperate *.lang files, common in some larger projects (phpbb as example).
You could then get the users browser setting.
I have "Accept-Language: en-us,en;q=0.5", so a en.lang.php might work for me in this case...
Posted: Fri Sep 26, 2003 6:24 pm
by Cruzado_Mainfrm
i think those are far too many choices, the user will get annoyed by so many choices, and he can't find his, what you should do, is make a simple sintax where the user can write:
Code: Select all
"їhour]:їmin]:їsec] їampm] їmonth]/їday]/їyear]" to get "06:45:34 pm 3/15/03"
another example:
Code: Select all
"їHOUR]:їmin] їmonthname] їday], їYEAR]" to get "18:45:34 September 16, 2003"
design the page like this:
[select hours format] [Insert]
[select minutes format] [Insert]
[select ??whatever?? format] [Insert] <-- the last [] is a button...
hope u get me
wasn't that a nice idea?
Posted: Sat Sep 27, 2003 4:34 pm
by m3rajk
JAM wrote:Just adding ideas...
Or just let them type "M Y D" or whatever as they want it themselves, combined with preview for easier understanding and effect?
If it's more than dates, time, currency etc., I'd use seperate *.lang files, common in some larger projects (phpbb as example).
You could then get the users browser setting.
I have "Accept-Language: en-us,en;q=0.5", so a en.lang.php might work for me in this case...
tinyint: 1 bite
varchar needed for their selection: 2 bites+1 for the length of their selection
hence why i went for it like i did
Posted: Sat Sep 27, 2003 7:13 pm
by Cruzado_Mainfrm
yea that is the first option, but u'll have to explain 'every' letter at glance...
also, it will be good after the user writes the format she/he is going to use click in a button that will show him how the date will look like(They should add this to the phpbb forums!).
Posted: Sun Sep 28, 2003 2:17 am
by JAM
m3rajk:
Yes, I know you need something else than tinyint. I still prefer letting the user choose for themselves rather than save space in this matter.
Posted: Sun Sep 28, 2003 11:32 am
by qads
lol..you guys scare the crap out of people lol..he only wanted to know one little thing you know

Posted: Sun Sep 28, 2003 9:50 pm
by JAM
I like when people explore the options, any options.
If there are several good ideas, why not mention them all?
Doesn't ask for an 'easy' way to do it, and by managing to build a class any of these ideas would be pretty selfexplainatory. Or so I hope.