Jump to content

Fluency - Integrated DeepL Powered Content Translation


FireWire

Recommended Posts

  • 2 weeks later...

I just started using it on the client project I mentionned a while ago and it's working amazingly, thank you so much for your hard work !

I have one suggestion / request though: could there be a way to add a string at the end of the translation automatically ? Something like "(translated with DeepL)". Ideally as an option per text field ?

I'm seeing from the source code that ___executeData() is hookable, would you suggest to go this way ? Editing the returned json ?

Thank you in advance for your feedback / help.

Link to comment
Share on other sites

14 hours ago, monollonom said:

I just started using it on the client project I mentionned a while ago and it's working amazingly, thank you so much for your hard work !

I have one suggestion / request though: could there be a way to add a string at the end of the translation automatically ? Something like "(translated with DeepL)". Ideally as an option per text field ?

I'm seeing from the source code that ___executeData() is hookable, would you suggest to go this way ? Editing the returned json ?

Thank you in advance for your feedback / help.

It would be pretty complex to create settings for that in the module config on a per-field basis and I think it might be too much of an edge case to implement in the module directly so I think hooking would be your best bet on this. Using `addHookAfter();` is the way to go.

Just remember to test the output of `___executeData()` as it returns different types of data depending on the request, see each case in the switch statement in the `___executeData()` method. Here's some quick info that might help you get up to speed more quickly.

All of the return values from `___executeData()` have the same data structure for predictability when used. At the very least each return value has `data` and `httpStatus` properties/values. A good way to make sure you are dealing with a translation is to decode the JSON (we'll say it's assigned to $decodedResponse), and then look for `$decodedResponse->data->translations;`. If the `translations` property exists in `data` then you know it's a translation. You would want to append your string to `$decodedResponse->data->translations[0]->text;`, encode `$decodedResponse` again, then return the modified JSON..

I'm not sure how you would be able to detect what field has been translated though because the return data from `___executeData()` doesn't contain any field name so your hook would append to all multi-language fields. Let me know if you can't find a workaround for this and I'll see if I can help.

Dunno if that is what you were looking for but hope it helps!

  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

I’m not quite sure if this is of interest for anyone and if this is the right forum for my post, but I got the client request to build a module extension for Fluency which translates all the text fields in a page with only one click. The module is not really ready for public (or the modules section), as it has no config page yet and was only tested in one ProcessWire installation, but maybe it is useful as a starting point for anyone who is in the same situation as me:

https://github.com/robertweiss/ProcessTranslatePage

The module checks for fluency-translate permissions and adds a ›Translate and save‹-button to the edit-page. It supports all core language fields, Repeater, FieldsetPage the pro modules Repeater Matrix, Combo and Functional Fields.

Caution: for now, the (language-)settings have to be manually edited in the hookPageSave-Method (Lines 64–69). 

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

On 9/24/2021 at 11:13 AM, robert said:

I’m not quite sure if this is of interest for anyone and if this is the right forum for my post, but I got the client request to build a module extension for Fluency which translates all the text fields in a page with only one click. The module is not really ready for public (or the modules section), as it has no config page yet and was only tested in one ProcessWire installation, but maybe it is useful as a starting point for anyone who is in the same situation as me:

https://github.com/robertweiss/ProcessTranslatePage

The module checks for fluency-translate permissions and adds a ›Translate and save‹-button to the edit-page. It supports all core language fields, Repeater, FieldsetPage the pro modules Repeater Matrix, Combo and Functional Fields.

Caution: for now, the (language-)settings have to be manually edited in the hookPageSave-Method (Lines 64–69). 

I had initially written off mass translation because after seeing the time it took to translate one or two fields I thought it could be a big holdup for the user. Have you run into any situations where a whole page runs into problems?

This is really awesome work!

Link to comment
Share on other sites

Thank you, this would not be possible without your excellent module!

I just pushed a new version to Github. The module got some additional features:

  • A config page where you can exclude templates and toggle whether you want to overwrite already existing translations
  • The language selection now uses the settings made in the Fluency config instead of having to configure it twice 😅 
  • Support for more than one target language (I never needed that but thought it would be nice to have in the future)
  • Support for the ProField Table

About the performance: I share your concerns, but my client still forced me to do it 😄 The largest page I tested had 63 fields (25 textfields, 14 file-descriptions, 24 richtext-fields) and took about a minute to translate, so you really have to take care of the php timeout-settings. To bypass that, I added a small external translate-pagetree script to the repository which can be used in the command line, so you can batch-translate multiple parts of the website (or all of it) at once. As this is not tested very well, a database-backup is recommended before trying!

  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...

