Jump to content

Can't get PW to output German month names


totoff

Recommended Posts

In the current version of PW (2.6.9 dev) it is possible to add the date format via the PHP strftime syntax to get localized output.

In my case I get a difference of 7 minutes between the choosen time in the backend and the outputted time in frontend.

post-2257-0-81445900-1437475074_thumb.pn

This is the date/time that I choose in the backend.

The output format for each language in the field is like this:

1) German output format

post-2257-0-93776000-1437475138_thumb.pn

2) English output format

post-2257-0-84905900-1437475157_thumb.pn

And this is what i looks like in the frontend:

1) German

post-2257-0-52991600-1437475186_thumb.pn

2) English

post-2257-0-63061800-1437475212_thumb.pn

So as you can see the monthname is in the correct language and the time is also the correct format but I have got a difference of 7 minutes between the output on the frontend and the choosen time in the backend (18:07 instead of 18:00 in German and 06:07 PM instead of 06:00 in English).

Could the cause be a server time problem where I hosted this site?

Best regards Jürgen

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

I just wanted to add to this archive of the "german month name battle"

Just like other people editing the config.php and adding the setlocale changed nothing for me.

The only solution in my case was the approach of this post with the addition of adding the setlocale to the PHP part of my template. Without it month names still had wrong coded umlauts.

The relevant part of my template now looks like that:


<?php 

  setlocale (LC_ALL, 'de_DE.UTF-8');
  ...
 foreach($allenews as $news) {
      echo "<p class=\"news-datum\">".strftime("%d. %B %Y", strtotime($news->newsdatum))."</p>";
      ...
}

I battled this for some time now and mostly did workaround it by not outputting a month name at all. But now I had to...

Link to comment
Share on other sites

I struggled with this too in the past. A while ago, I switched to use The IntlDateFormatter class like, for example:

    $fmt = datefmt_create(
        'de-DE',
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,
        'Europe/Berlin',
        IntlDateFormatter::GREGORIAN,
        'MMMM Y'
    );  // format doesn't use PHP style, but ISO-Format! see: http://framework.zend.com/manual/1.12/en/zend.date.constants.html#zend.date.constants.selfdefinedformats
    $datum = is_numeric($page->getUnformatted('datum')) ? datefmt_format($fmt, $page->getUnformatted('datum')) : '';

And welcome to the forums, @Klenkes. (?)

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hey Guys,

I'm super lost with this :( and am hoping somebody can help me!

All I want is for the days of a datetime field used in a form to change from English to Dutch.

I've tried change locale in config.php, I've tried installing a dutch language, I've tried ProcessLanguageTranslate

but all to no avail, the stupid thing is still in english :'(  

Could someone please give me a list of steps to follow in order to achieve this?

Thanks alot in advance! 

Gr,

Bram

Link to comment
Share on other sites

Okay let me try to be a little clearer.

I get that I should use both the setlocale and the strftime function codes,

but I don't know in which file and at what place I should insert those for this to work.

Could you maybe help me with that?

thanx :)

Link to comment
Share on other sites

Languages :-)

Try this in a template:

<?php

setlocale(LC_TIME, 'NL_nl');
echo strftime('%e %B %Y om %H:%M', time());

The function time() creates a timestamp. If you formatted the date you might want to get the date unformatted like:

<?php

$page->getUnformatted('FIELDNAMEHERE');

So:

<?php

setlocale(LC_TIME, 'NL_nl');
echo strftime('%e %B %Y om %H:%M', $page->getUnformatted('FIELDNAMEHERE'));

Should produce the time in the Dutch language. Place it at the top of your file. 

You can also get the current locale with:

<?php

echo locale_get_default();
  • Like 2
Link to comment
Share on other sites

Hey Arjen,

Thanks for your detailed explanation :) I got it to work and it outputted a Dutch version of the current timestamp.

However, I'm trying to convert one field of a FormBuilder form to Dutch and I still can't seem to get it to do that.

Just using the code without a specific variable or timestamp to convert still outputs the form field in english,

and trying to get it to convert all the form data like I tried here, also doesn't work:

$form = $forms->render('reserveren');

setlocale(LC_TIME, 'NL_nl');
echo strftime('%e %B %Y om %H:%M', $form);

Any ideas how to do this?

Thanks for your help so far :)

Gr,

Bram

Link to comment
Share on other sites

Bram, you need to set the locale before rendering the form. Then any output formats defined for date/time fields in that form (assuming we're talking about PW Inputfields) will be rendered according to the chosen locale.

strftime() only formats unix timestamps, i.e. integer values in seconds since the first of January 1970. You can't feed it HTML snippets.

Link to comment
Share on other sites

Hey BitPoet,
 
Thanks for the reply! What I gather from your post is that setlocale has to go before rending the form and
that strftime is not going to work since I can't feed it html snippets. so I did this, and later on echoed the
form, but this still doesn't work :(

setlocale(LC_TIME, 'NL_nl');
$form = $forms->render('reserveren');

datetime.png

Link to comment
Share on other sites

Sorry, my bad for not thinking my answer through. setlocale() has no effect on PHP's date() formatting, it only influences strftime(). Thus, you can use it to change how the formatted value of a PW field looks if it uses a percent encoded format fitting for strftime, but not the input format that is active when used as a form field. So I'm not aware of any way to make native PW date fields locale aware.

  • Like 1
Link to comment
Share on other sites

Hey Martijn,

I tried this but I keep getting undefined errors in my console:

Uncaught TypeError: Cannot read property 'setDefaults' of undefined
jquery.ui.datepicker-nl.js:4 Uncaught TypeError: Cannot read property 'regional' of undefined

even though I did target the right element:

$.datepicker.setDefaults( $.datepicker.regional[ "nl" ] );
$('#Inputfield_datum').datepicker({
            numberOfMonths: 1,
            showButtonPanel: true,
            dateFormat : 'dd/mm/yy'
        });

The form can be found here:

http://www.cafepool.nl/reserveren/

Thanks guys

Link to comment
Share on other sites

InputfieldDatetime allows you to translate the paths for the datepicker and timepicker language files if LanguageSupport is installed.

/wire/modules/Jquery/JqueryUI/i18n/jquery.ui.datepicker-xx.js => /wire/modules/Jquery/JqueryUI/i18n/jquery.ui.datepicker-nl.js
timepicker/i18n/jquery-ui-timepicker-xx.js => timepicker/i18n/jquery-ui-timepicker-nl.js

This might be easier than toying around with custom JS.

Link to comment
Share on other sites

In Setup -> Languages click your default language. Click "Translate File", then select InputfieldDatetime in the "Translatable files in Wire" select - unless the language pack already contains a translation for it, then you only need to click on the title of the translation in the language itself.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...