6

Im going to build a Silex/Symfony2 project and I have been looking around for a method to generate XLIFF/PO/YAML translation files based on texts-to-be-translated inside the project but not found any instruction or documentation on it.

My question is: Is there an automated way to generate translation file(s) in specific format for a Symfony2/Silex project?

If yes, please tell me how to generate the file then update the translation after that.

If no, please tell me how to create translation file(s) then adding up more text for my project? I am looking for an editor desktop based or web-based instead of using normal editor such as Transifex, GetLocalization (but they dont have option to create a new file or add more text)

4

3 回答 3

11

上网找了好久,找到了一个不错的:

https://github.com/schmittjoh/JMSTranslationBundle

于 2013-04-22T06:40:58.007 回答
6

我看到你找到了一个转换器,但要回答你关于生成初始翻译文件的第一个问题 -

如果您的系统上安装了Gettext,您可以从“项目内要翻译的文本”生成 PO 文件。命令行程序xgettext将扫描源文件以查找您正在使用的任何功能。

示例:
要扫描 PHP 文件以查找此处所示trans的方法调用实例,您可以使用以下命令 -

find . -name "*.php" | xargs xgettext --language=PHP --keyword=trans --output=messages.pot

关于编辑器的问题:
您可以使用任何 PO 编辑器,例如POEdit来管理您的翻译,但正如您所说,您最终需要将 PO 文件转换为 Symfony 的 XLIFF 或 YAML 语言包。

我看到你已经找到了一个转换器工具。你可能还想试试我为 Loco 写的那个。它支持PO 到 YAMLPO 到 XLIFF

于 2013-05-09T10:22:22.640 回答
1

忙碌人士的解决方法 (UNIX)

您可以在终端中运行以下命令:

$ grep -rEo --no-filename "'.+'\|\btrans\b" templates/ > output.txt

这将输出要翻译的消息列表:

'Please provide your email'|trans
'Phone'|trans
'Please provide your phone number'|trans
...

我的意思是几乎......但你通常可以从这里做一些工作......

显然,您必须根据自己的喜好调整命令(transchoice双引号而不是单引号...)。

不理想但可以提供帮助!

grep选项

  • grep -R, -r, --recursive: 读取每个目录下的所有文件,递归这个相当于-drecurse选项。
  • grep -E, --extended-regexp: 将 PATTERN 解释为扩展的正则表达式。
  • grep -o, --only-matching:仅显示匹配 PATTERN 的匹配行部分。
  • grep -h, --no-filename:当搜索多个文件时,抑制输出文件名的前缀。

来源

于 2015-06-08T14:11:06.530 回答