simpliko_cz/wavevision_namespace-translator
Composer 安装命令:
composer require simpliko_cz/wavevision_namespace-translator
包简介
Manage Nette app translations on per namespace basis.
README 文档
README
Namespace Translator
Translations manager for Nette framework using contributte/translation. It allows you to have your translation files located where they are really used (e.g. next to a component or a model).
No more global translations mess! 💪
Installation
Via Composer
composer require wavevision/namespace-translator
Note: This will automatically install
contributte/translationtoo.
Usage
Register required extensions in your project config:
extensions: translation: Contributte\Translation\DI\TranslationExtension namespaceTranslator: Wavevision\NamespaceTranslator\DI\Extension
You can configure namespaceTranslator as follows (default values):
namespaceTranslator: dirNames: # names of dirs in which namespace translations will reside - translations - Translations loaders: # namespace translations loaders neon: Wavevision\NamespaceTranslator\Loaders\Neon php: Wavevision\NamespaceTranslator\Loaders\TranslationClass flatJson: Wavevision\NamespaceTranslator\Loaders\FlatJson
Note: Refer to Contributte docs for further info about configuring
translation.
With this setup, you can start managing your translations like a boss 🤵.
The best thing is the translator keeps full backwards compatibility with contributte/translation setup,
so you can still use your translations as you are used to and migrate to namespaces step-by-step.
Any translation not found by namespace translator will fallback to translation resources.
Translated components
Your components (or presenters) can use Wavevision\NamespaceTranslator\TranslatedComponent trait.
Make sure your component has inject allowed.
The trait will provide your component class / template with $translator property / variable.
The translator will look for resources in configured dir names inside component's namespace.
Note: The
translatemacro in component templates will, of course, work too.
Translated models
Even your services can use the translator. Simply use Wavevision\NamespaceTranslator\NamespaceTranslator.
Make sure your service is registered with inject: true in your config.
After that, it works the same as with your components.
Loaders
There are three resource loaders included by default:
- Neon – loads translations from
neonfiles - TranslationClass – loads translations from PHP classes
- FlatJson - loads translations from flat (no nesting)
jsonfiles
Using PHP classes is useful when you want to refer to your translations using constants so changes in your resources get propagated throughout the whole project.
Classes containing translations must implement Wavevision\NamespaceTranslator\Resources\Translation.
You can also create and register your own loader, just make sure it implements Wavevision\NamespaceTranslator\Loaders\Loader.
Export \ Import
For exporting \ importing translations to \ from CSV or GoogleSheet (or both) update configuration file
namespaceTranslator: transfer: google: credentials: credentials.json sheetId: googleSheetId parts: - directory: %vendorDir%/../App/AdminModule tabName: admin-module csv: parts: - directory: %vendorDir%/../App/FrontModule filename: %vendorDir%/../temp/front-module.csv
Set locales whitelist from contributte/translation. Whitelist is used for creating translation columns in export.
Run command to export translations
php {bin/console} namespace-translator:export
Update translations, then run command to import them
php {bin/console} namespace-translator:import
Google Sheet
For accessing Google sheet you will need server-to-server API key and sheet ID.
Export example
From files
# file translations/en.neon hello: Hello %name%
# file translations/de.neon hello: Hallo %name%
<?php declare(strict_types=1); //file Translations/Cs.php use Wavevision\NamespaceTranslator\Resources\Translation; use Wavevision\NamespaceTranslator\Loaders\TranslationClass\Message; class Cs implements Translation { public const HELLO = 'hello'; public const NAME = 'name'; public static function define() : array { return [self::HELLO => Message::create('Hello %s', self::NAME)]; } }
export should look like this
file, key, en, de, format /translations/, hello, Hello %name%, Hallo %name%, neon /Translations/, c:self-HELLO, Hello {c:self-Name}, , php
columns file, key and format shouldn't be modified.
For details see example export.csv.
Limitation of TranslationClass
- Define function must have only one statement (
return [...]) - Array keys must be strings or class constants
- Array values must be arrays, strings or
Message::create()function calls - Php files should be linted after import
Examples
See tests for example app implementation.
simpliko_cz/wavevision_namespace-translator 适用场景与选型建议
simpliko_cz/wavevision_namespace-translator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 simpliko_cz/wavevision_namespace-translator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simpliko_cz/wavevision_namespace-translator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-07