在Poedit中提取javascript gettext? [英] Extract javascript gettext in Poedit?

查看:114
本文介绍了在Poedit中提取javascript gettext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中使用了GNU gettext,并且通过使用poedit做了一个更好的工作我能够提取PO文件格式

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

但是当我尝试了同样的事情,我的HTML脚本标签内的我的javascript我没有工作,我看不到任何javascript支持。

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支持几乎所有语言,除了JavaScript或者我这样做以错误的方式
可以为任何人提供javascript的工作示例吗?!
i使用poedit跟随近20种语言的所有示例,除了javascript之外全部工作

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

gettext-0.19.7.ta​​r.gz

gettext-0.19.7.tar.gz

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

gettext-0.19.7 \ gettext-tools \\ \\ example>

gettext-0.19.7\gettext-tools\examples

这是php testlpe,我需要为javascript做同样的事情

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


推荐答案

Poedit和 xgettext 现在支持JavaScript一段时间了。您的问题是您将代码嵌入到HTML文件中,因此它不被识别为JavaScript文件(Poedit使用的 xgettext 不支持嵌入式内容其他语言)。

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).

只需将您的JavaScript代码放在单独的 .js 文件中。

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

请注意,JavaScript代码在客户端运行,因此您还需要在JavaScript 中加载翻译。一个更好的解决方案,考虑到你在PHP代码中只有一些JS(可能是小的)片段,可能是用PHP生成JS代码 - 即在PHP /服务器端进行翻译。

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.

这篇关于在Poedit中提取javascript gettext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