tigron / skeleton-i18n
Skeleton 的翻译和国际化功能
v4.0.6
2023-11-06 09:03 UTC
Requires
- dev-master
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- 2.1.12
- v2.1.11
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0
- 1.x-dev
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- v0
- dev-feature/4.x
This package is auto-updated.
Last update: 2024-09-06 11:14:48 UTC
README
描述
此库为 Skeleton 提供国际化翻译功能。
安装
通过 composer 安装
composer require tigron/skeleton-i18n
运行迁移来更新数据库模式
skeleton migrate:up
如何使用
配置软件包
/**
* The path to store the po files
*
* \Skeleton\I18n\Config::$po_directory is deprecated
*/
\Skeleton\I18n\Config::$po_path = '/my_app/po';
/**
* Define a temporary folder to cache all translations
*
* \Skeleton\I18n\Config::$cache_directory is deprecated
*/
\Skeleton\I18n\Config::$cache_path = '/my_app/tmp/languages';
/**
* Optional:
* skeleton-i18n keeps translations for templates per application.
* For every skeleton application in your project a different po file is
* created that contains all strings to be translated for the given
* application.
* If for some reason, you want to include more templates, this can
* be done via the following configuration.
\Skeleton\I18n\Config::$additional_template_paths['pdf'] = '/my_app/pdf/templates';
/**
* Optional:
* Set another Language interface
*/
\Skeleton\I18n\Config::$language_interface = '\Language';
/**
* Optional:
* Enable auto fill po file when requesting translation
* Default to false
*/
\Skeleton\I18n\Config::$auto_fill_po = true;
使用它
通过 skeleton-template-twig 渲染的 twig 模板
{% trans "To be translated" %}
直接通过 PHP
$language = Language::get_by_name_short('en');
$application_name = 'admin';
$translation = \Skeleton\I18n\Translation::get($language, $application_name);
\Skeleton\I18n\Translation::translate('To be translated', $translation);