PWaddict Posted May 5, 2017 Share Posted May 5, 2017 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? Link to comment Share on other sites More sharing options...
PWaddict Posted May 5, 2017 Share Posted May 5, 2017 @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. Link to comment Share on other sites More sharing options...
kixe Posted May 5, 2017 Author Share Posted May 5, 2017 @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 language-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 Link to comment Share on other sites More sharing options...
PWaddict Posted May 5, 2017 Share Posted May 5, 2017 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 language-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 Link to comment Share on other sites More sharing options...
kixe Posted May 5, 2017 Author Share Posted May 5, 2017 @PWaddict Thanks for pointing on LanguageSupport::_('C'). I pushed an update 2.0.5 which is aware of this. Link to comment Share on other sites More sharing options...
PWaddict Posted May 5, 2017 Share Posted May 5, 2017 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. Link to comment Share on other sites More sharing options...
kixe Posted May 5, 2017 Author Share Posted May 5, 2017 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. Link to comment Share on other sites More sharing options...
PWaddict Posted May 5, 2017 Share Posted May 5, 2017 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... Link to comment Share on other sites More sharing options...
kixe Posted May 5, 2017 Author Share Posted May 5, 2017 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 Link to comment Share on other sites More sharing options...
PWaddict Posted May 5, 2017 Share Posted May 5, 2017 @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? Link to comment Share on other sites More sharing options...
PWaddict Posted May 6, 2017 Share Posted May 6, 2017 @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. Link to comment Share on other sites More sharing options...
kixe Posted May 6, 2017 Author Share Posted May 6, 2017 @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. Link to comment Share on other sites More sharing options...
PWaddict Posted May 6, 2017 Share Posted May 6, 2017 @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-2018german: 17-okt-2018 Link to comment Share on other sites More sharing options...
kixe Posted May 6, 2017 Author Share Posted May 6, 2017 It works for me, since I didn't use comma separated multiple values. With latest version it should work for your settings too. 1 Link to comment Share on other sites More sharing options...
PWaddict Posted May 6, 2017 Share Posted May 6, 2017 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. Link to comment Share on other sites More sharing options...
kixe Posted May 6, 2017 Author Share Posted May 6, 2017 @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. Link to comment Share on other sites More sharing options...
PWaddict Posted May 6, 2017 Share Posted May 6, 2017 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 Link to comment Share on other sites More sharing options...
kixe Posted May 6, 2017 Author Share Posted May 6, 2017 @PWaddict Thanks. I could reproduce. I will try to fix this. Link to comment Share on other sites More sharing options...
PWaddict Posted May 12, 2017 Share Posted May 12, 2017 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. Link to comment Share on other sites More sharing options...
hellomoto Posted June 17, 2017 Share Posted June 17, 2017 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. Link to comment Share on other sites More sharing options...
PWaddict Posted June 17, 2017 Share Posted June 17, 2017 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. Link to comment Share on other sites More sharing options...
hellomoto Posted June 17, 2017 Share Posted June 17, 2017 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']); Link to comment Share on other sites More sharing options...
hellomoto Posted June 17, 2017 Share Posted June 17, 2017 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. Link to comment Share on other sites More sharing options...
kixe Posted June 18, 2017 Author Share Posted June 18, 2017 @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 Link to comment Share on other sites More sharing options...
PWaddict Posted June 19, 2017 Share Posted June 19, 2017 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now