Jump to content

Can't get PW to output German month names


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 post
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 post
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 post
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 post
Share on other sites

Hey Martijn, 

I tried setting locale in config.php but not with setlocale and I didn't use strftime. 

Where, and how would you suggest to use those in order the change the datetime field?

Thanks in advance :)

Link to post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kreativmonkey
      Hi,
      i want to set a date field value by api but i have problems to do so. I think this should be work:
      $page->of(false); $page->expire_date = time(); $page->save(); $page->of(true); but when i look into the field i get not the saved time. The output is always: 30 Nov, -0001 00:00  (timestamp: -62169987208).
      when i echo the time directly after the $page->of(true); than i get the current time but avter reload and output the time bevor $page->of(false); i get the time above!
      do you have any idea whats the problem?
    • By abdus
      I'm trying to build a multilanguage website with Turkish as main and English as alternative language. I replaced hardcoded strings in template files and used built-in translation tools to translate template files. I'm using the functions ProcessWire provides:
      // using __() <?= __("There are no products to display.") ?> // or _x() <html lang="<?= echo _x('en', 'HTML language code'); ?>"> // Both works when I use _main.php When I disable auto including _main.php from config.php file, and move or rename _main.php to something else or use another file (other than  _main.php that comes with site-languages profile) for template specific markups, say markup/products.php like below, translations stop working.
      // config.php, disabled auto append // $config->appendTemplateFile = '_main.php'; // home.php include_once("./_main.php"); wireIncludeFile("./_main.php"); // TRANSLATION WORKS include_once("./_home.php"); // DOESNT WORK wireIncludeFile("markup/_main.php"); include_once("markup/_main.php"); // DOESNT WORK // NOTE: home.php and main.php has the same content, same permissions, same ownership I debugged the issue, and the reason, as ridiculous as it sounds, originates from using file other than _main.php. I searched the forums, google, but this seems like a unique issue. Is there anything I'm missing and how can I fix this, because I can't think of anything else after hours lost trying to find the underlying cause?
      Thanks in advance.
    • By Orkun
      I have set the right Datepicker translation file "/wire/modules/Jquery/JqueryUI/i18n/jquery.ui.datepicker-de.js".
      And change the code from:
      /* German initialisation for the jQuery UI date picker plugin. */ /* Written by Milian Wolff (mail@milianw.de). */ jQuery(function($){ $.datepicker.regional['de'] = { closeText: 'schließen', prevText: '<zurück', nextText: 'Vor>', currentText: 'heute', monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'], monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'], dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'], dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'], dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'], weekHeader: 'KW', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['de']); }); to:
      /* German initialisation for the jQuery UI date picker plugin. */ /* Written by Milian Wolff (mail@milianw.de). */ jQuery(function($){ $.datepicker.regional['de'] = { closeText: 'schließen', prevText: '<zurück', nextText: 'Vor>', currentText: 'heute', monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'], monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'], dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'], dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'], dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'], weekHeader: 'KW', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['de']); $.timepicker.regional['de'] = { timeText: 'Uhrzeit', hourText: 'Stunde', minuteText: 'Minute', secondText: 'Sekunde', millisecText: 'Millisekunde', timezoneText: 'Zeitzone', currentText: 'jetzt', closeText: 'schliessen', }; $.timepicker.setDefaults($.timepicker.regional['de']); }); But it only affects the date and not the time. What I'm missing?
    • By EvanFreyer
      Hey there,
      I have a problem with URL Segments and Umlauts in it. I want to grab the a segment of the url and use it as a parameter to find a something in Processwire. The problem is, that if I input an umlaut into the url, processwire immediately throws a 404 error page and I am not able to transform my inputs.
      Is there a way to get around that problem?
      Cheers,
      Evan
    • By MarcC
      I'm testing ProcessWIre's localization features, trying out fields like TextAreaLanguage and PageTitleLanguage. I've got them installed, assigned, and filled out. Now, how do I, for example, make Spanish-language fields show up on the public site for Spanish-language visitors?
      It feels like a bit of a dumb question, but I swear I looked at the docs!
      I thought it might be automatic detection based on a header string or something, but that hasn't worked for me. I don't know exactly what details to look for as this is my first time through. Thanks!
×
×
  • Create New...