Extract javascript gettext in Poedit?

自作多情 提交于 2019-12-23 05:45:07

问题


I have used "GNU gettext" with PHP and it did a greate job by using poedit I was able to extract the PO file format

but when I tried the same thing for my javascript inside my HTML "script" tag I didn't work even more I can't see any javascript support.

poedit support almost all languages except javascript or I am doing it In a wrong way can anyone provide working example for javascript?! i followed all example in almost 20 languages using poedit and all worked except javascript

all working examples from GNU gettext found in

gettext-0.19.7.tar.gz

http://ftp.gnu.org/gnu/gettext/

gettext-0.19.7\gettext-tools\examples

this is php examlpe which works i need to do the same for javascript

    #!@PHP@ -q
    <?
      // Example for use of GNU gettext.
      // This file is in the public domain.
      //
      // Source code of the PHP program.

      setlocale (LC_ALL, "");
      textdomain ("hello-php");
      bindtextdomain ("hello-php", "@localedir@");

      echo _("Hello, world!");
      echo "\n";
      echo printf (_("This program is running as process number %d."),posix_getpid());
      echo "\n";
    ?>

回答1:


Both Poedit and xgettext have support for JavaScript for some time now. Your problem is that you're embedding the code in HTML file, so it's not recognized as a JavaScript file (and xgettext, which Poedit uses, doesn't support embedded content in other languages).

Just put your JavaScript code in a separate .js file.

Notice that JavaScript code runs on the client side, so you need to load translations in JavaScript as well. A better solution for you, considering that you have just some (presumably small-ish) snippets of JS inside a PHP code, may be to generate that JS code with PHP — i.e. do the translation on PHP/server side.




回答2:


You can use this npm package to work with those files, assuming you are working from a node environment. I do not think it is possible from the browser.



来源:https://stackoverflow.com/questions/35406246/extract-javascript-gettext-in-poedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!