kixe

Name Format Children

75 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

Love this module but I'm having an issue. This import script worked for me outside my module, but now I'm including it inside a module, and getting the following error upon install: 

Quote

Fatal Error

Call to a member function getLanguageValue() on string search►

Source file

File: .../ProcessSetupPageName.module:121

111: foreach ($formats as $_format) { 112: $_format = trim($_format, " \t\n\r,}{'\""); 113: if (!strlen($_format)) continue; 114: $_pageName = $this->createFromFormat($page, $_format, $languageID); 115: if ($_pageName == false) return false; 116: $pageName .= '-'.$_pageName; 117: } 118: } 119: 120: // case 2: title default
121: else if ($format == 'title' && strlen($page->title->getLanguageValue($languageID)))
{ 122: $pageName .= '-'.$page->title->getLanguageValue($languageID); 123: } 124: 125: // case 3: date()

Culprit file:

<?php namespace ProcessWire;


importUsers(__DIR__.'/data/users.csv');

function importUsers($filepath) {
  $csv = array_map('str_getcsv', file($filepath));
  array_walk($csv, function(&$a) use ($csv) {
    $a = array_combine($csv[0], $a); # set header keys
  });
  array_shift($csv); # remove column header
  //echo '<pre>'; print_r($csv); echo '</pre>';
  foreach($csv as $r) {
    $u = new User();
    $u->of(false);
    foreach($r as $k=>$v) {
      $v = trim($v);
      if($k == 'name') {
        if($v == '') $u->$k = wire('sanitizer')->pageName($u->email);
        else $u->name = wire('sanitizer')->pageName($v); continue;
      }
      if(wire('fields')->get('name='.$k)) {
        $fieldtype = wire('fields')->get('name='.$k)->type;
        if($fieldtype == 'FieldtypeMapMarker') {
          $u->$k->address = (string)$v;
        }
        elseif($fieldtype == 'FieldtypeImage') {
          $imgs = explode('|', $v);
          foreach($imgs as $i) {
            $u->$k = $i;
          }
        }
        elseif(in_array($fieldtype, ['FieldtypeText', 'FieldtypeTextarea', 'FieldtypeInteger', 'FieldtypeCheckbox', 'FieldtypePassword', 'FieldtypeEmail'])) $u->$k = $v;
      }
      if($k == 'roles') {
        $roles = explode('|', $v);
        foreach($roles as $role) {
          $u->addRole($role);
        }
      }
    }
    if(!$u->hasRole('guest')) $u->addRole('guest');
    $u->save(); //echo '<br>';

    if($u->password == '') {
      $u->password = crypt($u->email, $u->id);
      $u->save();
    }
  }
}

// email users welcome & verify


$mmpid = wire('pages')->get('template.name=mamo_makes')->id;

importCSV(__DIR__.'/data/manufacturers.csv', 'mamo_manufacturer', $mmpid);
//importCSV(__DIR__.'/data/models.csv', 'mamo_model', 0, $mmpid);
//importCSV(__DIR__.'/data/vessels.csv', 'boat_vessel', wire('pages')->get('template.name=boat_index')->id, 0);

function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) {
  $csv = array_map('str_getcsv', file($filepath));
  array_walk($csv, function(&$a) use ($csv) {
    $a = array_combine($csv[0], $a); # set header keys
  });
  array_shift($csv); # remove column header
  //echo '<pre>'; print_r($csv); echo '</pre>';
  foreach($csv as $r) {
    $p = new Page();
    $p->template = $template;
    if($parent_id !== 0||null) {
      $p->parent_id = $parent_id;
    } elseif($parent_id == 0||null) {
      //echo $r['parent'].' ';
      $parent = wire('sanitizer')->pageName($r['parent']);
      $parent = str_replace('---','-',$parent);
      //echo $parent.' ';//echo $grandparent_id.'gp ';
      $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id;
      //echo $parent.'p ';
      $p->parent_id = $parent;
      unset($r['parent']);
    }
    $p->save();
    $p->of(false);
    foreach($r as $k=>$v) {
      $v = trim($v);
      $fieldtype = wire('fields')->get('name='.$k)->type;
      if($fieldtype == 'FieldtypeMapMarker') {
        $p->$k->address = (string)$v;
      }
      elseif($fieldtype == 'FieldtypeImage') {
        $imgs = explode('|', $v);
        foreach($imgs as $i) {
          $p->$k = $i;
        }
      }
      else $p->$k = $v;
    }
    $p->save(); //echo '<br>';
  }
}

