Jump to content

MilenKo

Members
  • Content Count

    425
  • Joined

  • Last visited

Community Reputation

107 Excellent

1 Follower

About MilenKo

  • Rank
    Sr. Member
  • Birthday September 17

Contact Methods

  • ICQ
    99982787
  • Skype
    mikemastercorp

Profile Information

  • Gender
    Male
  • Location
    Montreal, Canada
  • Interests
    Web development, coding, Network infrastructures, Linux, BSD, Windows, Cisco, Photography, Cooking

Recent Profile Visitors

2,050 profile views
  1. Great share, @Edison I will definitely test this in my next profile. How would I add the honeypot if I am using custom forms and modifying the module placing it in /site/modules/FieldTypeComments ?
  2. Hello there. I know this is a quite old topic, however I was facing the same issue and fount an easy way to handle the browser errors: in my form I had the following: $first_name_error = translate('Missing first name'); I've added my translation string to _strings.php: _x('Missing first name', 'General'); And then in my HTML markup I had the following code showing the translation: <div class="form-group col-lg-6 col-md-12 col-sm-12"> <input type="text" name="first_name" placeholder="{$first_name}" required="" oninvalid="this.setCustomValidity('{$first_name_error}')" oninput="this.setCustomValidity('')"> </div> Btw, the same approach was taken for the placeholder as well so $first_name was translated as well in my _strings.php For sure, @soma suggested long time ago, one can disable all the error messages, however if you would prefer to have the tooltip active, this is a nice and easy way to achieve it. It took me a few hours to find the right approach, so hopefully the next one won't have to spend that much time. So far it worked with Opera, IE, Edge, Chrome. I did not test with Safari, but doubt it won't work as well 😉
  3. I had a similar issue, but in my scenario (with no module modifications) the line causing it was 58 if(count($values)){ I can confirm that changing the line to @Macrura correction eliminated the error in my logs.
  4. @Kai2000 Hello Kai and welcome to the PW Forum. I remember having a battle with my comments list and comments form the first time I needed to implement those and I was able to manage it with ratings, custom styling and inline replies. Here is the topic for you in case you haven't found it. With your own custom markup for the comments list and/or comment form I would suggest as the easiest way to copy the FieldType Comments module from /wire/modules to /site/modules and apply all the custom styling to this version. As I see, @Edison beat me on this and he also helped me to show comments based on the user/site language. Just follow the steps to select your new module copy from the admin (listed in one of the links of Edison and you would have your markup in no time. It seemed a bit confusing for me at the beginning, but you will get used to it and be able to manage any complexity of your comments. Should you have some difficulties understanding the code or adding a copy of the module, feel free to reach back to me and I will be glad to help 😉
  5. Hey everyone, I got some great news about the proper date showing of ProcessWire in Russian. There are different approaches depending on the format to present the date. Here are the two best fitting the purpose: Approach 1: Approach 2: Even though I personally liked the second approach better since it just use the proper month number that would return the same value in any language, for the Russian proper date appearance I took much simpler solution where all I had to do was to swap the day and the month since plenty of websites were using it already. In a scenario where the month is first and then the date, there is ABSOLUTELY NO NEED to conjugate the month name and the date is appearing still gramatically and esthetically correct: Июль 31, 2019 To allow different date formatting per language (the default way of setting the locales did not work on my server) I've modified a bit the code I've added earlier to my header.inc: And was able to finally have the date properly showing in all selected languages by calling it inside the HTML markup: <?php // STRFTIME FUNCTION DATE FORMAT: // https://www.php.net/manual/en/function.strftime.php // $date_format - defined in /sites/includes/head.php for every language // $l->published/created shows the date the page was published/created // $locale - defined in head.php as well setting the proper locale for every language echo strf_time("{$date_format}", $l->published, $locale); ?> Please note that this approach would work for date() and strftime and there is actually no need of adding the extra DateTime field nor is necessary the code at /site/ready.php , however I've decided to leave it as it is for the learning curve and if a need be, to have a better option to manipulate the date. As far as the head.inc is included in every template of the profile but I would only need it to a few that would show the creation/publishing date, I might add a check for the page ID and include the header to only those templates that need it, however these things are some simple steps so I won't go any deeper there. Hope it helps to anyone needing to present a date in Russian or any other language that would require some names that differ from the standart PHP date/time function result. Case closed now! P.S. Forgot to mention that the strf_time is a function that I've used to my _func.php to convert the month name to utf-8 which I use by default in my profile: /** * Convert date/time stamp from different characters to utf-8 */ function strf_time($format, $timestamp, $locale) { $date_str = strftime($format, $timestamp); if (strpos($locale, '1251') !== false) { return iconv('cp1251', 'utf-8', $date_str); } else { return $date_str; } }
  6. OK, folks. I got a prototype of fully working month names Russian ranslation that works perfectly by creating an array with the proper month names and then showing the array result for the number of the present month. Simple and elegant, but I decided to go further now and create an unified version of translation function which would check the user selected language, set the proper locale and echo the month name either from the array for the Russian translation or directly. I am surprised that I did not see any solutions for that here yet 🙂 Having a universal function would allow me to use it over and over again for any websites that would have the Russian in the languages list simply by inserting it to my _functions.php 😉
  7. After giving it some thought, It really messes up the things when one see the month in Russian language without the proper termination so I will have to find a way to translate the month name to the proper one in order to make it gramatically correct. It would be great if some of the russian techies could share their experience 😉
  8. Alright, I got it all sorted out and is working on my Unix & Windows hosts both locally and online. In case someone stumbles upon the same issue, here is what worked for me to have cyrillic languages and 1252 ones working fine: 1. Add the following code to _functions.php or other file that you use for your functions: /** * Convert date/time stamp from different characters to utf-8 */ function strf_time($format, $timestamp, $locale) { $date_str = strftime($format, $timestamp); if (strpos($locale, '1251') !== false) { return iconv('cp1251', 'utf-8', $date_str); } else { return $date_str; } } 2. Add this code to your head.inc (note that head.inc is included in all my templates) <?php // Check the user language name // Assign the language locale to $locale // Windows locale source: https://docs.moodle.org/dev/Table_of_locales switch($user->language->name) { // Default language is English case 'default': $locale = setlocale (LC_ALL, 'en_US.UTF-8', '-parent en_utf8 used-'); break; // Bulgarian language locale case 'bulgarian': $locale = setlocale (LC_ALL, 'bg_BG.utf8', 'Bulgarian_Bulgaria.1251'); break; // Russian language locale case 'russian': $locale = setlocale (LC_ALL, 'ru_RU.utf8', 'Russian_Russia.1251'); break; // French language locale case 'french': $locale = setlocale (LC_TIME, 'fr_CA.UTF-8', 'French_Canada.1252'); break; } ?> 3. Add a field to your templates that you would like the date to appear (set the field as DateTime) and no date/time format. In my scenario I called it 'date_created' 4. Assign the field to all templates where the custom date would be needed (in my scenario I assigned it to news-inner.php as I am grabbing some news pages to show on the main page). Note that I assigned the date field to the inner page of every news, but not to the parent or Home. 5. Add this code to your ready.php (if you don't have one create it at ../site/ready.php (where your config.php resign 😉 ). Inside of this file add the following hook (Thanks to @Edison for the code!) $wire->addHookBefore('Pages::saveReady', function($event) { $page = $event->arguments(0); if($page->hasField('date_created')) { $page->date_created = time(); } $event->arguments(0, $page); }); Please note that you need to replace 'date_created' with your custom date field (unless you follow steps 1x1). 6. In your markup where the MULTILANGUAGE ENABLED DATE is needed, use the following call: <?php echo strf_time("%d %B %Y", $l->date_created, $locale);?> Note: Feel free to change the date appearance format using PHP strftime function format Well, that is it, it works fine with me and showing all the languages properly now. If you would like to go further, some of the months that are having more than 3-4 letters in the abbreviation could have a dot after the name, however for this you should create an array with the shorter months and show the dot if it is not one of those or do some magic counting the letters of the month and if the result is higher than 3-4 to show it, but I did not go that way as it is working as the original markup 😉 Another issue I noticed is the Declination of the names of the months when displaying the date in Russian. I found a function that could heal that, however I hightly doubt I would need it. In case someone wants to play with it and adapt it for PW, here it is . Note, that the page is in Russian so you might need a translator or just read the code.
  9. After a decent night sleep and my morning coffee I had some progress towards resolving my issue. While searching the Internet I found some useful pieces of code that I was able to put together to test my server setlocale. As it appears, it is all running properly with only one issue where for the cyrillic letters to appear properly, I needed to use iconv to convert them to UTF-8: The result of the script gave me this: mardi, juillet 23 вторник, Июль 23 вторник, юли 23 Tuesday, July 23 So now I will look for a way to use the function and apply it to all locales which should not affect the French/English date but will make the proper appearance of the cyrillic chars. Since I am on a Windows host, I had to use the Windows locales instead of the unix format, however running the code on my unix host returned the proper values as well so it seems like this solution is multiplatform one 😉
  10. @Edison Hey man, adding the brackets and semicolon did the trick. Now the date gets populated during the saving and I don't have to add the earlier code to the footer of the templates. However, this did not help much to have the month translated and it still shows the month on English for any of the languages. Will try to move the profile to my real host which uses linux so that I can be sure that setlocale is setup and working properly. Maybe there is no issue but just the local server is messing things up. Moving the site to my live host did not solve the issue. There has to be something else that is messing up the things. P.S. Double checked that the DateTime field has the date format for every language as well as that the setlocale is properly set for every language as: bg_BG.utf-8, ru_RU.UTF-8, fr_FR.utf-8 and C (last one for English) Strange enough, only the date translation is not working but all other translated strings do work.
  11. @Edison Will try that once I get back to my place in a bit as I decided to step back from the problem and then hit it with fresh power and some caffeine 🙂 With the page->save approach all my dates were properly populated, so step one is completed, however when I echoed the date, it still does not change with the language switch. Starting to think that the issue might be caused by not adding the language packs or some field settings I've missed...
  12. @Edison - another error, but this time on the closing bracket
  13. @Edison The code returned an error: P.S. With a bit of more digging, I was able to populate the value of $page->creaded by inserting the following code to my news-inner template: <?php $page->of(false); // date_created is my custom DateTime field for storing the value // To avoid date changes every time I edit the page, a check if the field is empty is added if($page->date_created == '') $page->set('date_created', $page->created); $page->save(); ?> Now I will test for multilanguage support and if it works, will report back 🙂
  14. @Edison There are no stupid questions especially when someone is trying to help without knowing all the facts. Unfortunately, even though I have full access to my server, I can't check /etc/default/locale as I am on a Windows server using OSPanel as my webserver. To make my life easier and to learn something new, I've added a new field called: date_created and set it as DateTimeField. Now the only thing left is to figure it out how can I save the value of $page->created to that field and to test the translation there. As I've mentioned earlier, maybe the issue is that I did not install any of the language packs available but only created the languages and added my _strings.php for frontend translation. As the owner of the website would be a super user, he does not want to have his admin and modules translated. I've added this code to my template footer: /* turn of output formating so PW do not give an error when we change the value */ $page->of(false); $page->date_created = time(); /* save the date_created field */ $page->save('date_created'); /* turn on output formating so PW work as it should */ $page->of(true); but for some reason it does not want to populate the value of $page->created to the date_created field... P.S. Since I am working on a testing profile, I can mark the option "default to todays date" and it would start saving the date/time, however if this was a profile with hundreds of pages that should preserve their creation date then I will have to populate somehow the value of $page->created to my DateTime field..
  15. @Edison I echoed the setlocale and it does not change for the language showing this for all of them: LC_COLLATE=C;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C I just noticed that I have a lang="en" in my html opening tag. Could it be because of that?
×
×
  • Create New...