• Resolved axos1192

    (@axos1192)


    I tried to translate a theme related js file with loco and so far everything seemed fine, just the translations weren’t showing in the frontend. After debugging I found out that the standard WordPress loader is somehow only looking for files that have the syntax $textdomain-$locale-md5.json as long as the text-domain isn’t “default” and loco is generating the file without the text-domain.
    I added the text-domain in front of the generated filename and everything was working immediately. (mo and po files are loaded correctly with just the domain name)

    Am I missing something? Is there something I can do to fix that on my own? Didn’t find any filters on my own.

    Thanks in advance!

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

    (@timwhitlock)

    Loco Translate takes JSON filenames from the PO file name, and the WordPress convention is that theme-provided PO files have no text domain suffix. This is a very old legacy that remains to this day. It hadn’t occurred to me that the JSON loader would “fix” this exception. I’ve not checked for myself, but I’ll take your word for it.

    I’ll look at fixing this, but I must say that saving translation files inside the theme is best avoided. I say that because WordPress is generally against author-provided translation and has made changes in the past that re-prioritised files in the global language. This was effectively a deprecation, and I half expect them to be scrapped one day.

    I suggest as a quick fix that you save your translation files in the “system” location, rather than inside the theme. If the child theme is your own and there is no community translation project for its text domain then it shouldn’t be touched by updates. As a precaution I’d always recommend daily backups.

    Alternatively you could look at using the loco_compile_single_json filter. I’d recommend the former as long as it works. Which it should.

    Thread Starter axos1192

    (@axos1192)

    Thanks for your fast reply! Actually i was able to fix it for now by just renaming the generated json file with the text-domain in front of the file name. As long as there is no update to my po file it will stay correctly but i thought it would be nice to have it fixed.

    I understand, that other folders for translations are preferred but I can’t wrap my head around the fact that my translations go “outside” of the template file-structure. It feels way tidier this way.

    I thought it may be a quite easy fix and probably saves some people a few hours.

    Thank you for providing loco translate!

    Plugin Author Tim W

    (@timwhitlock)

    There’s a fix for this on the current development branch.

    It wasn’t an easy fix because the system was relying on PO file names in order to establish matching JSON file names. Hence some code scopes were not aware of the theme text domain when presented with a file like “en.po”

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘.json translation files are generated without text-domain in child-theme folder’ is closed to new replies.