Download the PHP package drago-ex/translator without Composer
On this page you can find all versions of the php package drago-ex/translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download drago-ex/translator
More information about drago-ex/translator
Files in drago-ex/translator
Package translator
Short Description Lightweight translator for Nette Framework using NEON files, supporting global and module-specific translations.
License MIT
Informations about the package translator
Drago Translator
Lightweight translator for Nette Framework using NEON files, supporting global and module-specific translations.
Requirements
- PHP >= 8.3
- Nette Framework
- Composer
Installation
Extension Registration
Register the DI extension in your NEON configuration.
Optional configuration
Translator Behavior
- All directories listed in translateDirs are loaded in order.
- Later directories override translations from earlier ones.
- If autoFinder is enabled, the entire application directory is scanned for NEON files.
- Directories listed in exclude are skipped during automatic scanning.
Translation files must be named by language code:
Translation File Format
Using Translator in Presenters
Add the TranslatorAdapter trait to your presenter:
The trait provides:
- persistent language parameter ($lang)
- automatic translator initialization
- template integration
Accessing the Current Language
You can access the currently set language using the following property:
Getting Translator Instance
To get the initialized translator for the current language:
Using Translations in Templates
The translator is automatically registered in templates. Example usage in Latte:
Using Translator in Forms
To enable translations in forms, set the translator explicitly:
Routing for Language Switching
To support language prefixes, configure your routes accordingly:
Switching Languages in Templates
You can switch languages by passing the lang parameter:
Language Switch Widget
The package provides a reusable Latte widget for language switching.
When project file copying is handled by drago-ex/project-tools, the widget is copied to:
Import the widget in your layout:
Render language links:
The current language link automatically receives the current class.
Available options:
lang- target language code.name- visible translated label.class- optional class added to the link.tag- optional wrapper tag:li,div, orspan.tagClass- optional class added to the wrapper tag.
Use class when the link needs a custom class:
Use tag when the link must be wrapped, for example in a dropdown menu:
Use tagClass when the wrapper needs styling:
Notes
- Translator loads translations lazily on first use
- Translations are loaded once per request
- Missing keys return the original message
All versions of translator with dependencies
nette/di Version ^3.1
nette/utils Version ^4.0
nette/application Version ^3.1
nette/caching Version ^3.4
tracy/tracy Version ^2.10