• Resolved aga2442

    (@aga2442)


    Hello,

    I want to use the PWA plugin on my website. also the translatepress plugin is already available. (https://www.ads-software.com/plugins/pwa/)

    After activating the PWA plugin, it works fine in the default language and the 2nd language I added.

    but the problem is that when the language option other than the default language is activated, errors appear in the developer tools section.

    I reported this problem to the PWA developer and he shared the following explanation with me:

    I’m looking at the service worker code and it seems that the translation plugin is corrupting the JavaScript. For example, in the JS file:

    const offlinePostRequestHandler = ({ event }) => { return fetch(event.request) .then((response) => { if (response.status < 500) { return response; } // @todo This is duplicated with code in service-worker-navigation-routing.js. return response.text().then(function (errorText) {

    This is getting turned into the following in the French version:

    const offlinePostRequestHandler = ({ event }) => { return fetch(event.request) .then((response) => { if (response.status &lt; 500) { réponse de retour&nbsp;; } // @todo Ceci est dupliqué avec le code dans service-worker-navigation-routing.js. return réponse.text().then(function (errorText) ...

    So the translation logic is erroneously attempting to translate the JavaScript code.

    So I think this is something you should raise with the plugin author, or if you can perhaps find a way to prevent translation for URLs that end in?wp.serviceworker.

    I wonder if there is a way to fix this problem, what can you suggest for a solution?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Anca

    (@ancavictoria)

    Hello @aga2442

    Thank you for reporting this to us and for the information provided!

    You can try the following custom code to check if it resolves this issue:

    /*
     * Do not translate URL's containing a certain path in them.
     */
    add_filter('trp_stop_translating_page', 'trpc_do_not_translate_service_worker_pages', 10, 2);
    function trpc_do_not_translate_service_worker_pages($translate, $output){
    
    	if( isset( $_SERVER['REQUEST_URI'] ) )
    		$request_uri = $_SERVER['REQUEST_URI'];
    	else
    		$request_uri = '';
    
    	if( str_contains( $request_uri, 'wp.serviceworker' ) ){
    		return true;
    	}
    
    	return $translate;
    }

    I have informed the development team about this, and it will be addressed in an upcoming update.

    Please confirm if the custom code resolves this issue.

    Kind Regards,

    Anca

    Thread Starter aga2442

    (@aga2442)

    @ancavictoria,

    thank you for your support.

    when I add this content as a PHP code snippet with the wpcode plugin, any problem no longer appears.

    Plugin Support Anca

    (@ancavictoria)

    Hello @aga2442

    Thank you for the feedback, I’m glad to hear that the custom code provided resolves the issue!

    I will come back when this fix becomes available in a future update.

    Kind Regards,

    Anca

    Plugin Support Anca

    (@ancavictoria)

    Hello @aga2442

    This issue has been resolved in the latest TranslatePress update.

    All the best!

    Anca

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.