PHPackages                             phpnomad/gettext-integration - 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. phpnomad/gettext-integration

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

phpnomad/gettext-integration
============================

PHPNomad gettext translation strategy implementation

1.0.0(3mo ago)00MITPHP

Since Mar 31Pushed 2mo agoCompare

[ Source](https://github.com/phpnomad/gettext-integration)[ Packagist](https://packagist.org/packages/phpnomad/gettext-integration)[ Docs](https://github.com/phpnomad/gettext-integration)[ RSS](/packages/phpnomad-gettext-integration/feed)WikiDiscussions main Synced 4w ago

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

phpnomad/gettext-integration
============================

[](#phpnomadgettext-integration)

[![Latest Version](https://camo.githubusercontent.com/4c58652079dd8b265c61c39540387522282cb8904bb13933f0f0141058e7975d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f676574746578742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/gettext-integration)[![Total Downloads](https://camo.githubusercontent.com/c07d7a683e3d01796cba7d3c3a3af01d704f4f70ff42c1afcff0087bb442b708/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f676574746578742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/gettext-integration)[![PHP Version](https://camo.githubusercontent.com/f56a96eaa0ac14c73fd7109d63cb9dddd9fae282399375824dacc6582f9cae03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f676574746578742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/gettext-integration)[![License](https://camo.githubusercontent.com/d5e77873f1af4461dd726a0d5476d138623f359d25c73b6ace3322a9a0d94f29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f676574746578742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/gettext-integration)

Integrates PHP's built-in gettext extension with `phpnomad/translate`. This package provides a `TranslationStrategy` implementation that delegates to `dgettext` and `dngettext`, applies the locale through `setlocale(LC_MESSAGES, ...)`, and handles gettext's `msgctxt` context convention. If you'd rather not depend on the `ext-gettext` PHP extension, `phpnomad/symfony-translation-integration` implements the same abstraction against Symfony Translation instead.

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

[](#installation)

This package requires the `ext-gettext` PHP extension to be installed and enabled.

```
composer require phpnomad/gettext-integration
```

What This Provides
------------------

[](#what-this-provides)

- `PHPNomad\Gettext\Strategies\TranslationStrategy`, which implements `PHPNomad\Translations\Interfaces\TranslationStrategy` using `dgettext` and `dngettext`.
- Locale application from an injected `HasLanguage` provider, applied with `setlocale(LC_MESSAGES, ...)` on every call.
- Context disambiguation via the gettext `msgctxt` convention (EOT separator `\x04`), with fallback to the untranslated source (or the appropriate singular/plural form) when no translation is registered for that context.

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

[](#requirements)

- PHP 8.0+
- `ext-gettext` PHP extension
- `phpnomad/translate ^2.0`
- A `HasTextDomain` provider and a `HasLanguage` provider bound in your container (both interfaces ship with `phpnomad/translate`)

Usage
-----

[](#usage)

Bind the `TranslationStrategy` interface from `phpnomad/translate` to the gettext implementation inside your bootstrapper. The strategy is then resolved wherever the interface is injected.

```
