PHPackages                             carica/localize - 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. carica/localize

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

carica/localize
===============

Extract and localize messages in PHP applications

1.0.0(1y ago)0173MITPHPPHP ^8.2

Since Nov 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ThomasWeinert/carica-localize)[ Packagist](https://packagist.org/packages/carica/localize)[ RSS](/packages/carica-localize/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Carica Localize
===============

[](#carica-localize)

Allows to localize messages in a PHP application. It uses the `ext/intl` MessageFormatter to allow ICU message syntax.

The goal is to have a mostly automated way to maintain the localized texts continuously.

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

[](#requirements)

- PHP &gt;= 8.2
- ext/intl
- ext/dom
- ext/xsl (when using XSL features)
- nikic/php-parser

Define
------

[](#define)

The library provides functions/templates for different contexts (PHP and XSL at the moment). The arguments are the same.

- `message` - The message text itself. ICU message syntax is supported.
- `meaning` - A category label for the message. (`financial` or `furniture` for `bank`)
- `id` - The message identifier (Auto generated from `message` and `meaning` if not provided.)
- `description` - A description of the message for translators.
- `values` - Placeholder values for the message.

It is mandatory to use string literals for all arguments except the `values`. !DO NOT USE VARIABLES!. The extractor will not work otherwise.

### PHP

[](#php)

Use the static call `Localize::message` to define your texts.

```
use Carica\Localize\Localize;

echo Localize::message('Example', meaning: 'test'), "\n";
echo Localize::message('Example', id: 'test.id'), "\n";
echo Localize::message('Example: {foo}', values: ['foo'=>'VALUE']), "\n";
```

### XSL

[](#xsl)

You need to register the stream wrapper and the callback function.

```
use Carica\Localize\XSL\Callbacks;

$processor = new \XSLTProcessor();
$processor->registerPHPFunctions([Callbacks::XSL_CALLBACK]);
```

The file loader allows your template to import the localize template. The callback function provides connection to the `ext/intl` MessageFormatter.

The message template is `{urn:carica:localize}message`. It uses a namespace to avoid conflicts.

```

        Example

        example.other
        Example: {foo}

          PARAMETER

```

Extract + Merge
---------------

[](#extract--merge)

Define an extraction for your project as an PHP helper script.

```
use Carica\Localize\Extraction;
use Carica\Localize\Serializer\Report\ConsoleReport;

$sourceLanguage = 'en';
$targetLanguages = ['de', 'fr'];

$messages = new Extraction(
  __DIR__.'../src/',
  [
    '(\\.php$)i' => new Extraction\PHPStaticFunctionExtractor()
    '(\\.xsl$)i' => new Extraction\XSLExtractor()
  ],
  function (Extraction\ConflictException $e) {
    echo $e->getMessage(), "\n";
  }
);
$messages->output(
  __DIR__.'../src/l10n',
  $sourceLanguage,
  $targetLanguages,
  'example',
  report: new ConsoleReport()
);
```

Running the script will generate XLIFF files for the source and each target language in the output directory. If the files exists they will be updated and existing translation in the target language files will be merged.

Load Translations
-----------------

[](#load-translations)

Add some logic to your PHP/XSL to load the messages for the current language.

### PHP

[](#php-1)

```
use Carica\Localize\Localize;
use Carica\Localize\Messages\XliffFileMessages;

Localize::messages(
  new XliffFileMessages(__DIR__.'/example.de.xlf')
);
```

### XSL

[](#xsl-1)

XLIFF files are XML, so they can be loaded using the `document()` function. `{urn:carica:localize}messages-file` helps to compile the message file name.

```

  de

```

### Translate

[](#translate)

For local translations you can use a tool like [POEdit](https://poedit.net/).

If you work in a team I suggest taking a look at [Weblate](https://weblate.org/de/). Weblate can connect to your GIT repository.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

581d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/236825?v=4)[Thomas Weinert](/maintainers/ThomasWeinert)[@ThomasWeinert](https://github.com/ThomasWeinert)

---

Top Contributors

[![ThomasWeinert](https://avatars.githubusercontent.com/u/236825?v=4)](https://github.com/ThomasWeinert "ThomasWeinert (28 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/carica-localize/health.svg)

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

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k9.9M89](/packages/dedoc-scramble)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[jms/translation-bundle

Puts the Symfony Translation Component on steroids

42411.0M74](/packages/jms-translation-bundle)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[php-translation/extractor

Extract translations form the source code

1284.5M9](/packages/php-translation-extractor)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9184.1M24](/packages/phparkitect-phparkitect)

PHPackages © 2026

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