kixe

Name Format Children

69 posts in this topic

1 hour ago, kixe said:

The module uses php function date() and NOT strftime(). To get what you expect use the following format string: 'date(M-d-Y)'.

That's not working for me since I'm grabbing the date from a datetime field which uses multi-language format. Here is what I did to make it work:

I replaced the 174 line:

$value = date($dateOutputFormat, $value);

into this:

$value = utf8_encode(strftime($dateOutputFormat, $value));

Can you add an option on the module where we can select if we want to use multi-language datetime formats?

Share this post


Link to post
Share on other sites

@kixe There is one last thing that I think needs to be fixed either you're using multi-language datetime formats or not.

The page name for all languages has only the default language's datetime format. If you can make it grab for the additional languages their datetime formats that would be perfect.

Share this post


Link to post
Share on other sites

@PWaddict

OK. I fixed the issue. For datetimefields the format will be pulled from the field settings including strftime formats.

58 minutes ago, PWaddict said:

The page name for all languages has only the default language's datetime format

Datetime fields are not true multilanguage fields. The language-specific output of a datetime field can not be influenced by changing the user language.

In a template, the output will be l
anguage-sensitive only by using setlocale() and if strftime formats for output are set in the datetime field settings. Inside PW datetime fields are not aware of the language.

It would actually be desirable to have a field for setting locales in Processwire for each language or an option to set the locale in datetimefields settings. You maybe want to start a topic in the wishlist and roadmap section to point out Ryan.


 

2 people like this

Share this post


Link to post
Share on other sites
14 minutes ago, kixe said:

@PWaddict

OK. I fixed the issue. For datetimefields the format will be pulled from the field settings including strftime formats.

Datetime fields are not true multilanguage fields. The language-specific output of a datetime field can not be influenced by changing the user language.

In a template, the output will be l
anguage-sensitive only by using setlocale() and if strftime formats for output are set in the datetime field settings. Inside PW datetime fields are not aware of the language.

It would actually be desirable to have a field for setting locales in Processwire for each language or an option to set the locale in datetimefields settings. You maybe want to start a topic in the wishlist and roadmap section to point out Ryan.


 

Thank you for the update. It works great.

I'm settng the locale by translating the "C" string on LanguageSupport.module on each language which is the easiest method. The other method would be to add a field for locale inside the system's template "language".

I've changed the default's language locale from english to german and the module updates the page name from oct-17-2018 to okt-17-2018. So PW is aware of the datetime's language.

Do you think you can get the locale from the "C" string on LanguageSupport.module or from a field under the template "language" so the module can update the additional language page names too?

 

2 people like this

Share this post


Link to post
Share on other sites

@PWaddict

Thanks for pointing on LanguageSupport::_('C'). I pushed an update 2.0.5 which is aware of this.

Share this post


Link to post
Share on other sites
13 minutes ago, kixe said:

@PWaddict

Thanks for pointing on LanguageSupport::_('C'). I pushed an update 2.0.5 which is aware of this.

I've tested the new update and It doesn't work. All the language page names are still getting the default language datetime format.

Share this post


Link to post
Share on other sites

Sorry for the trouble. I tested with translations 'en_EN' for default and 'de_DE' for german and it works.
If I set german as default it doesn't work. I will have a deeper look asap.

Share this post


Link to post
Share on other sites
6 minutes ago, kixe said:

Sorry for the trouble. I tested with translations 'en_EN' for default and 'de_DE' for german and it works.
If I set german as default it doesn't work. I will have a deeper look asap.

On my test site my default language is english and having 2 additional languages (spanish & german). All the language page names are getting the english format. If I switch the default language to german then all language page names are getting the german format and so on...

Share this post


Link to post
Share on other sites

It depends on your server settings. You should play around a bit with LanguageSupport:: _('C') translation strings.

In my local environment I am getting the following results in a test template:

setlocale(LC_TIME , 'de_DE');
echo $page->mydatetimefield; // getting Mai-27-2017

setlocale(LC_TIME , 'en_EN');
echo $page->mydatetimefield; // getting Mai-27-2017, expecting May-27-2017

setlocale(LC_TIME , 'en_US');
echo $page->mydatetimefield; // getting May-27-2017

As you can see I am not able to solve this via the module.
Have also a look here http://stackoverflow.com/questions/10909911/php-setlocale-has-no-effect

1 person likes this

Share this post


Link to post
Share on other sites

@kixe My locale settings are correct cause datetime formats on front-end are working fine. Even on the module datetime formats are working fine if it's on the default language. I wish I knew how to modify the module to get the correct datetime formats for the additional language too.

