Download the PHP package jdz/language without Composer
On this page you can find all versions of the php package jdz/language. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package language
JDZ Language
Language is a proxy to the symfony/translation component - a modular PHP package designed for managing and translating multilingual content in your web projects. This project simplifies the use of language files and provides a clear API for easily handling translations.
Features
- Built on the symfony/translation component for robust translation capabilities.
- Uses the symfony/string inflector for pluralization and singularization.
- LanguageCode enum for type-safe language code handling.
- Custom LanguageException for language-specific error handling.
- Load default or application-specific language files.
- Flexible management of translation keys.
- Support for YAML format language files.
- Easy integration with other frameworks or custom solutions.
- Optimized for fast performance and maximum extensibility.
- Inflector support for French, English & Spanish (introduced in symfony/string 7.2, requires PHP >= 8.2).
Installation
Add the package to your project using Composer:
Requirements
- PHP 8.2 or higher
- symfony/translation
- symfony/string
- symfony/yaml
Usage
For a complete example, check the example folder in the repository.
Initialization
Load User Language
If not an available language, it falls back to the default language.
Load Translations from Array
Load Translations from YAML File
Example YAML file:
Setting Values
Getting Values
Using LanguageCode Enum
API Reference
Language Class Methods
| Method | Description |
|---|---|
load(string $lang) |
Load a user language. Throws LanguageException if invalid. |
loadYamlFiles(array $resources) |
Load translations from an array of YAML files. |
loadYamlFile(string $resource) |
Load translations from a single YAML file. |
loadArray(array $strings) |
Load translations from an array of key => value pairs. |
set(string $key, mixed $value) |
Adds a translation. |
get(string $key, array $parameters = [], ?string $default = null) |
Retrieves a translation at the specified path. |
has(string $key) |
Checks if a translation exists at the specified path. |
plural(string $key, int $count) |
Load a plural translation with count parameter. |
pluralize(string $string) |
Uses the symfony/string inflector to pluralize a word. |
singularize(string $string) |
Uses the symfony/string inflector to singularize a word. |
LanguageCode Enum
Available language codes:
LanguageCode::FRENCH(value: 'fr')LanguageCode::ENGLISH(value: 'en')LanguageCode::SPANISH(value: 'es')
Methods:
LanguageCode::isValid(string $value): bool- Check if a string is a valid language code
LanguageException
Custom exception class for language-specific errors. Extends \Exception.
Testing
The package includes a comprehensive test suite with 38 tests covering all functionality.
To run the tests:
Or directly with PHPUnit:
License
This project is licensed under the MIT License - see the LICENSE file for details.
All versions of language with dependencies
symfony/translation Version ^7.4
symfony/string Version ^7.4
symfony/yaml Version ^7.4