PHPackages                             imponeer/symfony-translations-constants-loader - 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. imponeer/symfony-translations-constants-loader

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

imponeer/symfony-translations-constants-loader
==============================================

symfony/translation extension to load PHP files that are defined all translations as constants

v2.1.0(11mo ago)024.1k↓33.3%1MITPHPPHP &gt;=8.3CI passing

Since Nov 11Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/imponeer/symfony-translations-constants-loader)[ Packagist](https://packagist.org/packages/imponeer/symfony-translations-constants-loader)[ RSS](/packages/imponeer-symfony-translations-constants-loader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (1)

[![Packagist License](https://camo.githubusercontent.com/add1d7297c5a968d4fd8ccc8a7a1da10c616c164b3a7d55daf5c6cfef42a7a65/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696d706f6e6565722f73796d666f6e792d7472616e736c6174696f6e732d636f6e7374616e74732d6c6f61646572)](https://github.com/imponeer/symfony-translations-constants-loader/blob/main/LICENSE) [![Packagist Version](https://camo.githubusercontent.com/f5cb64fbf9926768cb2baa5b6e53e66f014ef0070211b43094380a583beb9a57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d706f6e6565722f73796d666f6e792d7472616e736c6174696f6e732d636f6e7374616e74732d6c6f61646572)](https://packagist.org/packages/imponeer/symfony-translations-constants-loader) [![Packagist Dependency Version](https://camo.githubusercontent.com/ee34177e2753d47e8cf96645e9baf34e81ad0270bcfaa887007d73834643f3cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f696d706f6e6565722f73796d666f6e792d7472616e736c6174696f6e732d636f6e7374616e74732d6c6f616465722f706870)](https://github.com/imponeer/symfony-translations-constants-loader/blob/main/composer.json)

Symfony Translations Constants Loader
=====================================

[](#symfony-translations-constants-loader)

Extension for [symfony/translation](https://symfony.com/doc/current/translation.html) package to load translations defined as constants list in PHP file.

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

[](#installation)

To install and use this package, we recommend to use [Composer](https://getcomposer.org):

```
composer require imponeer/symfony-translations-constants-loader
```

Otherwise you need to include manualy files from `src/` directory.

Usage Example
-------------

[](#usage-example)

### 1. Create a file with `define()` constants:

[](#1-create-a-file-with-define-constants)

```
// translations/en/messages.php

define('HELLO', 'Hello!');
define('GOODBYE', 'Goodbye!');
```

> 💡 You can create separate files for other locales, such as `translations/fr/messages.php`.

### 2. Load the constants using the PHPFileLoader:

[](#2-load-the-constants-using-the-phpfileloader)

```
use Symfony\Component\Translation\Translator;
use Imponeer\SymfonyTranslationsConstantsLoader\PHPFileLoader;

$translator = new Translator('en');

// Register the loader for the 'php_consts' format
$translator->addLoader('php_consts', new PHPFileLoader());

// Add your translation resource
$translator->addResource('php_consts', __DIR__ . '/translations/en/messages.php', 'en');

// Use translations
echo $translator->trans('HELLO');   // Outputs: Hello!
echo $translator->trans('GOODBYE'); // Outputs: Goodbye!
```

Development
-----------

[](#development)

### Code Style

[](#code-style)

This project follows the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standard. To check your code for style issues:

```
composer phpcs
```

To automatically fix most coding standards issues:

```
composer phpcbf
```

### Testing

[](#testing)

To run the test suite, execute:

```
vendor/bin/phpunit
```

This will run all tests in the `tests/` directory.

### Static Analysis

[](#static-analysis)

This project uses [PHPStan](https://phpstan.org/) for static code analysis at level 5. PHPStan helps detect bugs and potential issues without running the code.

To run the static analysis:

```
composer phpstan
```

The analysis checks both the `src/` and `tests/` directories. Configuration can be found in the `phpstan.neon` file.

How to contribute?
------------------

[](#how-to-contribute)

If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try read [GitHub documentation about git](https://docs.github.com/en/get-started/using-git).

Please make sure your code follows the PSR-12 coding standard by running the code style checks before submitting a pull request.

If you found any bug or have some questions, use [issues tab](https://github.com/imponeer/symfony-translations-constants-loader/issues) and write there your questions.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance67

Regular maintenance activity

Popularity24

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 74.7% 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 ~185 days

Recently: every ~229 days

Total

10

Last Release

347d ago

Major Versions

v1.0.7 → v2.0.02025-04-03

PHP version history (2 changes)v1.0.0PHP ^7.3 || ^8.0

v2.0.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dba53e399a507d1f60626164c8b1e340a5cc0dc4f0637f4c6aaff8fc239fdaee?d=identicon)[fiammybe](/maintainers/fiammybe)

![](https://www.gravatar.com/avatar/7255f306e0ca27292c50cdd9644c1c04e0d7b0f54bf35e0cdd79dc55c83b4923?d=identicon)[MekDrop](/maintainers/MekDrop)

![](https://www.gravatar.com/avatar/79009323fafcd4974bb1713b12eea0a610f01c4fb21cc5e85d446c4cb66453d4?d=identicon)[skenow](/maintainers/skenow)

---

Top Contributors

[![MekDrop](https://avatars.githubusercontent.com/u/342641?v=4)](https://github.com/MekDrop "MekDrop (65 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")[![fiammybe](https://avatars.githubusercontent.com/u/3736946?v=4)](https://github.com/fiammybe "fiammybe (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")

---

Tags

composer-libraryhacktoberfestlibraryloadersymfonytranslationsymfonytranslationloaderconstants

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imponeer-symfony-translations-constants-loader/health.svg)

```
[![Health](https://phpackages.com/badges/imponeer-symfony-translations-constants-loader/health.svg)](https://phpackages.com/packages/imponeer-symfony-translations-constants-loader)
```

###  Alternatives

[willdurand/js-translation-bundle

A pretty nice way to expose your translation messages to your JavaScript.

58917.1M55](/packages/willdurand-js-translation-bundle)[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)[contributte/translation

Symfony/Translation integration for Nette Framework.

771.8M37](/packages/contributte-translation)

PHPackages © 2026

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