简体   繁体   English

在Poedit中提取javascript gettext?

[英]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 我在PHP中使用了“ GNU gettext”,并且通过使用poedit可以很好地提取PO文件格式

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. 但是,当我在HTML“ script”标签中为JavaScript尝试相同的操作时,我什至无法工作,我看不到任何javascript支持。

poedit support almost all languages except javascript or I am doing it In a wrong way can anyone provide working example for javascript?! poedit支持除javascript之外的几乎所有语言,或者我正在这样做。有人用错误的方式可以为javascript提供有效的示例吗? i followed all example in almost 20 languages using poedit and all worked except javascript 我使用poedit遵循了将近20种语言的所有示例,除javascript之外,所有示例均有效

all working examples from GNU gettext found in GNU gettext中所有可用的示例都在

gettext-0.19.7.tar.gz gettext-0.19.7.ta​​r.gz

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

gettext-0.19.7\\gettext-tools\\examples gettext-0.19.7 \\ gettext-tools \\ examples

this is php examlpe which works i need to do the same for javascript 这是php示例,我需要对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. Poedit和xgettext都已经支持JavaScript一段时间了。 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). 您的问题是您将代码嵌入HTML文件中,因此无法将其识别为JavaScript文件(Poedit使用的xgettext不支持其他语言的嵌入式内容)。

Just put your JavaScript code in a separate .js file. 只需将您的JavaScript代码放在单独的.js文件中。

Notice that JavaScript code runs on the client side, so you need to load translations in JavaScript as well. 请注意,JavaScript代码在客户端运行,因此您还需要在JavaScript中加载翻译。 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. 考虑到您在PHP代码中只有JS片段(大概很小),对您来说,一个更好的解决方案可能是使用PHP生成该JS代码-即在PHP /服务器端进行翻译。

You can use this npm package to work with those files, assuming you are working from a node environment. 假设您在节点环境中工作,则可以使用此npm软件包来处理这些文件。 I do not think it is possible from the browser. 我认为无法通过浏览器访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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