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

ActiveLibrary

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

Extract and localize messages in PHP applications

1.0.0(1y ago)0166↓100%MITPHPPHP ^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 today

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

30

—

LowBetter than 67% of packages

Maintenance41

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

490d 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

[phpunit/php-code-coverage

Library that provides collection, processing, and rendering functionality for PHP code coverage information.

8.9k879.4M1.4k](/packages/phpunit-php-code-coverage)[psy/psysh

An interactive shell for modern PHP.

9.8k534.6M650](/packages/psy-psysh)[zircote/swagger-php

Generate interactive documentation for your RESTful API using PHP attributes (preferred) or PHPDoc annotations

5.3k129.4M415](/packages/zircote-swagger-php)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k76.1M6.1k](/packages/vimeo-psalm)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k95.0M1.8k](/packages/behat-behat)[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k108.7M499](/packages/symfony-maker-bundle)

PHPackages © 2026

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