How to translate strings in JS

前端 未结 7 1073
心在旅途
心在旅途 2021-02-10 09:52

I have a project which I want to translate into multiple languages for the PHP Part I use Zend Frameworks Zend_Translate with GetText. Now I want to translate the JS part too.

相关标签:
7条回答
  • 2021-02-10 10:56

    I have a PHP web page that also exists in several languages. I have written my own language class in PHP and when it came to localizing the JavaScript files I just configured the server to execute .js files as PHP too, and I used my PHP class to translate JavaScript strings.

    Something like this:

    alert ( '<?php echo $l->Get ( 'MyString' ); ?>' );
    

    I just include a file that initializes the "$l" at the beginning of every JavaScript file. I have no problems with this.

    0 讨论(0)
提交回复
热议问题