gpt4 book ai didi

php - 生成 Yii 翻译消息文件

转载 作者:IT王子 更新时间:2023-10-29 00:03:19 25 4
gpt4 key购买 nike

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

例如。如果我在 Controller 中有以下代码

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

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

最佳答案

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

USAGE yiic message path/to/config/file

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: required, the path of the configuration file. You can find an example in framework/messages/config.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.

The following options are available:

  • sourcePath: string, root directory of all source files.
  • messagePath: string, root directory containing message translations.
  • languages: array, list of language codes that the extracted messages should be translated to. For example, array('zh_cn','en_au').
  • fileTypes: array, a list of file extensions (e.g. 'php', 'xml'). Only the files whose extension name can be found in this list will be processed. If empty, all files will be processed.
  • exclude: array, a list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory 'sourcePath/a/b'.
  • translator: the name of the function for translating messages. Defaults to 'Yii::t'. This is used as a mark to find messages to be translated.
  • overwrite: if message file must be overwritten with the merged messages.
  • removeOld: if message no longer needs translation it will be removed, instead of being enclosed between a pair of '@@' marks.

您应该修改(并移动)示例配置文件,一切就绪。请务必使用完整路径(即 Windows 上的 C:\path\to\project 或 *nix 上的 /var/www/your/project)

关于php - 生成 Yii 翻译消息文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11232039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com