kunstmaan / translator-bundle
一个插件,允许在不编辑翻译文件的情况下,在管理界面编辑翻译。翻译将存储在(默认)数据库中,并以最有效的方式检索。
Requires
- php: ^8.1
- kunstmaan/adminlist-bundle: ^7.0
- openspout/openspout: ^4.0
Requires (Dev)
- doctrine/data-fixtures: ^1.5
- fakerphp/faker: ^1.15
- matthiasnoback/symfony-config-test: ^4.2.1
- matthiasnoback/symfony-dependency-injection-test: ^4.2.1
- phpunit/phpunit: ^9.5.5
- symfony/phpunit-bridge: ^7.0
- 7.x-dev
- 7.1.x-dev
- 7.1.1
- 7.1.0
- 7.1.0-alpha2
- 7.1.0-alpha1
- 7.0.x-dev
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 7.0.0-alpha1
- 6.x-dev
- 6.4.x-dev
- 6.4.2
- 6.4.1
- 6.4.0
- 6.4.0-alpha2
- 6.4.0-alpha1
- 6.3.x-dev
- 6.3.1
- 6.3.0
- 6.2.x-dev
- 6.2.5
- 6.2.4
- 6.2.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.x-dev
- 6.1.9
- 6.1.8
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.x-dev
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.10.x-dev
- dev-master / 5.10.x-dev
- 5.10.7
- 5.10.6
- 5.10.5
- 5.10.4
- 5.10.3
- 5.10.2
- 5.10.1
- 5.10.0
- 5.9.x-dev
- 5.9.3
- 5.9.2
- 5.9.1
- 5.9.0
- 5.8.x-dev
- 5.8.1
- 5.8.0
- 5.7.x-dev
- 5.7.3
- 5.7.2
- 5.7.1
- 5.7.0
- 5.6.x-dev
- 5.6.6
- 5.6.5
- 5.6.4
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.x-dev
- 5.5.6
- 5.5.5
- 5.5.4
- 5.5.3
- 5.5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- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- dev-6.0-copy
- dev-sf3
This package is auto-updated.
Last update: 2024-08-28 20:17:40 UTC
README
一个插件,允许在不编辑翻译文件的情况下,在管理界面编辑翻译。翻译将存储在(默认)数据库中,并以最有效的方式检索。
安装要求
在您安装 KunstmaanTranslatorBundle 之前,您应该能够安装并运行 Symfony >=2.3。
安装说明
假设您已安装 composer.phar 或 composer 二进制文件
$ composer require kunstmaan/translator-bundle 2.3.*@dev
$ composer require doctrine/migrations dev-master
$ composer require doctrine/doctrine-migrations-bundle dev-master
将 KunstmaanTranslatorBundle 添加到您的 AppKernel.php 文件
new Kunstmaan\TranslatorBundle\KunstmaanTranslatorBundle(), new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
将 KunstmaanTranslatorBundle 添加到您的 routing.yml。考虑到您自己的路由配置,您可能需要在您自己的路由配置之前添加以下代码
KunstmaanTranslatorBundle: resource: "@KunstmaanTranslatorBundle/Resources/config/routing.yml" prefix: /{_locale}/ requirements: _locale: "%requiredlocales%"
配置
根据需要覆盖 config.yml 中的 KunstmaanTranslatorBundle 配置,以下为默认值
kunstmaan_translator: enabled: true default_bundle: own bundles: [] cache_dir: %kernel.cache_dir%/translations managed_locales: [] file_formats: ['yml', 'yaml', 'xliff'] debug: defaults to the kernel.debug parameter (boolean)
enabled
: 启用或禁用 KunstmaanTranslatorBundledefault_bundle
: 在后端使用导入功能所用的哪些束。可能的值:'own', 'all', 'custom'。- own : 您 src 目录中的所有束
- all : 您 src 目录中的所有束 + 您 vendor 目录中的所有束
- custom : 您在
bundles
中指定的束
bundles
: 将用于后端导入功能的束列表。仅在default_bundle
设置为 'custom' 时使用。cache_dir
: 缓存翻译目录managed_locales
: 应导入哪些区域设置翻译文件file_formats
: 应导入哪种类型的翻译文件debug
: 当启用调试时,禁用翻译缓存
示例配置
kunstmaan_translator: managed_locales: ['en', 'fr', 'es']
kunstmaan_translator: default_bundle: own managed_locales: ['en', 'fr', 'es'] debug: false
kunstmaan_translator: enabled: true default_bundle: custom bundles: ['MyCompanyCoolBundle', 'MyCompanyAwesomeBundle'] managed_locales: ['en', 'fr', 'es']
数据库模式
使用 doctrine 更新您的数据库模式
bin/console doctrine:schema:update --force Database schema updated successfully! "1" queries were executed
将开发翻译迁移到生产
使用以下命令生成 doctrine 迁移,其中包含从您当前环境的所有新翻译和更新的翻译。
bin/console kuma:translator:migrations:diff
当您想将迁移的这些翻译包含到您的(其他)环境时,使用正常的 doctrine migrate 命令。
bin/console doctrine:migrations:migrate
导入现有翻译文件
当迁移您的当前项目时,您可以轻松导入现有翻译文件。
如果没有参数,则包括所有翻译,从当前 main
项目中的所有区域
bin/console kuma:translator:import
要强制覆盖存储器中的现有翻译
bin/console kuma:translator:import --force
要导入特定束的翻译
bin/console kuma:translator:import --bundle=superCoolNewApplicationBundle
要导入特定区域
bin/console kuma:translator:import --locales=nl,fr,de
要从全局资源(app/Resources/translations)导入翻译
bin/console kuma:translator:import --globals
缓存是如何工作的
翻译存储在数据库中,但在非调试模式下缓存(如 Symfony 通常所做)。
$kernel = new AppKernel('prod', false); // translations are cached an read from this cache
$kernel = new AppKernel('dev', true); // translations are always loaded from the stash (slower, more queries)
当在后台编辑翻译时,更改不会立即在您的网站上可见。当未加载较新或更新的翻译到缓存时,后端将显示警告消息。单击 刷新实时
按钮以重建缓存。
清除缓存和请求状态
清除翻译缓存文件,这将触发在访问页面时重建翻译缓存
bin/console kuma:translator:cache --flush
请求当前缓存的状态
bin/console kuma:translator:cache --status
重置翻译标志
当所有翻译都更新到最新状态时,例如将所有开发翻译迁移到生产环境中,您需要重置所有标记翻译为新或更新的标志。否则,已迁移的翻译将再次添加到后续迁移中(这可能会导致插入和唯一键错误)
bin/console kuma:translator:flag --reset
查找翻译的关键字/域
您可能并不总是记得特定页面上的翻译使用的是哪个关键字和/或域。为了解决这个问题,您可以在请求中添加一个额外的GET参数。将?transSource=1
添加到您的URL中,以查看所有翻译标签的来源。
您可能会看到“Hello world”而不是“Hello world”,而是header.hello_world (messages)
。这意味着
- 关键字是header.hello_world
- 域是messages
Symfony Profiler集成
Symfony Profiler显示了当前请求中使用的翻译数量
当您点击此项目时,您可以看到当前请求中使用的所有翻译以及添加或编辑它们的Kunstmaan Admin后端链接。
工作流程示例(新项目)
- 在您的模板文件中添加翻译(带关键字)(开发环境)
- 通过“添加翻译”将(1)的翻译添加到您的后端(开发环境)
- 重复1和2
- 创建迁移差异
bin/console kuma:translator:migrations:diff
(开发环境) - 重置翻译标志
bin/console kuma:translator:flag --reset
(开发环境) - 部署您的应用程序
- 执行Doctrine迁移
bin/console doctrine:migrations:migrate
(生产环境) - 编辑/添加翻译(生产环境)
- 编辑/添加完成后,单击“刷新实时”或
bin/console kuma:translator:cache --flush
(生产环境) - 在prod中编辑/添加翻译时,重复7和8
工作流程示例(现有项目)
- 导入当前翻译,点击“导入 -> 导入”或
bin/console kuma:translator:import
(生产/开发环境) - 如果您在开发环境中进行了1的操作,请转到“工作流程示例(新项目)”中的4,否则转到7“工作流程示例(新项目)”
功能
- 从任何类型的翻译文件导入bundle/global翻译
- 仅导入特定翻译(仅从控制台命令中导入)
- 强制导入以覆盖具有相同域/关键字/语言环境的现有翻译
- 从后端界面编辑存储的翻译
- 从后端界面添加新翻译
- 翻译被缓存(如果禁用调试)
- 当缓存的翻译与存储的翻译不一致时发出警告
- 清除翻译缓存以从存储的翻译重建翻译
- 较新或更新的翻译被标记
- 创建包含所有标记翻译的Doctrine迁移文件
- 重置所有标记翻译(从控制台命令中)
- 从控制台命令清除和检查翻译缓存
- 检查所有翻译的关键字和域的页面
开发说明
运行单元测试
./vendor/bin/phpunit -c phpunit.xml.dist
运行PHP CS Fixer,在安装php-cs-fixer系统全局后
php-cs-fixer fix .
如何创建您自己的文件导出器
- 将您的导出器标记为`translation.exporter`
- 实现\Kunstmaan\TranslatorBundle\Service\Exporter\FileExporterInterface
注意:导出尚未稳定(目前)