生成 Yii 翻译消息文件 [英] Generate Yii translation message files

查看:16
本文介绍了生成 Yii 翻译消息文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想知道是否有脚本或其他方式可用于在控制器/项目中收集和生成 Yii 翻译消息

I am interested to know is there a script or otherway available to collect and generate Yii translation messages in a controller/project

例如.如果我在控制器中有以下代码

Eg. If I have the following codes in a controller

Yii::t('blog', 'Your name');
Yii::t('category', 'Category name');

它应该在消息目录中生成带有上述字符串的英文翻译消息文件 blog.php 和 category.php.如果有人知道方法,请告诉我.谢谢

It should generate English translation message files as blog.php and category.php with above strings in messages directory. Please let me know if somebody knows a way. Thanks

推荐答案

无需重新发明轮子.您可以为此使用 yiic(如果您转到框架文件夹并输入 yiic 帮助消息,您将获得有关其用法的所有信息).为了方便,我把它贴在这里.

There's no need to reinvent the wheel. You can use yiic for that (if you go to the framework folder and type in yiic help message you will get all the info to need about it's usage). For convenience, I'm going to paste it here.

用法 yiic 消息路径/to/config/file

USAGE yiic message path/to/config/file

DESCRIPTION 此命令搜索要翻译的消息指定的源文件并将它们编译为 PHP 数组消息来源.

DESCRIPTION This command searches for messages to be translated in the specified source files and compiles them into PHP arrays as message source.

PARAMETERS * config-file:必填,配置路径文件.您可以在 framework/messages/config.php 中找到示例.

PARAMETERS * config-file: required, the path of the configuration file. You can find an example in framework/messages/config.php.

文件可以放在任何地方,并且必须是有效的PHP脚本它返回一个名称-值对数组.每个名称-值对代表一个配置选项.

The file can be placed anywhere and must be a valid PHP script which returns an array of name-value pairs. Each name-value pair represents a configuration option.

以下选项可用:

  • sourcePath:字符串,所有源文件的根目录.
  • messagePath:字符串,包含消息翻译的根目录.
  • languages:数组,提取消息的语言代码列表应该翻译成.例如,array('zh_cn','en_au').
  • fileTypes:数组,文件扩展名列表(例如'php'、'xml').只能在此列表中找到其扩展名的文件将被处理.如果为空,则将处理所有文件.
  • exclude:数组,目录和文件排除列表.每个排除可以是名称或路径.如果一个文件或目录名或路径匹配排除,它不会被复制.例如,'.svn' 的排除将排除所有文件和目录名称是.svn".排除 '/a/b' 将排除文件或目录sourcePath/a/b".
  • translator:翻译消息的函数名.默认为'Yii::t'.这用作标记以查找要发送的消息已翻译.
  • 覆盖:如果必须用合并的消息覆盖消息文件.
  • removeOld:如果消息不再需要翻译,它将被删除,而不是包含在一对@@"标记之间.

您应该修改(并移动)示例配置文件,一切就绪.确保使用完整路径(即 C:path oproject 在 Windows 上或 /var/www/your/project 在 *nix 上)

You should modify (and move) the example config file and you're all set. Be sure to use full paths (ie. C:path oproject on Windows or /var/www/your/project on *nix)

这篇关于生成 Yii 翻译消息文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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