PHPackages                             jdz/language - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. jdz/language

ActiveLibrary[Localization &amp; i18n](/categories/localization)

jdz/language
============

JDZ Translator (i18n) and Inflector library based on Symfony components

2.0.1(1mo ago)019MITPHPPHP &gt;=8.2

Since Dec 20Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/joffreydemetz/language)[ Packagist](https://packagist.org/packages/jdz/language)[ Docs](https://jdz.joffreydemetz.com/language/)[ RSS](/packages/jdz-language/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (6)Used By (0)

JDZ 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
--------

[](#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 &amp; Spanish (introduced in symfony/string 7.2, requires PHP &gt;= 8.2).

Installation
------------

[](#installation)

Add the package to your project using **Composer**:

```
composer require jdz/language
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- symfony/translation
- symfony/string
- symfony/yaml

Usage
-----

[](#usage)

For a complete example, check the `example` folder in the repository.

### Initialization

[](#initialization)

```
use JDZ\Language\Language;

$language = new Language(
    // app languages
    ['fr', 'en'],
    // default language
    'fr'
);
```

### Load User Language

[](#load-user-language)

If not an available language, it falls back to the default language.

```
$language->load('fr');
```

### Load Translations from Array

[](#load-translations-from-array)

```
$language->loadArray([
    'welcome_message' => 'Hi !',
    'test' => [
        'key1' => 'Test 1 nested',
        'key2' => 'Test 1 nested 2',
    ],
    'test2' => 'Test 2',
]);
```

### Load Translations from YAML File

[](#load-translations-from-yaml-file)

```
$language->loadYamlFiles([
    __DIR__ . '/file1.yml',
    __DIR__ . '/file2.yml',
]);
$language->loadYamlFile(__DIR__ . '/file3.yml');
```

Example YAML file:

```
welcome_message: "Welcome"
goodbye_message: "Goodbye"
```

### Setting Values

[](#setting-values)

```
$language->set('custom.key', 'My custom value');
```

### Getting Values

[](#getting-values)

```
$welcomeMessage = $language->get('welcome_message');
// Hi !

$customMessage = $language->get('custom.key');
// My custom value

$notDefined = $language->get('test.me');
// test.me (returns key if not found)

$notDefinedButDefault = $language->get('test.me', [], 'Default value');
// Default value
```

### Using LanguageCode Enum

[](#using-languagecode-enum)

```
use JDZ\Language\LanguageCode;

// Check if a language code is valid
if (LanguageCode::isValid('fr')) {
    // Valid language
}

// Get language from enum
$french = LanguageCode::FRENCH;
echo $french->value; // 'fr'

// Try to get enum from string
$lang = LanguageCode::tryFrom('en'); // Returns LanguageCode::ENGLISH or null
```

API Reference
-------------

[](#api-reference)

### Language Class Methods

[](#language-class-methods)

MethodDescription`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 =&gt; 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

[](#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

[](#languageexception)

Custom exception class for language-specific errors. Extends `\Exception`.

Testing
-------

[](#testing)

The package includes a comprehensive test suite with 38 tests covering all functionality.

To run the tests:

```
composer test

# For detailed test output:
composer test -- --testdox
```

Or directly with PHPUnit:

```
vendor/bin/phpunit --colors=always --testdox
```

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~154 days

Total

4

Last Release

51d ago

Major Versions

1.0.1 → 2.0.02025-12-10

PHP version history (2 changes)1.0.1PHP &gt;=8.1

2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e83e3701566e43438525ed14578487e732b849d152b5071aa1613a0dad96913?d=identicon)[jdz](/maintainers/jdz)

---

Top Contributors

[![joffreydemetz](https://avatars.githubusercontent.com/u/15113527?v=4)](https://github.com/joffreydemetz "joffreydemetz (24 commits)")

---

Tags

i18nlanguagetranslateinflectJDZ

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jdz-language/health.svg)

```
[![Health](https://phpackages.com/badges/jdz-language/health.svg)](https://phpackages.com/packages/jdz-language)
```

###  Alternatives

[lexik/translation-bundle

This bundle allows to import translation files content into the database and provide a GUI to edit translations.

4362.7M19](/packages/lexik-translation-bundle)[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[aplus/language

Aplus Framework Language Library

2351.7M15](/packages/aplus-language)[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[optimistdigital/nova-translatable

A laravel-translatable extension for Laravel Nova.

202427.4k5](/packages/optimistdigital-nova-translatable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
