• Resolved glocc

    (@glocc)


    Hello,

    I want to translate strings from JavaScript files with special extention (.tag in my case).

    Loco Translate has “Scan JavaScript files with extensions” option on settings page. First of all I filled in there my custom file extention (.tag). After that I am gone to “Editor” page to “Sync” my new string. Loco Translate found my new string as expected and suggested to translate it. But after click “Save” button translated strings didn’t appear in JSON translation file and also weren’t shown on frontend.

    I think the solution is near on the line 158 in /src/gettext/Compiler.php (Loco Translate version 2.6.9)
    foreach( $po->exportRefs('\.js') as $ref => $fragment ){
    Because it search strings just in files with .js extention.

    I changed this code to foreach( $po->exportRefs('\.tag') as $ref => $fragment ){
    In this way my strings appeared in JSON translation file and were shown on frontend.

    Please make it possible to translate strings of any JavaScript files with extentions specified in “Scan JavaScript files with extensions” in next update.

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

    (@timwhitlock)

    JSON files are for use with wp_set_script_translations, and this only works with .jsand .min.js files, as this is what gets loaded at run time.

    Are you compiling your .tag files to .js files for deployment?

    Some more info on this problem here. https://localise.biz/wordpress/plugin/manual/json

    Plugin Author Tim W

    (@timwhitlock)

    I changed this code […] this way my strings appeared in JSON translation file and were shown on frontend.

    I’m curious how this actually worked. Can you show me more about the way you’re loading your scripts via WordPress? An example .tag path and the resulting JSON file name would be useful.

    Plugin Author Tim W

    (@timwhitlock)

    I’ve updated the dev branch with this patch so the compiler observes the configured .js aliases from settings. So, I’m marking as resolved.

    After trying this myself I can see that localizing a script with a non-standard extension DOES produce a targetable JSON file.

    So I take it back. wp_set_script_translations seems to work with any file extension. The only special logic is that .min.js extensions are normalized to .js. So [currently] you wouldn’t be able to extract strings from a .tag file and then load a .min.tag file at runtime.

    Thread Starter glocc

    (@glocc)

    Hello, Tim

    Thanks for your answer and fast solution.

    I installed plugin from your GitHub repository (Version 2.6.10-dev) and it works like a charm: strings from files with .js and .tag extentions detected, saved to JSON and shown on frontend.

    Will wait possibility to update the plugin via admin panel from WordPress directory.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can’t translate JavaScript with specific extention’ is closed to new replies.