Here is exactly how my translated "C" string value is on each language:

Default
en_US.utf8, English_United States

Español
es_ES.utf8, Spanish_Spain

Deutsch
de_DE.utf8, German_Germany

Note: The first value is for my server (Linux) and the second is for XAMPP (Windows).

You should replace your en_EN to en_GB to get the proper value. As far as I know the en_EN isn't a correct locale.

When you said that you've tested the translations you meant on template just like on your example above or in the module?

Share this post


Link to post
Share on other sites

@kixe I'm suggesting you first to try to get ONLY the regular date format values from additional languages. Add on the default language: M d Y and then on additional language add d M Y. When you managed to get that values correctly on page names then continue by adding the code for setlocale and the strftime format values: %b %d %Y on the default language and %d %b %Y on the additional language.

Share this post


Link to post
Share on other sites

@PWaddict
Module works as expected. No failures here. Thanks, but I have no need for your suggestions. Feel free to fork it and adapt it for your needs. :rolleyes:

Share this post


Link to post
Share on other sites

@kixe Can you please confirm that the below example is working for you?

If you have %b %d %Y on the default language and %d %b %Y on the additional language are you getting these formats on their page names?

default: oct-17-2018
german: 17-okt-2018

Share this post


Link to post
Share on other sites

Screencast.gif.d71fa7a37da2c567d147bb278860af85.gif

It works for me, since I didn't use comma separated multiple values. With latest version it should work for your settings too.

1 person likes this

Share this post


Link to post
Share on other sites
1 hour ago, kixe said:

It works for me, since I didn't use comma separated multiple values. With latest version it should work for your settings too.

For me it's still not working :( All the page names having the format value from the default language. Thank you so much for updating the module with this feature. I hope I will figure out why it isn't working for me.

I'm on localhost with php7 and the pages are created from a pagetable. Do you think any of these is causing the issue?

My site url on localhost is http://localhost/mysite/ and I'm thinking that the problem might be that. For example the module "Admin Custom Files" can't inject the files properly on that url. Somehow can't see this part: /mysite/. On a live server it's working properly. So, maybe your module too can't see the correct urls of my additional languages. I have to upload it on a live server to make sure if that's the problem.

Thanks again. I will let you know if I find the problem.

Share this post


Link to post
Share on other sites

@PWaddict Just to be sure. You are talking about modules version 2.0.7 I pushed this morning?

Note
The strings you have posted doesn't work at all for me. I had to change from utf8 to utf-8 to get it work.
But this depends on the environment and if you get the right output of your datetime field in the frontend it should work in the module too.

Share this post


Link to post
Share on other sites
Just now, kixe said:

@PWaddict Just to be sure. You are talking about modules version 2.0.7 I pushed this morning?

Yes, I have the 2.0.7 version. I found the issue. I'm using 2 fields on "Name format for children": title tour_date
All these time I was only posting a title on default language. The only way to get the correct date format is If I post a title on an additional language. Can this be fixed from your module?

1 person likes this

Share this post


Link to post
Share on other sites
On 5/6/2017 at 2:36 PM, kixe said:

@PWaddict Thanks. I could reproduce. I will try to fix this.

Any news about the fix? Thanks.

Note: The problem happens only on multi-language title field. If use a regular text field everything is working properly.

