Title: Decode from JS
Last modified: August 31, 2016

---

# Decode from JS

 *  Resolved [jeromeeee](https://wordpress.org/support/users/jeromeeee/)
 * (@jeromeeee)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/)
 * Hi,
 * I have a JavaScript that displays some content on a Google map interface. Is 
   there any way to decode this within the JS file?
 * This is what is being displayed currently:
    {:en}4 Room Flat{:}{:zh}四房式{:}
   in {:en}Sale{:}{:zh}出售{:}
 * Optimally, it should display the content based on the locale, and this is how
   I’m getting the variable in the JS (if it helps):
 * > var category = decodeURIComponent ( this.category.replace(/-/g,’ ‘) );
 * Thanks in advance!
 * [https://wordpress.org/plugins/wpglobus/](https://wordpress.org/plugins/wpglobus/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7293979)
 * you can use filter in your template to get appropriate language string
 *     ```
       echo apply_filters( 'the_content', '{:en}4 Room Flat{:}{:zh}四房式{:}' );
       echo 'in';
       echo apply_filters( 'the_content', '{:en}Sale{:}{:zh}出售{:}' );
       ```
   
 *  Thread Starter [jeromeeee](https://wordpress.org/support/users/jeromeeee/)
 * (@jeromeeee)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7293990)
 * Problem is the output is directly from the JS file, not the PHP template file.
   Is there any other workaround?
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7294016)
 * for js you can use
 *     ```
       WPGlobusCore.TextFilter('{:en}4 Room Flat{:}{:zh}四房式{:}',WPGlobusCoreData.language);
       ```
   
 *  Thread Starter [jeromeeee](https://wordpress.org/support/users/jeromeeee/)
 * (@jeromeeee)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7294021)
 * Pardon my dumb question, but I am getting the error:
 * VM4335:2 Uncaught ReferenceError: WPGlobusCore is not defined
 * I have moved the wpglobus.min.js file to the header, and it is loaded in the 
   page above my file, but can’t seem to use the code in my JS script. Any suggestions?
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7294099)
 * You can find solution at PHP using filters when data are retrieved from DB
 *  Thread Starter [jeromeeee](https://wordpress.org/support/users/jeromeeee/)
 * (@jeromeeee)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7294116)
 * Turns out that it doesn’t work as I’m reading the information from a file rather
   than a DB. As such, the PHP functions apply_filers did not work after many tests.
 * In the end, I wrote a custom JS function to do text filtering based on the language.
   In case if any one stumbles across the same problem as me:
 * >  function switch_content_language(text){
   >  if (typeof WPGlobus === ‘undefined’){
   > return; }
   >  var lang = WPGlobus.language;
   >  var res = text.split(“{:}”); for (i = 0; i 
   > < res.length; i++) { if (res[i].toLowerCase().indexOf(lang) >= 0) { return 
   > res[i].substring(res[i].indexOf(“}”) + 1); } } }

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Decode from JS’ is closed to new replies.

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

 * 6 replies
 * 2 participants
 * Last reply from: [jeromeeee](https://wordpress.org/support/users/jeromeeee/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/decode-from-js/#post-7294116)
 * Status: resolved