Internationalization
Moderator: General Moderators
Internationalization
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
I've already designed such a class myself but it isn't all that
-- Mike
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.
when u need it, use the key, .e.g. if u need lang1 then use
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());
?>Code: Select all
<?php
echo $dates[lang1];
?>unless lang1, lang2, lang3 are defines use
see also: http://php.net/manual/en/language.types.array.php#language.types.array.donts
Code: Select all
$dates['lang1'] = ...;
echo $dates['lang1'];
?>-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL
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....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
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');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...
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...
-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL
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:
another example:
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?
Code: Select all
"їhour]:їmin]:їsec] їampm] їmonth]/їday]/їyear]" to get "06:45:34 pm 3/15/03"Code: Select all
"їHOUR]:їmin] їmonthname] їday], їYEAR]" to get "18:45:34 September 16, 2003"[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?
tinyint: 1 biteJAM 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...
varchar needed for their selection: 2 bites+1 for the length of their selection
hence why i went for it like i did
-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL