Download the PHP package wavevision/namespace-translator without Composer
On this page you can find all versions of the php package wavevision/namespace-translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wavevision/namespace-translator
More information about wavevision/namespace-translator
Files in wavevision/namespace-translator
Package namespace-translator
Short Description Manage Nette app translations on per namespace basis.
License MIT
Informations about the package namespace-translator
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
Note: This will automatically install
contributte/translation
too.
Usage
Register required extensions in your project config:
You can configure namespaceTranslator
as follows (default values):
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
translate
macro 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
neon
files - TranslationClass – loads translations from PHP classes
- FlatJson - loads translations from flat (no nesting)
json
files
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
Set locales whitelist from contributte/translation. Whitelist is used for creating translation columns in export.
Run command to export translations
Update translations, then run command to import them
Google Sheet
For accessing Google sheet you will need server-to-server API key and sheet ID.
Export example
From files
export should look like this
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.
All versions of namespace-translator with dependencies
contributte/console Version ^0.9
contributte/translation Version ^0.8
google/apiclient Version ^2.7
nette/application Version ^3.1
nette/di Version ^3.0
nette/neon Version ^3.0
nikic/php-parser Version ^4.9
wavevision/di-service-annotation Version ^4.0
wavevision/utils Version ^2.1