The above portion (users) runs through ok. It's the latter section that produces the error. What is the string being referred to, how can I remedy this? Any ideas as to how I can troubleshoot?? Thanks a ton.

Share this post


Link to post
Share on other sites

It seems that the module isn't working anymore on websites without languages core modules installed. I've upgrade the module from 2.0.3 to 2.0.7 on a live website (without languages core modules installed) and when I tried to add a page that used by this module the page didn't even saved as unpublished and there was an error. I forgot to copy the error cause I was in hurry to switch back the module to the 2.0.3 version. I hope @kixe can fix it.

Share this post


Link to post
Share on other sites

Well I added this now it works not ideal and wasn't needed before but whatever 


    if($template == 'boat_vessel') $p->name = wire('sanitizer')->pageName($r['boat_model']) . '-' . wire('sanitizer')->pageName($r['title']);
    else $p->name = wire('sanitizer')->pageName($r['title']);

 

Share this post


Link to post
Share on other sites

PWaddict I suspected that and installed Languages Support. Prior to doing so it was actually producing a different error earlier up in the module file. Forgot to mention that. But installing it didn't solve the problem for me.

Share this post


Link to post
Share on other sites

@hellomoto

10 hours ago, hellomoto said:
111: foreach ($formats as $_format) { 112: $_format = trim($_format, " \t\n\r,}{'\""); 113: if (!strlen($_format)) continue; 114: $_pageName = $this->createFromFormat($page, $_format, $languageID); 115: if ($_pageName == false) return false; 116: $pageName .= '-'.$_pageName; 117: } 118: } 119: 120: // case 2: title default
121: else if ($format == 'title' && strlen($page->title->getLanguageValue($languageID)))
{ 122: $pageName .= '-'.$page->title->getLanguageValue($languageID); 123: } 124: 125: // case 3: date()

This issue was fixed in late 2016 (module version 2.0.0 or 2.0.1). Please update to last version and try again.

@PWaddict
I pushed a fix and tested the module in 3.0.64. Please update to 2.0.8

2 people like this

Share this post


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

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?

Wow you fixed that issue. Now it's working properly. Thank you so much :)

2 people like this

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 bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By Xonox
      Hi,
      I need to add the original image dimensions (width x height) for the images inserted in the body field, in a few data-fields. Something like:
      <a href="/site/assets/files/1092/image-1.jpg"> <img alt="" src="/site/assets/files/1092/image-1.690x0-is.jpg" width="690" data-width="1500" data-height="1000 "> </a> Where data-width and data-height are the image-1.jpg dimensions.
      I tried to do this through a file, to control the field output:
      templates/fields/post/body.php But turns out the body comes already formatted from the DB, so I can't override the image display, unless I use some cumbersome str_replaces. Even with this solution, it's impossible to achieve the desired result.
      Is there any way I can do this through a ProcessWire process?
      I know it can be done through php, reading the file's header to extract the height and width and then do a str_replace on the body string to insert the desired code. However I'm curious if it can be done in any simpler and more effective way, without having to read the files from disk and do the replaces.
      Thanks,
    • By cosmicsafari
      Hi all,
      I am creating a page field (field of type FieldtypePage) via the API, however im still trying to find some documentation as to how I would go about setting the Selectable Pages for said field using the API.
      From what I have found it looks like it involves the use of, albeit this looks like a getter rather than a setter:
      $field->getInputfield($page) Which looks like it would make sense if I wanted to specify the selectable pages by a parent page, but what if I wanted to specify it by say a template?
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend