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}出售{:}' );
Problem is the output is directly from the JS file, not the PHP template file. Is there any other workaround?
for js you can use
WPGlobusCore.TextFilter('{:en}4 Room Flat{:}{:zh}四房式{:}',WPGlobusCoreData.language);
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?
You can find solution at PHP using filters when data are retrieved from DB
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);
}
}
}