Xonox

Members
  • Content count

    44
  • Joined

  • Last visited

Community Reputation

29 Excellent

About Xonox

  • Rank
    Jr. Member

Recent Profile Visitors

684 profile views
  1. I've been using PW for quite a while, now, so I would like to give back to the community that helped me so many times. I had this customer that wanted to use the Google Translate API to automatically translate the site, so I built this function that takes advantage of it without the need to use the API on every page cycle. I put it on a file that gets called on the _init.php, so that I can use it on every template. Here it is: <?php function googleAutoTranslate($page, $field) { // Turn off outputFormatting $page->of(false); // Get current language and field content for this language $current_language = wire('user')->language->name; $field_content = $page->getLanguageValue($current_language, $field); // Is there any content for this language? if($field_content != '') { // Do nothing! } else { // No content, lets translate... // Get default language text $text = $page->getLanguageValue('default', $field); // Translate only if there's content in the default language if($text != '') { // Translate it $apiKey = 'YOUR API KEY HERE'; $default_language = 'pt'; // Your default language here! $url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey .'&q=' . rawurlencode($text) . '&source=' . $default_language . '&target=' . $current_language; $json = json_decode(file_get_contents($url)); $field_content = $json->data->translations[0]->translatedText; // Save translated text $page->$field->setLanguageValue($current_language, $field_content); $page->save(); } } // Turn on outputFormatting $page->of(true); // Return result return $field_content; } ?> Whenever you use a field on a template that should be auto translated, just call the function with a page object and the field name, like so: echo googleAutoTranslate($page, 'body'); Features: Translation occurs only once per field, so you don't need to keep paying translations (it stores the translation into the field language); You can correct the translation in the admin area and it won't be overwritten; If you need the translation to be made again, just delete the field content in the needed language. For the translation to occur, content must exist in the default language. I had to fight a little to get this working, so I hope this helps anyone, who comes across this particular need. Nice Things To Have If someone wants to give it a shot to make this into a module, please do. It would be nice to have a checkbox "Enable Google auto translate for this field", when you edit a field input features. Don't Spend Too Much Mind you that the Google translate is a payed service! and needs a Credit Card to get it going (even with $300 free credit); With a relatively small site (and the tests made to get this to work) I already spent about 80.000 translated characters = $3, Hope this helps someone!
  2. I also develop like that. I noticed that when I copy the changes to the production server, there's no need to delete the cache. So I'm figuring that it must be some configuration. I haven't had the time to compare both dev and the production servers. If I get to any conclusion, I'll post it.
  3. When I do that, I get a Fatal Error. Can't use: $pages = wire('pages'); Fatal error: Call to undefined function wire()
  4. The changed file doesn't appear as compiled in the logs. After I delete the FileCompiler folder, the template is updated, but the file still doesn't show as compiled in the logs. However, the file is inside the FileCompiler folder. If the file is in the folder, shouldn't it show in the logs?
  5. Tried this, but it doesn't make a difference!
  6. Hi, On some of the sites that I develop, I must keep deleting assets/cache/FileCompiler folder in order to see the changes made in the php files. I have cache disabled for the template, but it doesn't seem matter. As you might imagine, this extra step is costly in dev time. Usually this happens in just some pages and not in other. Am I missing something? Thanks,
  7. Solved it!!!! It isn't namespaces, thanks for the suggestion! It was the freaking cache!!!! It gets me everytime! Emptied the cache and it's working
  8. Hi, Great script. I managed to create my own form to submit Comments. It's working great on my local dev server, however, when I put it online, I get a Class Comment Not Found for the line: $c = new Comment(); Everything is configured the same way on both sides. I added the comments field to the template. What am I missing?
  9. Hi, @Robin S, after turning on the debug mode, it was all looking fine. @Macrura, when I was looking for the directories' permissions, I came across a post that recommended to delete the cache folders, so I did and everything was working fine. Thank's guys, for sending me through the right path! I also skipped this step on my local server so it´s a bit strange that this would have any influence. But it did. Solution Delete the session and cache files in the /site/assets directory.
  10. Hi, I updated a site from version 2. something, can't recall for sure, to version 3.0.39. All is working fine on local server. However, when I uploaded to online server, the page tree display stopped working. 1. Whenever I try to access the page tree it gives an alert with the text: Uknown error, please try again later On the console I can see the following: GET http://mysite.com/admin/page/list?id=1&renderJSON&start=0&open=undefined&mode=actions 500 (Internal Server Error) JqueryCore.js?v=1478723146:2 2. Whenever I try to access the page children (when editing a page) it gives an alert with the text: Uknown error, please try again later On the console I can see the following: Failed to load resource: the server responded with a status 500 http://mysite.com/admin/page/list?id=1040&renderJSON&start=0&lang=0&open=undefined&mode=actions (Internal Server Error) When I was updating, I got an error on the site config.php file. I forgot to update the $config->httpHosts for the domain in the new server, which was corrected after the update. The server is running PHP 5.4, MySQL 5.5.52, PW updated to 3.0.39 Any clues?
  11. Hi SamC, Sorry for the delayed answer. I still haven't been able to correct this situation. I catch these errors in the Javascript console, when I finish cropping. It gives the error on line 1 Were you able to solve your problem?
  12. Hi, I can't seem to be able to crop an image in the backend. I'm using PW 3.0.29 in Chrome without Image plugins. When I click apply, the button stays on "Saving..." forever. I get the following JavaScript Errors: An invalid form control with name='width' is not focusable. ?id=1024&file=1024,cfaf-2013-poster.jpg&rte=0&field=poster&modal=1:1 An invalid form control with name='height' is not focusable. ?id=1024&file=1024,cfaf-2013-poster.jpg&rte=0&field=poster&modal=1:1 Is this a bug?
  13. After some testing I came to the conclusion that we don't need the AJAX code. In fact it makes the code incompatible with the other extra actions. At the end of the day, the code becomes even simpler! It's been edited to show the final, simpler version.
  14. With return via $event->return, the module stops working. The used return is inside the Ajax process, not the hook. If we change the return, the module doesn't get an ajax response and doesn't update the page (keeps the ajax spinner forever). However, I'm not that knowledgeable in ProcessWire. Does this make sense?