Posts: 357
Threads: 23
Joined: Dec 2009
Hello;
Trying to solve this problem: http://get-simple.info/forum/viewtopic.php?id=342
I have made a plugin that translate publication date to spanish.
To use in template:
- <?php traduce_fecha_pub("l"); ?>
if you want to show the date in format dd/mm/yyyy
- <?php traduce_fecha_pub("n"); ?>
if you want to show the date in format dd de mes de año
If you want to use with other langs, translate array of months.
Regards
Posts: 1
Threads: 0
Joined: Jun 2011
useful
thanks
Posts: 2,094
Threads: 54
Joined: Jan 2011
luc Wrote:useful
thanks
See here for the more general solution to display dates in other languages.
Posts: 1,848
Threads: 86
Joined: Aug 2009
mvlcek Wrote:See here for the more general solution to display dates in other languages.
Can this be used to fix this bug?
- Chris
Thanks for using GetSimple! - Download
Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Posts: 357
Threads: 23
Joined: Dec 2009
Hi mvlcek,
I try to use the following:
Code: $dateLocale = 'de_DE,de,ger,deu'; // or use $LANG or a setting in your plugin,
// for OS compatibility multiple locales should be possible
$dateFormat = "%A, %d.%m.%Y - %H:%M"; // should be a entry in the i18n language file of your plugin
// for the format see PHP function strftime
$oldlocale = setLocale(LC_TIME, '0'); // save old locale
setlocale(LC_TIME, preg_split('/\s*,\s*/', $dateLocale));
echo strftime($dateFormat, $date).'<br />'; // $date is a UNIX timestamp
setLocale(LC_TIME, $oldlocale); // restore old locale
$Fecha_num="2011-06-15";
setlocale(LC_TIME, preg_split('/\s*,\s*/','es_ES'));
$fecha=strftime('%d %B %Y',strtotime($Fecha_num));
echo $fecha.'<br />';
and show:
Code: Donnerstag, 01.01.1970 - 01:00
15 June 2011
I don't know why, but it doesn't work in servers that use. Always in english .
Regards.
Posts: 1,204
Threads: 30
Joined: Jun 2010
2011-06-16, 04:04:57
(This post was last modified: 2011-06-16, 04:11:01 by BlackRose.)
cumbe: strtotime vs strftime
this is the thing I pointed.
to explain: strtotime formats date only in english while strftime is a per locale date function.
There's also an iconv, but everything I mentioned about it you can find across forums, and under link provided by CC.
edit: after below Mvlcek response
I don't see the reason of fetching and processing date from strtotime.
Try with iconv function: iconv("", "UTF-8",strftime('%A, %e.%B. %Y'));
Addons: blue business theme, Online Visitors, Notepad
Posts: 2,094
Threads: 54
Joined: Jan 2011
cumbe Wrote:I don't know why, but it doesn't work in servers that use. Always in english .
It seems that it depends on the operating system, which locales are available and how they are named.
If you have shell access, you can find out with locale -a.
Otherwise you can just try: use a string with all possible names separated by comma as in the example for german, like 'es_ES,es,esp,spa' (I'm guessing here - you may find possible names with google).
Posts: 357
Threads: 23
Joined: Dec 2009
It is the solution: thanks mvlcek.
Quote:It seems that it depends on the operating system, which locales are available and how they are named.
If you have shell access, you can find out with locale -a.
Otherwise you can just try: use a string with all possible names separated by comma as in the example for german, like 'es_ES,es,esp,spa' (I'm guessing here - you may find possible names with google).
In Apache windows server, only with 'esp' works good.
Code: setlocale(LC_TIME, preg_split('/\s*,\s*/','esp'));
But in apache linux server, it doesn´t work.
I will investigate...
Hi yojoe; i use strftime...
Regards.
Posts: 1,204
Threads: 30
Joined: Jun 2010
cumbe: what about using LC_ALL instead of only LC_TIME ?
Addons: blue business theme, Online Visitors, Notepad
Posts: 357
Threads: 23
Joined: Dec 2009
yojoe, i try it, but with the same result...
Posts: 357
Threads: 23
Joined: Dec 2009
Anyway, I think it's best to format the date by a function that to depend of server with setlocale.......
Regards.
Posts: 2,094
Threads: 54
Joined: Jan 2011
cumbe Wrote:But in apache linux server, it doesn´t work.
I will investigate... Just use all variants you find, separated by comma. The function will use the first available locale and it will run on (hopefully) all os.
Posts: 3,491
Threads: 106
Joined: Mar 2010
With XAMPP on Windows XP I have those problems displaying date strings having non-English characters: like März, miércoles... Accented/punctuated (non US-ASCII) characters are all displayed as a diamond symbol.
With plugins like I18N Search or News Manager, if I edit them by changing strftime(...) to utf8_encode(strftime(...)) then dates are diplayed ok (also works with iconv("", "UTF-8",strftime(...))) )
Anyone knows if there's a way to select a locale that uses UTF-8 in XAMPP without having to use that kind of patch? In Spanish I've tried with "es_ES.utf8,es_ES,esp,spanish,es" but doesn't work, I don't get utf-8. (The locale being used is "Spanish_Spain.1252")
Posts: 2,094
Threads: 54
Joined: Jan 2011
(2013-01-14, 04:37:31)Carlos Wrote: With XAMPP on Windows XP I have those problems displaying date strings having non-English characters: like März, miércoles... Accented/punctuated (non US-ASCII) characters are all displayed as a diamond symbol.
With plugins like I18N Search or News Manager, if I edit them by changing strftime(...) to utf8_encode(strftime(...)) then dates are diplayed ok (also works with iconv("", "UTF-8",strftime(...))) )
Anyone knows if there's a way to select a locale that uses UTF-8 in XAMPP without having to use that kind of patch? In Spanish I've tried with "es_ES.utf8,es_ES,esp,spanish,es" but doesn't work, I don't get utf-8. (The locale being used is "Spanish_Spain.1252")
Yeah, Microsoft was never one to use standards...
It seems impossible to set a UTF-8 locale in PHP on Windows.
And I suppose in east european countries another code page is used by Windows - then utf8_encode won't work, as it assumes iso-8859-1 (which is a subset of Windows-1252).
Luckily most hosting providers use Linux hosts :-)
Posts: 6,266
Threads: 181
Joined: Sep 2011
When you geniuses figure this out let us know how to apply it in core.
Posts: 3,491
Threads: 106
Joined: Mar 2010
(2013-01-14, 07:11:10)mvlcek Wrote: Yeah, Microsoft was never one to use standards...
It seems impossible to set a UTF-8 locale in PHP on Windows.
And I suppose in east european countries another code page is used by Windows - then utf8_encode won't work, as it assumes iso-8859-1 (which is a subset of Windows-1252).
Luckily most hosting providers use Linux hosts :-)
What about using iconv("", "UTF-8",strftime(...))) instead of utf8_encode(strftime(...))? (as yojoe suggested in post 6)
Would that work better for everyone? Or is there any disadvantage?
What I don't like about this is that users with Windows (be it dev or production sites) have to patch plugins that use strftime. If there's no other solution I think it would be nice to agree some kind of gsconfig setting like GSWINUTF8ENCODE (I'm not inspired today) so that plugins use iconv or utf8_encode if enabled.
Posts: 6,266
Threads: 181
Joined: Sep 2011
I found this on a site after a quick query
PHP Code: if(WINDOWS){ echo base64_encode(iconv('ISO-8859-2', 'UTF-8',strftime("%a %d-%b-%Y",(DateAdd("d", $day, strtotime($grid_date))))))."|"; } else { echo base64_encode(strftime("%a %d-%b-%Y",(DateAdd("d", $day, strtotime($grid_date)))))."|"; }
dont know if it helps
I think iconv should be enabled by default unless php was built specifically without it.
Posts: 3,491
Threads: 106
Joined: Mar 2010
Ah yes, iconv would have to be installed. I suppose that the less requirements the better, so maybe utf8_encode would be better.
@shawn_a Do you plan to use strftime in the core?
BTW mvlcek suggested it in this interesting thread...
Posts: 6,266
Threads: 181
Joined: Sep 2011
Yeah its going to have to be implemented soon.
oh and that thread, I hope I haven't lost that file i was working on, lol
Posts: 6,266
Threads: 181
Joined: Sep 2011
Posts: 3,491
Threads: 106
Joined: Mar 2010
2013-01-20, 07:35:17
(This post was last modified: 2013-01-21, 05:32:01 by Carlos.)
@mvlcek
So a workaround for this would be checking if OS is windows, then using utf8_encode.
But... it seems there are linux hosts that have this problem (ovh), see:
http://get-simple.info/forums/showthread...5#pid31845
http://get-simple.info/forums/showthread...5#pid32055
Any ideas?
[edit] Sorry, forget about this. It was just the locale was not being set.
Posts: 6,266
Threads: 181
Joined: Sep 2011
PHP Code: iconv('Windows-1252', 'UTF-8', blah;
?
Posts: 3,491
Threads: 106
Joined: Mar 2010
If OS == WIN
utf8_encode(strftime(...))
else
strftime(...)
GS lang file should have a LOCALE (or DATE_LOCALE) string, as mvlcek suggested in the other thread, with several possible server date locales.
As for get_page_date, to keep backwards compatibility with themes, the function might check if the parameter given contains any % character, to use date or strftime.
Posts: 6,266
Threads: 181
Joined: Sep 2011
So do we also need to add a user date format or use it from Lang or provide a bunch of predefined ones?
Posts: 2,094
Threads: 54
Joined: Jan 2011
(2013-01-21, 11:28:33)shawn_a Wrote: So do we also need to add a user date format or use it from Lang or provide a bunch of predefined ones?
Basically GetSimple needs to separate web site (frontend) settings and administration (backend) settings as regards language:
At least there should be a frontend language setting: - language (gsconfig.php or better in settings), but overwriteable by plugins (I18N)
- and a function to retrieve the current language
Then, assuming the corresponding language is installed, defaults for the following can be taken from the GetSimple language file: - locale (new)
- date/time settings (already exists, but should be able to use strftime)
Plugins displaying text on the frontend can either use these defaults or have special date/time settings (like short date) in their language files or provide an option on their plugin settings page.
The I18N plugin would still switch the language based on the user's language settings, but other plugins should be able to retrieve the current language with above mentioned language.
For the backend the language would still be the current user's language and the locale and date/time setting from the language file(s).
@Carlos: I like the idea to allow both old (date) and new (strftime) formats and decide which function to use based on the existence of "%".
P.S.: when setting the locale, LC_ALL should be used - this way numbers will also be shown in the correct format (. or , as decimal separator).
|