Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PlugIn > translate Publication date
#1
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
Reply
#2
useful
thanks Smile
Reply
#3
luc Wrote:useful
thanks Smile

See here for the more general solution to display dates in other languages.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#4
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!
Reply
#5
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 Sad.


Regards.
Reply
#6
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
Reply
#7
cumbe Wrote:I don't know why, but it doesn't work in servers that use. Always in english Sad.

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).
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#8
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... Smile

Hi yojoe; i use strftime...

Regards.
Reply
#9
cumbe: what about using LC_ALL instead of only LC_TIME ?
Addons: blue business theme, Online Visitors, Notepad
Reply
#10
yojoe, i try it, but with the same result...
Reply
#11
Anyway, I think it's best to format the date by a function that to depend of server with setlocale.......

Regards.
Reply
#12
cumbe Wrote:But in apache linux server, it doesn´t work.
I will investigate... Smile
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.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#13
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")
Reply
#14
(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 :-)
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#15
When you geniuses figure this out let us know how to apply it in core.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#16
(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.
Reply
#17
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"$daystrtotime($grid_date))))))."|";
} else {
echo 
base64_encode(strftime("%a %d-%b-%Y",(DateAdd("d"$daystrtotime($grid_date)))))."|";


dont know if it helps

I think iconv should be enabled by default unless php was built specifically without it.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#18
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...
Reply
#19
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
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#20
fyi
http://www.loc.gov/standards/iso639-2/php/code_list.php
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#21
@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.
Reply
#22
PHP Code:
iconv('Windows-1252''UTF-8'blah

?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#23
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.
Reply
#24
So do we also need to add a user date format or use it from Lang or provide a bunch of predefined ones?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#25
(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).
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 1 Guest(s)