g4/translate

g4 国际化 PHP 库

1.0.0 2024-03-01 09:16 UTC

This package is auto-updated.

Last update: 2024-08-30 10:19:26 UTC


README

  • gettext 扩展配置
  • 生成 .mo 文件的实用工具
  • 提取模板字符串的实用工具

安装

使用 Composer 和 Packagist

composer require g4/translate

资源

需求

用法

在渲染任何国际化模板之前,在程序中尽早设置区域设置。

use G4\Translate\Locale\Locale;
use G4\Translate\Locale\Options;

$options = new Options();
$options
    ->setDomain('myDomain')
    ->setLocale('en_US')
    ->setPath('/path/to/locale/files');
(new Locale($options))->set();

命令行界面

将 .po 文件转换为 .mo

./vendor/bin/translate --path /path/to/locale/files

其中 --path 是您的区域文件夹的路径

提取模板字符串

./vendor/bin/translate-extract -t /path/to/templates -w /path/to/tmp -g /path/to/locale/files -d myDomain

其中

  • -t 是包含模板的文件夹路径
  • -w 是临时文件夹路径
  • -g 是生成包含字符串的 myDomain.po 文件的文件夹路径
  • -d 域名

开发

安装依赖项

$ make install

运行测试

$ make test

许可证

(MIT 许可证) 详细信息请参阅 LICENSE 文件...