• Content count

  • Joined

  • Last visited

Community Reputation

6 Neutral

About ZGD

  • Rank
    Jr. Member

Recent Profile Visitors

931 profile views
  1. Managed to resolve this, code below for any that's interested. My translations class: <?php namespace Translations; class Translation { private function __construct() {} protected static function translations() { return []; } private static function initialize() { $languages = \ProcessWire\wire('languages'); $user = \ProcessWire\wire('user'); $translated = []; foreach($languages as $lang) { $user->language = $lang; foreach(static::translations() as $k => $t) { $translated[$k][$lang->language_code] = $t; } } return $translated; } public static function translate() { return static::initialize(); } } include_once __DIR__ . '/greetings.php'; include_once __DIR__ . '/questions.php'; Now I can create as many different translation files as I like, for example greetings.php <?php namespace Translations; use function ProcessWire\__ as __; class Greetings extends Translation { protected static function translations() { return [ 'hello' => __('Hello'), // A casual greeting message 'goodbye' => __('GoodBye'), // A casual departing message ]; } } and questions.php <?php namespace Translations; use function ProcessWire\__ as __; class Questions extends Translation { protected static function translations() { return [ 'howareyou' => __('How are You?'), 'howmuch' => __('How Much?'), ]; } } So in my template I can now write: <?php use Translations\Greetings; use Translations\Questions; $greetings = Greetings::translate(); $questions = Questions::translate(); // ... output here
  2. I'm using PW to build an API which returns data in multiple languages at once. For example I might have the words "Hello" and "Goodbye" that need to be translated into several languages. The API (which returns data as JSON) needs to return something like the following... { "hello": { "de": "Hallo", "en": "Hello", "fr": "Bonjour", "it": "Ciao", "tc": "你好" }, "goodbye": { "de": "Auf Wiedersehen", "en": "Goodbye", "fr": "Au Revoir", "it": "Addio", "tc": "再見" } } Ideally I'd like to be able to use PW's template string translating feature, as there will be potentially hundreds of different translations and creating many fields seems the wrong way to go. Each translation will also need to have a note or description alongside it. I was originally thinking something like the example below may be possible, but it seems unlikely. <?php function _t($translation) { // logic to return all translations here... return $translation; } $translations = [ 'hello' => _t(__('Hello')), // A casual greeting message 'goodbye' => _t(__('Goodbye')) // A casual departing message ]; echo json_encode($translations); Can anyone suggest a good method for returning all translations of a translatable string? Is it even possible to access multiple translations of static strings within a template? Alternatively, if anyone has solved a similar problem before, I'm open to suggestions. Thanks!
  3. I'm also seeing this, did you find a workaround? EDIT: Prepended the ProcessWire namespace to the wirePopulateStringTags method which seems to have fixed the problem for now.
  4. @kongondo Do you know if this is something that is being built already? I'd like to contribute if possible.
  5. Thanks @LostKobrakai. That all makes sense. I'd estimate less than 5% of images will have alternatives, so the manual uploading for those would be manageable. Being able to drag and drop multiple images at once is really the priority, but I had a better look through all the core modules earlier and decided the development time to create something custom probably wasn't worth it for this project. I looks like we will have to go with a repeater or pagetable approach as you've suggested.
  6. Nope not quite, sorry I probably wasn't very clear there. Drag-and-drop does indeed work inside repeaters, my problem is that if I need to separate each image and its associated crop in the image grid into a separate repeater with an image field then I can't drag-and-drop say 20 images at once. I have to manually drag each image to the associated field in the repeater array. An ideal situation would be the ability to store a secondary image with each image. For example each image has an input for alt text, I would somehow like there to be another input for another image. Essentially nested images. CroppableImage3 is great but it also won't work for this as the images are prepared outside of PW as they have various other applications. The crops also aren't systematic and we also need to support the option for the crop being a completely different image entirely.
  7. I'm currently developing a site where some image fields need to be able to have two images associated with them, a thumbnail and a full sized image (which is often a different crop) which will be shown in a lightbox view. This is fine for most templates, I'm just using normal image fields that return an array and support up to two images. If a second image is present in the field then it will be used as the alternative image for the lightbox. If only one image is present, it will be used for both thumbnail and full sized (the template resizes for the thumbnail using the API). However I have templates with flexible layouts using a repeater matrix, and one of the matrix types is an 'image grid'. This is an image field that supports an unlimited number of images, so obviously this method is not suitable here. I've tried creating a repeater in this matrix type which contains an image field (each supporting two images, as above), but this means that I can no longer drag and drop multiple images at once. Each image in the grid has to be uploaded individually which is a big problem as there are many instances of these grids with a large number of images. I've tried the ImageExtra module but it seems you can't add an image field as a secondary field. Any suggestions as to how I might solve this problem?
  8. I've looked through the forum and various issues on Github and can't seem to find a definitive answer for this. It seems some Lazycron hooks have stopped working reliably on one of my PW installations. The function which adds the hooks is triggered successfully every minute and logs a message (I've tested the cronjob and it is working correctly), however it seems the hook itself is being very temperamental. This line in the module's init method should add a hook for every minute: $this->addHook("LazyCron::everyMinute", $this, 'myFunction'); The first line of myFunction logs a string whenever it is executed, before doing anything else. I've been watching the module log all day and this function seems to execute each minute up to around 5 times, and then stops executing. I've been monitoring the site's cache folder, and sometimes deleting the LazyCron.cache file resolves the problem temporarily, other times it does not. Sometimes if I leave everything alone for a few hours, myFunction starts executing again. Unlike other people who have reported similar issues, I don't have have a LazyCronLock.cache file that is causing problems. I can't work this one out, has anyone encountered something similar?
  9. Ah I understand now, I hadn't realized single quotes were used for literal strings. All makes sense and the above code seems to do the trick, thanks once again!
  10. No luck with that unfortunately, still lots of fragmented lines. Do the instances of '\r\n' need to be wrapped in double quotes? I can't work out the logic here! I should also note that these strings can include \r\n but are also sometimes littered with instances of \r or \n individually.
  11. I think I may have found a small problem with WireQueueTextfile, although it could be due to this PHP bug? The array is being serialized in the addItem() function, but in my case an element's value is sometimes a string containing newline characters "\r\n". I believe WireQueueTextfile saves each array to one line, but these characters are causing the serialized string to be split onto multiple lines, which I'm assuming causes problems for WireQueue. Would it make sense to somehow sanitize these values (outside of WireQueue) before adding them to the queue?
  12. Thanks LostKobrakai, works perfectly. I'll think about creating a new/modified field for pre-generating variants for future use.
  13. I've been using PW for a few years now and I believe this is the only problem I frequently encounter, although this latest case is particularly relevant. I'm sure there must be a simple solution, but I've yet to work it out. Thanks to a great collaboration with a member of the community, we have a website (still in development...) that imports data from an external service into PW via a JSON feed. The import process can create hundreds of pages with new images that are saved from URLs specified in the feed. As these can be very high resolution, we use the $image->size() method to resize them to acceptable dimensions. As this import process is happening constantly in the background, images on certain pages are constantly changing. This means a large number of images may not have variants generated until that page is visited by a user, and that process can take quite a while. Some pages have 50+ images (lazyloaded!). What is the normal way of solving this problem? I'd considered writing a module that would imitate a user visit to these pages each time they are saved and thus generate the variants. Is there a simpler solution?
  14. Thanks matjazp and adrian. Looks like I was trying to access the filesize property of an array of files rather than the files themselves. All solved now, might post the module up somewhere when I get a chance.
  15. Sorry adrian, you're right, I don't know why I mentioned $file->title! $file returns the filename, I must have been thinking of that. Updated question with strikethrough. No errors, and filesize($file->filename) also returns nothing unfortunately. Code below from the module: public function ___execute() { // this will be dynamic later $fieldname = "image"; $old_name = ""; $pagesWithImages = wire('pages')->find($fieldname.".count>0, sort=title"); $allImages = array(); foreach($pagesWithImages as $p) { $imagedata = $p->get($fieldname); if (is_array($imagedata)) { foreach($imagedata as $image) { $allImages[] = $image; } } else { $allImages[] = $imagedata; } } $out .= "<h3>".count($allImages)." images found.</h3>"; if (count($allImages)) { $adminURL = $this->config->urls->admin; $table = $this->modules->get('MarkupAdminDataTable'); $table->setEncodeEntities(false); $table->headerRow(array( $this->_x('Page', 'list-table'), $this->_x('Filename', 'list-table'), $this->_x('Filesize', 'list-table') )); foreach ($allImages as $i) { $pg = $i->page; $pagelink = "<a target='_blank' href='".$adminURL."page/edit/?id={$pg->id}'>".$pg->title." (".$pg->id.")</a>"; $filesize = filesize($i->filename); $table->row(array( $pagelink, $i, $filesize )); } $out .= $table->render(); } return $out; }