Share this post


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 psy
      I've configured my PW site to use regions and mostly it's fabulous. However I encountered a strange problem when appending scripts to the body tag of a template. The body tag id is "bodyTag" (duh!).
      There are 3 scripts - two external and one inline. My first attempt was to append each script individually thinking they'd appear in the same order on the output:
      <script id="googlemapskey" type="text/javascript" src="https://maps.google.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXX" pw-append="bodyTag"></script> <script id="localMapsJS" type="text/javascript" src="<?=$bootstrap?>js/jquery.gmap.js" pw-append="bodyTag"></script> <script type="text/javascript" pw-append="bodyTag"> jQuery(document).ready(function($){ ... }); </script> Not so! Got lots of js errors and discovered the output had placed the scripts in the incorrect order, ie:
      <script type="text/javascript" pw-append="bodyTag"> jQuery(document).ready(function($){ ... }); </script> <script id="localMapsJS" type="text/javascript" src="/site/assets/mytheme/js/jquery.gmap.js"></script> <script id="googlemapskey" type="text/javascript" src="https://maps.google.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXX"></script> In other places I've appended multiple HTML regions to the same tag and it's worked fine. It only happens with scripts.
      After trying a few things, I discovered a workaround which was to wrap all the scripts into one div which is then appended to the body tag. This is OK but not ideal. I think (?), the partial is rendered in its entirety before being appended to the body tag:
      <div pw-append="bodyTag"> <script id="googlemapskey" type="text/javascript" src="https://maps.google.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXX"></script> <script id="localMapsJS" type="text/javascript" src="<?=$bootstrap?>js/jquery.gmap.js"></script> <script type="text/javascript" pw-append="bodyTag"> jQuery(document).ready(function($){ ... }); </script> </div> Curious to know where I went wrong in the first example with each script appended individually or is this behaviour with scripts an undocumented feature of regions?
      Using PW 3.0.61 with both Chrome and Firefox
    • By louisstephens
      I have been scratching my head on this one for a while, so I thought maybe someone could shed some light on this issue. I am using a grid layout (that I have created over the years) with a class for responsive images (very similar to bootstrap, but very stripped down). Using this, I created a gallery using a foreach loop, and included a "print button" to print each image. I got the classes and everything worked out, but I ran into a small problem with the print functionality. My images (which are around 2400px wide to fill the space) are just fine in the grid and on resize, but when I print, they "run off" the page. I understand that they are just too big to be printed in portrait mode, which led to me think that I could use $image->size(); to print a scaled down version of the image (which adds a bit more load time as now the site needs to load the image large scale and the scaled down version). However, I can't seem to wrap my head around serving just the scaled down version for print only (obviously display:none; doesn't do the trick). Has anyone tackled this before, or does anyone know of a more elegant solution to the conundrum that I have found myself in?
      The Foreachloop:
      $printclass = 1; foreach($page->galleries as $gallery) { $printclass++; $printimage = $gallery->gallery_image->width(600)->url; $out = ""; $out .= "<div class=\"row\">"; $out .= "<div class=\"grid-12\">"; $out .= "<img src=\"{$gallery->gallery_image->url}\" class=\"reimage\"/>"; $out .= "</div>"; $out .= "</div>"; $out .= "<div class=\"row\">"; $out .= "<div class=\"grid-12\">"; $out .= "<a href=\"#\" onClick=\"printCoupon('printable{$printclass}');\">Print</a>"; $out .= "</div> "; $out .= "</div> "; $out .="<div id=\"printable{$printclass}\"><img src=\"{$printimage}\"/></div>"; echo $out; }  
       
    • By cosmicsafari
      Hi All,
      I was playing around with the settings for various templates as I had created a new role and have inadvertantly locked myself out.
      I changed some of the settings on the Admin template, so I assume this is what has caused the lock out.
      I have direct access to the database but I have no idea what I would need to change in it to regain access.
      Probably also worth mentioning that all the existing pages are still accessible, but /processwire throws a 404.
    • By Martin Muzatko
      Hello!
      I'm trying to use the data I create in Processwire as much as possible.
      So for a form, I try to use the fields description, name and also its built-in validation rules I defined in ProcessWire on the front-end. (minlength, ranges, patterns, etc)
      I already looked into this tutorial, but it is using external resources to validate the form.
      Since ProcessWire does all the heavy lifting, when processing data, I don't have to sanitize anything - ___processInput should do the job just fine.
      However, it is not actually working correctly. 
      $fields = $templates->get('user')->fields; $submission = $input->post; foreach ($submission as $key => $value) { $field = $fields->{$key}; if ($field instanceof Field) { $field = $field->getInputfield($user); $field->___processInput(new WireInputData([$key => $value])); var_dump($field->getErrors(true)); // retrieve validation error } } This works for some constraints, but the values are not correctly validated.
      Example: 

      All the fields are required and zip is an integer field.
      Yet, I get no validation error for zip, although it was entered as a string, and not an integer. Funny enough: if I provide a number outside the range, I get "Specified value 2 removed because it is out of bounds (min=1000, max=99999)".
      firstname will not return any error for being a required field.
      From what I have looked through the source code, there is no check for "required". Some fields only validate on setAttribute. Am I missing anything or am I doomed to build my own validation process?
      Thank you in advance!
      Best,
      Martin
    • By thomas
      Hi,
      I want to extend PagesType to get a new `Product $products` variable in the API. Problem is, I have about a million (well, about 50) different templates for the products so `addTemplates()`  can be difficult. Without a template, `pagesType` throws notices (`Trying to get property of non-object in wire/core/PagesType.php on line 161`). Is there a way to extend `pagesType` without specifing templates or by specifying a template group?
      Thanks, thomas