Jump to content

Markus (Blue Tomato)

  • Content Count

  • Joined

  • Last visited

  • Days Won


Markus (Blue Tomato) last won the day on June 20 2019

Markus (Blue Tomato) had the most liked content!

Community Reputation

86 Excellent

About Markus (Blue Tomato)

  • Rank
    Full Member

Contact Methods

  • Website URL

Profile Information

  • Location
    Graz, Austria

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. 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}"); }
  2. 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.
  3. 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
  4. Some possebility to fold/expand duplicates in the log view would be great.
  5. 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;
  6. 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.
  7. @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(); }); });
  8. I want to avoid to collect the strings in the PHP file and ProcessWire does not find the strings when they are in Smarty or Twig syntax.
  9. 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; }
  10. yes, the frontend was not affected 😂
  11. @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 😀
  12. aaah, the missing 'namespace ProcessWire;' was the problem. thx!
  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. We use Nginx. But the ProcessWire Site is non public.
  • Create New...