Jump to content

markus_blue_tomato

Members
  • Posts

    192
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by markus_blue_tomato

  1. 24 minutes ago, Gadgetto said:

    Austria 2020-03-13 14:00: 361 Covid-19 cases, 1 dead. Starting with coming Monday all shops (except grocery stores, post office, banks, gas stations and similar) closed, schools closed! Some ski areas under complete quarantine. Borders closed. People are hoarding shops. It's really creepy! This is how I imagine the beginning of the Zombie Apocalypse!

    But our neighbor country Italy is hit much harder: about 15.000 cases, more then 800 dead! Hold on through people!

     

    People buying 4 things in crazy amounts: noodles, rice, toiletpaper and BEER ?

  2. In Austria the whole thing becomes creepy. schools closed, event/restaurants with more than 100 people are not allowed, borders to italy closed, other countries closed border to Austria, gov. want's that companies should make homeoffice etc.

    Our company make home office beginning tomorrow.

     

  3. Oooh - Thanks that was my problem: I have set the value on the image field and not on the image file!

    This works:

    if($language->id == $languages->getDefault()->id) {
    	$page->images->findOne("basename=xyz.jpg")->set("my_custom_image_field", "test default language");
    } else {
    	$page->images->findOne("basename=xyz.jpg")->set("my_custom_image_field__{$language->id}", "test language {$language->name}");
    }

     

  4. I found this new "setFieldValue" function in the pw dev commits: https://github.com/processwire/processwire/commit/573048abb4a6bdec77aee2cbff7d5837de857a05#diff-b4e6cafb51396ac6ada1a538da0ddc8cR639

    I tried following:

    if($language->id == $languages->getDefault()->id) {
    	$page->images->setFieldValue("my_custom_image_field", "test default language");
    } else {
    	$page->images->setFieldValue("my_custom_image_field__{$language->id}", "test language {$language->name}");
    }

    I get no error, but all fields are still empty ?

    I will continue my investigations... Maybe @ryan has an idea?

    Also strange: the function should return true or false but if I dump the return of setFieldValue, I get only an empty string back.

  5. I'am working on a migration script from the ImageExtra Module to the new Custom Image Fields feature in ProcessWire.

    I have some problems while setting a field value to the new custom image field. I have set up the custom field and it works correct in the admin panel but not via the API:

    $page->images->my_custom_image_field = "test";
    $page->save();

    Results into:

    Fatal error: Uncaught ProcessWire\WireException: Item 'my_custom_image_field' set to ProcessWire\Pageimages is not an allowed type in /var/www/html/wire/core/WireArray.php:458

     

     

  6. 11 hours ago, teppo said:

    I haven't had the chance to see this in action yet, but looking at the code I'm wondering about one thing: at least in my case it's often important to know exactly when a particular issue first occurred, so that I can figure out what might've caused it – but if that initial occurrence is now removed, doesn't this make that process difficult, if not impossible?

    My initial thinking is that perhaps we should also store the timestamp for the first occurrence along with the counter data. That would, in my opinion, be an improvement over just logging the latest case along with a counter.

    While debugging a strange issue it's sometimes also helpful to know about the exact timestamps of all occurrences, but then we're basically back at not having this feature at all ?

    Overall I can see value in this, particularly from the UI point of view and for those cases where you're somehow spammed with a truckload of identical log entries, but I'm also a bit concerned that it could make debugging problems harder. As such, it might actually be a good idea to allow disabling this feature altogether; this way users could still opt-in for "full logging" instead if that works better for their workflow.

    Some possebility to fold/expand duplicates in the log view would be great.

    • Like 1
  7. I found a solution which works:

    //users current language is for example: german
    // language "default" is english
    
    $key = "lorem_ipsum";
    $string = __($key, "path/to/my/textdomain.php");
    
    if($key == $string && wire('user')->language->name != "default") {
    	wire('languages')->setLanguage('default');
        $string = __($key, "path/to/my/textdomain.php");
        wire('languages')->unsetLanguage();
    }
    
    echo $string;

     

    • Like 2
  8. Is it possible to get the value of a specific language in ProcessWire's translation tools?

    What I want to is following: Before printing out $key as fallback, I want to use a "fallback" language. Only after the fallback language has also no result, the $key should be printed out.

    //users current language is for example: german
    
    $key = "lorem_ipsum";
    $string = __($key, "path/to/my/textdomain.php");
    
    if(empty($string)) {
    	$string = __($key, "path/to/my/textdomain.php", "english");
    }
    
    echo $string;

    And yes I know I could put the fallback into the code as key, but I don't want this. If the fallback has to change, the customer can't do it on his own and I have to to this with a full deployment.

  9. @Wanze

    I ended up in using your solution but to avoid writing the key everytime in two files per hand I created a node.js script which is executed in my build script of the whole project.

    The scripts reads all translatable strings from my .tpl files which look like this {translate}Lorem Ipsum{/translate} and creates in every view-directory a translation.php file.

    If anyone needs it here is the code of the node.js module (you have to install async and glob via npm..)

    "use strict";
    
    const glob = require('glob');
    const async = require('async');
    const fs = require('fs');
    
    // find all directories
    glob("site/templates/views/**/", null, (error, directories) => {
      // iterate in paralell over directories
      async.each(directories, function(directory, directoryCallback) {
    
        // find all template files in the current directory
        glob(`${directory}*.tpl`, null, (error, templateFiles) => {
          if(error) return directoryCallback(error);
    
          let translationKeys = [];
          // iterate in paralell over templateFiles
          async.each(templateFiles, function(templateFile, templateFileCallback) {
            fs.readFile(templateFile, (error, data) => {
              if(error) throw err;
              let tpl = data.toString('utf8');
    
              // find all keys
              let pattern = new RegExp('{translate\}(.+?)\{\/translate\}', 'gm');
              let result = tpl.match(pattern);
              if(result && result.length > 0) {
                // extract key without smarty block syntax
                // transform it to PHP syntax
                result = result.map(item => item.replace(pattern, '__("$1");'));
                // push all keys to the collector of all keys in the current directory
                translationKeys.push(...result);
              }
              templateFileCallback();
    
            });
          }, function(error) {
            if(error) console.log("Error in the templateFiles logic", error);
    
            // executed after alle keys are collected from the tpl files in the current directory
            if(translationKeys.length > 0) {
    
              // filter duplicates
              // sort alphabetical
              translationKeys = [ ...new Set(translationKeys) ].sort();
    
              // make the final PHP file
              let phpFile = [ '<?php namespace ProcessWire;', ...translationKeys ].join("\n");
              fs.writeFile(`${directory}translations.php`, phpFile, 'utf8', function(error) {
                if(error) throw err;
                directoryCallback();
              });
            } else {
              directoryCallback();
            }
    
          });
    
        });
      }, function(error) {
        if(error) console.log("Error in the directory logic", error);
    
        // all done exit the process
        process.exit();
    
      });
    });

     

    • Like 1
  10. Hello!

    I am working on a pull request, to make Smarty and Twig templates translatable within ProcessWire.

    I stuck a little bit at the RegExp patterns. Maybe some RegExp-Professional want's to help me? :-)

    Should be possible in Smarty files:

    {$this->__('text')}
    {__('text')}
    {_x('text')}
    {_n('text')}

    Should be possible in Twig Files:

    {{ $this->__('text') }}
    {{ __('text') }}
    {{ _x('text') }}
    {{ _n('text') }}

    The whole patters are in the parseFile Function: https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/modules/LanguageSupport/LanguageParser.php#L120

    /**
    	 * Run regex's on file contents to locate all translation functions
    	 *
    	 */
    	protected function parseFile($file) { 
    		$matches = array(
    			1 => array(), 	// $this->_('text'); 
    			2 => array(),	// __('text', [textdomain]);
    			3 => array(),	// _x('text', 'context', [textdomain]) or $this->_x('text', 'context'); 
    			4 => array(),	// _n('singular', 'plural', $cnt, [textdomain]) or $this->_n(...); 
    			);
    		if(!is_file($file)) return $matches; 
    		$data = file_get_contents($file); 
    		// Find $this->_('text') style matches
    		preg_match_all(	'/(>_)\(\s*' .				// $this->_( 
    				'([\'"])(.+?)(?<!\\\\)\\2' . 		// "text"
    				'\s*\)+(.*)$/m',					// and everything else
    				$data, $matches[1]); 
    		// Find __('text', textdomain) style matches
    		preg_match_all(	'/([\s.=(]__|^__)\(\s*' . 		// __(
    				'([\'"])(.+?)(?<!\\\\)\\2\s*' . 	// "text"
    				'(?:,\s*[^)]+)?\)+(.*)$/m', 		// , textdomain (optional) and everything else
    				$data, $matches[2]); 
    		// Find _x('text', 'context', textdomain) or $this->_x('text', 'context') style matches
    		preg_match_all(	'/([\s.=>(]_x|^_x)\(\s*' . 		// _x( or $this->_x(
    				'([\'"])(.+?)(?<!\\\\)\\2\s*,\s*' . 	// "text", 
    				'([\'"])(.+?)(?<!\\\\)\\4\s*' . 	// "context"
    				'[^)]*\)+(.*)$/m',			// , textdomain (optional) and everything else 
    				$data, $matches[3]); 
    		// Find _n('singular text', 'plural text', $cnt, textdomain) or $this->_n(...) style matches
    		preg_match_all(	'/([\s.=>(]_n|^_n)\(\s*' . 		// _n( or $this->_n(
    				'([\'"])(.+?)(?<!\\\\)\\2\s*,\s*' . 	// "singular", 
    				'([\'"])(.+?)(?<!\\\\)\\4\s*,\s*' . 	// "plural", 
    				'.+?\)+(.*)$/m', 			// $count, optional textdomain, closing function parenthesis ) and rest of line
    				$data, $matches[4]); 
    		return $matches; 
    	}

     

    • Like 1
  11. 10 hours ago, Wanze said:

    Uups, sorry about that. I did not think about this issue and also missed to handle the "error" case. ?So in your case, the module was generating the sitemap on every request. At least it did not affect the frontend ?Kudos to @teppo for bringing this up! ?

    Cheers

    yes, the frontend was not affected ?

  12. @Wanze haha awesome - I had checked the sitemap generation in the module config but I don't use it and the path is not writeable.

    after upgrading I got the error message and unchecked it. now my pw adminpanel runs 100 times faster.... ?

    and I thought the slowness would be normal with this amount of fields/templates/pages ?

    • Like 1
  13. I try to access wie WireHttp Class in a script executed on the command line but I'm failing hard and don't know why. Access to the Pages Class works well.

    <?php
    
    // include PW API
    include(__DIR__ . "/index.php");
    
    var_dump($wire->pages);
    
    var_dump($wire->http);
    php test.php 
    object(ProcessWire\Pages)#172 (0) {
    }
    NULL
    

    Does anyone know why? ? I tried also new WireHttp(), wire('http'), $http...

  14. How would you map the Firebase data? Each collections / document would represent a page in pw? So you would need some kind of sync tasks which are triggerd on save / trash / publish and maybe a full sync job x times.

    And what should be the single source of truth? Firebase or ProcessWire?

    • Like 1
×
×
  • Create New...