are there any known issues with pw-installations inside a folder?

It works for me on a website like domain.com but not on pw-installation like domain.com/_temp/
I get this errors on a backend pageload

fluency_tools.js:60 POST https://domain.com/_tmp/fluency/data/ 404
moduleRequest	@	fluency_tools.js:60
(anonymous)	@	fluency.js:579
load (async)		
(anonymous)	@	fluency.js:576
VM287:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.xhr.onload (fluency_tools.js:53)
xhr.onload	@	fluency_tools.js:53
load (async)		
moduleRequest	@	fluency_tools.js:52
(anonymous)	@	fluency.js:579
load (async)		
(anonymous)	@	fluency.js:576


@FireWire you hardcoded the paypalme-PNG-Url into FluencyConfig.php (line:365). It's broken. 
/Fluency/img/paypal_me.png  > /Fluency-Translation-main/img/paypal_me.png

Link to comment
Share on other sites

On 10/29/2021 at 10:42 AM, ngrmm said:

are there any known issues with pw-installations inside a folder?

It works for me on a website like domain.com but not on pw-installation like domain.com/_temp/
I get this errors on a backend pageload

fluency_tools.js:60 POST https://domain.com/_tmp/fluency/data/ 404
moduleRequest	@	fluency_tools.js:60
(anonymous)	@	fluency.js:579
load (async)		
(anonymous)	@	fluency.js:576
VM287:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.xhr.onload (fluency_tools.js:53)
xhr.onload	@	fluency_tools.js:53
load (async)		
moduleRequest	@	fluency_tools.js:52
(anonymous)	@	fluency.js:579
load (async)		
(anonymous)	@	fluency.js:576


@FireWire you hardcoded the paypalme-PNG-Url into FluencyConfig.php (line:365). It's broken. 
/Fluency/img/paypal_me.png  > /Fluency-Translation-main/img/paypal_me.png

Added a fix for the PayPalm img. Thanks for mentioning. Will be included in the next release.

I hadn't anticipated an installation in a subfolder. The module creates an admin page when installed and that page's URL is an endpoint for the JavaScript on the page to make AJAX calls to when getting/sending translation data. The JS assumes that this URL will be at the root level. The JavaScript can't tell if the site is in a subdirectory. I don't know how to code the JavaScript to figure that out since it is separate from the CMS and the module which can tell what the full proper URL is but the JS doesn't have a way to get that info. There is probably a way to solve this problem but it will take a little investigating.

There is a quick and dirty solution that would fix this issue for you right now. That would be to go into the module directory, navigate to /src/js/ and then edit fluency_tools.js to point to the full URL you need by changing line 32.

From this: winLoc.pathname.split('/')[1] + '/fluency/data/'
To this: winLoc.pathname.split('/')[1] + '/_temp/fluency/data/'

That will let the JS know where to get/send translation data. If/when you need to move your PW site to the root directory then change it back to the original value.

Let me know if that works for you.

  • Thanks 1
Link to comment
Share on other sites

Thanks @FireWire
Actually the folder is already showing up in the error message above. When i do your quick fix i get this:  

fluency_tools.js:60 POST https://domain.com/_temp/_temp/fluency/data/ 404
moduleRequest @ fluency_tools.js:60
(anonymous) @ fluency.js:579
load (async)
(anonymous) @ fluency.js:576
VM752:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.xhr.onload (fluency_tools.js:53)
xhr.onload @ fluency_tools.js:53
load (async)
moduleRequest @ fluency_tools.js:52
(anonymous) @ fluency.js:579
load (async)
(anonymous) @ fluency.js:576

 

Link to comment
Share on other sites

25 minutes ago, ngrmm said:

Thanks @FireWire
Actually the folder is already showing up in the error message above. When i do your quick fix i get this:  

fluency_tools.js:60 POST https://domain.com/_temp/_temp/fluency/data/ 404
moduleRequest @ fluency_tools.js:60
(anonymous) @ fluency.js:579
load (async)
(anonymous) @ fluency.js:576
VM752:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.xhr.onload (fluency_tools.js:53)
xhr.onload @ fluency_tools.js:53
load (async)
moduleRequest @ fluency_tools.js:52
(anonymous) @ fluency.js:579
load (async)
(anonymous) @ fluency.js:576

 

Go to the Fluency module configuration page, then click on the "Translation" link in the menu bar. What is the URL of the page that loads?

Link to comment
Share on other sites

