Title: Can&#8217;t translate JavaScript with specific extention
Last modified: May 23, 2024

---

# Can’t translate JavaScript with specific extention

 *  Resolved [glocc](https://wordpress.org/support/users/glocc/)
 * (@glocc)
 * [2 years ago](https://wordpress.org/support/topic/cant-translate-javascript-with-specific-extention/)
 * 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](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [2 years ago](https://wordpress.org/support/topic/cant-translate-javascript-with-specific-extention/#post-17776739)
 * JSON files are for use with [wp_set_script_translations](https://developer.wordpress.org/reference/functions/wp_set_script_translations/),
   and this only works with `.js`and `.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](https://localise.biz/wordpress/plugin/manual/json)
 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [2 years ago](https://wordpress.org/support/topic/cant-translate-javascript-with-specific-extention/#post-17776797)
 * > 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](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [2 years ago](https://wordpress.org/support/topic/cant-translate-javascript-with-specific-extention/#post-17778062)
 * I’ve updated the [dev branch](https://localise.biz/wordpress/plugin/developers)
   with [this patch](https://github.com/loco/wp-loco/blob/16c75b387174978b6ea9b1d287b30aa9c7675d1b/src/gettext/Compiler.php#L157-L158)
   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](https://wordpress.org/support/users/glocc/)
 * (@glocc)
 * [2 years ago](https://wordpress.org/support/topic/cant-translate-javascript-with-specific-extention/#post-17778197)
 * 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.

 * ![](https://ps.w.org/loco-translate/assets/icon-256x256.png?rev=1000676)
 * [Loco Translate](https://wordpress.org/plugins/loco-translate/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/loco-translate/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/loco-translate/)
 * [Active Topics](https://wordpress.org/support/plugin/loco-translate/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/loco-translate/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/loco-translate/reviews/)

## Tags

 * [json](https://wordpress.org/support/topic-tag/json/)

 * 4 replies
 * 2 participants
 * Last reply from: [glocc](https://wordpress.org/support/users/glocc/)
 * Last activity: [2 years ago](https://wordpress.org/support/topic/cant-translate-javascript-with-specific-extention/#post-17778197)
 * Status: resolved