简体   繁体   中英

Extract javascript gettext in Poedit?

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";
    ?>

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 — ie do the translation on PHP/server side.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM