Support » Plugin: Loco Translate » FAQ: What is causing Unexpected token/character syntax error?

  • Plugin Author Tim W

    (@timwhitlock)


    When saving or syncing your translations, Loco Translate makes Ajax requests to your server. In normal situations the plugin will respond as JSON (even when something goes wrong).

    If something goes unexpectedly wrong (something that is outside of Loco Translate’s control) your server might send back a whole HTML page instead of a JSON response.

    In this case you will get a JavaScript error notice. Depending on what browser you are using it may read “JSON.parse: unexpected character…” or “SyntaxError: Unexpected token …”, or something similar.

    As to what went wrong to cause this error – it could could be one of infinite possibilities, but there are some reasons more likely than others. Here are some things to check:

    ModSecurity (mod_sec)

    “mod_sec” is a security add-on for Apache web server. Some hosting providers install this and it is known to prevent Loco Translate from functioning. Ask your provider if mod_sec is installed. If it is then this is almost certainly your problem and you’ll have to work with your provider to configure it appropriately.

    Maximum POST size

    Most web servers (and also PHP) have settings that restrict the maximum size of the data you may post to it. Loco Translate posts your entire translation file to the server when generating your MO file. Most normal server configurations should easily permit Loco Translate to function, but if you have a very big translation file and a very small maximum post size you could run into a server error. Ask your hosting provider for their size limit and compare this to the size of your PO files.

    Bug in Loco Translate

    Of course, I’m not ruling out a bug in the plugin, but the above cases make up the majority. If you want to report this error message as a bug, please provide the following information:

    – Installed versions of WordPress, Loco Translate and PHP;
    – The browser you are using;
    – Any messages in your error log file;
    – * Output from the Ajax request that went wrong.

    * This is the most important piece of the puzzle. To see the server response you will need to use your browser’s network inspection tool, which is usually part of its “developer” tools.

    https://wordpress.org/plugins/loco-translate/

Viewing 1 replies (of 1 total)
  • Plugin Author Tim W

    (@timwhitlock)

    + PHP Errors in your theme and other plugins

    If your theme or some other plugin is throwing PHP errors, these may be printed out when ajax processes run and that will break the response causing this error. Try switching off debug mode if you get this problem.

Viewing 1 replies (of 1 total)
  • The topic ‘FAQ: What is causing Unexpected token/character syntax error?’ is closed to new replies.