7 minutes ago, FireWire said:

Go to the Fluency module configuration page, then click on the "Translation" link in the menu bar. What is the URL of the page that loads?

https://domain.com/_tmp/processwire/fluency/

 

Link to comment
Share on other sites

6 minutes ago, ngrmm said:
https://domain.com/_tmp/processwire/fluency/

 

Okay now I got it. That is the URL that needs to be in the JS file I mentioned. In that JS it does it's best to parse the URL, get the admin slug, then build the request URL.

If you revisit that code in fluency_tools.js  set the value of requestUrl to where it should be able to send requests to the module. It should look like this:

var moduleRequest = function(requestData, callback) {
  var winLoc = window.location,
      params = [],
      requestUrl = 'https://domain.com/_tmp/processwire/fluency/data/'
      // requestUrl = winLoc.protocol + '//' +
      //              winLoc.host + '/' +
      //              winLoc.pathname.split('/')[1] + '/fluency/data/'

    // ... ommitted for brevity ...
}

If you move to production and ProcessWire is being served from the root directory then change this back.

  • Like 1
Link to comment
Share on other sites

9 minutes ago, FireWire said:

Okay now I got it. That is the URL that needs to be in the JS file I mentioned. In that JS it does it's best to parse the URL, get the admin slug, then build the request URL.

If you revisit that code in fluency_tools.js  set the value of requestUrl to where it should be able to send requests to the module. It should look like this:

var moduleRequest = function(requestData, callback) {
  var winLoc = window.location,
      params = [],
      requestUrl = 'https://domain.com/_tmp/processwire/fluency/data/'
      // requestUrl = winLoc.protocol + '//' +
      //              winLoc.host + '/' +
      //              winLoc.pathname.split('/')[1] + '/fluency/data/'

    // ... ommitted for brevity ...
}

If you move to production and ProcessWire is being served from the root directory then change this back.

it works! thanks a lot

  • Like 1
Link to comment
Share on other sites

On 11/11/2020 at 8:29 PM, FireWire said:

Unfortunately I haven't localized the UI yet but that is the next priority item on my list. If you have your primary language set as German and the other language as English, the translation link will still say "Translate from English" but it will still translate from German to English. Right now this issue is purely aesthetic. Here's the language translating from German to English but the translate link saying the wrong text.

868413029_Screenshotfrom2020-11-1109-35-00.png.311e4b7a9ca2e4558d012ab18b451e60.png

If you would like to change these now so you don't have to wait for a module upgrade, you can update the text strings located on the following lines in these JS files:

Fluency/src/js/fluency.js
153
160
216
473
476
490

Fluency/src/js/fluency_language_translator.js
108
168

By changing the text there the module will then fit your setup. Like I mentioned above, I'm working on having this behave correctly out of the box!

I think that due to almost-impossibility to change Processwire default language it's not necessary to explicitly name the language from which the text will be translated. It's enough to change all "Translate from English" phrases to just "Translate".

Link to comment
Share on other sites

On 11/4/2021 at 6:36 PM, theoretic said:

I think that due to almost-impossibility to change Processwire default language it's not necessary to explicitly name the language from which the text will be translated. It's enough to change all "Translate from English" phrases to just "Translate".

I am finishing the next release right now and will be pushing a new version. In this version you can customize all Fluency UI strings for any default language, using the translation service if desired.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      PageMjmlToHtml
      Github: https://github.com/romaincazier/PageMjmlToHtml
      Modules directory: https://processwire.com/modules/page-mjml-to-html/
      A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.
      This is considered to be in alpha and as such needs some testing before being used in production!

      About
      Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients.
      Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API.
      Prerequisite
      For this module to work you will need to get an API key and paste it in the module’s configuration.
      Usage
      Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your page(s) to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go.
      From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer.
      Features
      The MJML output is cached to avoid repetitive API calls Not cached if there are errors/warnings Cleared if the page is saved Cleared if the template file has been modified A simple (dumb?) code viewer highlights lines with errors/warnings A button is added to quickly copy the raw code of the generated newsletter Not added if the page is rendered outside of a PageView Only visible to users with the page’s edit permission A shortcut is also added under “View” in the edit page to open the raw code in a new tab Multi-languages support
      Notes
      The code viewer is only shown to superusers. If there’s an error the page will display:
      Only its title for guests Its title and a message inviting to contact the administrator for editors If you are using the markup regions output strategy, it might be best to not append files to preserve your MJML markup before calling the MJML API. This option is available in the module’s settings.
    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
×
×
  • Create New...