PHPackages                             webhappens/laravel-po - 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. webhappens/laravel-po

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

webhappens/laravel-po
=====================

Synchronize Laravel PHP translation arrays with PO (Portable Object) files, with optional POEditor integration

v0.6.0(1mo ago)0491↓41.7%MITPHPPHP ^8.3|^8.4|^8.5CI passing

Since Nov 13Pushed 1mo agoCompare

[ Source](https://github.com/webhappens/laravel-po)[ Packagist](https://packagist.org/packages/webhappens/laravel-po)[ RSS](/packages/webhappens-laravel-po/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (18)Versions (9)Used By (0)

Laravel PO
==========

[](#laravel-po)

[![Tests](https://github.com/webhappens/laravel-po/workflows/Tests/badge.svg)](https://github.com/webhappens/laravel-po/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/b130c87a36b56a63b919e92438996185bd5d6b23184970b394a86336fe2a5299/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77656268617070656e732f6c61726176656c2d706f2e737667)](https://packagist.org/packages/webhappens/laravel-po)[![Total Downloads](https://camo.githubusercontent.com/49f586923fa6b9f47f20d8065a182dda846087e054d5a52da84e9528e24c9856/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656268617070656e732f6c61726176656c2d706f2e737667)](https://packagist.org/packages/webhappens/laravel-po)[![License](https://camo.githubusercontent.com/1390fb27bb74b1f845493ac4e0ee08b4c922cce8778648d2d7cd5156426cec29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656268617070656e732f6c61726176656c2d706f2e737667)](https://packagist.org/packages/webhappens/laravel-po)

A Laravel package for synchronizing Laravel PHP translation arrays with PO (Portable Object) files, with optional POEditor integration.

Perfect for teams using translation management services like POEditor, Crowdin, or Lokalise that work with industry-standard gettext PO files.

Features
--------

[](#features)

- 📤 **Export** Laravel PHP translations to PO files
- 📥 **Import** PO files back to Laravel PHP arrays
- 🔄 **POEditor Integration** - Download translations directly from POEditor API
- 🎯 **Selective Imports** - Filter translations by pattern with `--only` option
- 🔀 **Merge or Replace** - Choose to merge with existing translations or replace them
- 🌐 **Auto-detection** - Automatically detect available languages from your lang directory
- 🧪 **Fully Tested** - Comprehensive test suite with 30+ tests
- ⚙️ **Configurable** - All paths and settings can be customized

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

[](#requirements)

- PHP 8.2 or higher
- Laravel 11.x or higher

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

[](#installation)

Install the package via Composer:

```
composer require webhappens/laravel-po
```

The service provider will be automatically registered via Laravel's package discovery.

### Publish Configuration

[](#publish-configuration)

Publish the configuration file to customize paths and settings:

```
php artisan vendor:publish --tag=po-config
```

This will create a `config/po.php` file where you can configure:

- Export and import directory paths
- Excluded translation groups
- Language definitions
- POEditor API credentials
- Cache clearing callbacks

Configuration
-------------

[](#configuration)

### Basic Configuration

[](#basic-configuration)

```
// config/po.php

return [
    'paths' => [
        'export' => lang_path('export'),  // Where PO files are exported
        'import' => lang_path('import'),  // Where PO files are imported from
        'lang' => lang_path(),            // Root translation directory
    ],

    'excluded_groups' => [
        'auth',
        'pagination',
        'passwords',
        'validation',
    ],

    'languages' => [
        // Leave empty for auto-detection, or define explicitly:
        'en' => ['label' => 'English', 'enabled' => true],
        'fr' => ['label' => 'Français', 'enabled' => true],
        'de' => ['label' => 'Deutsch', 'enabled' => true],
    ],
];
```

### POEditor Integration

[](#poeditor-integration)

If you use POEditor, add these to your `.env` file:

```
POEDITOR_ENABLED=true
POEDITOR_API_TOKEN=your-api-token-here
POEDITOR_PROJECT_ID=your-project-id-here
```

### Cache Clearing (Optional)

[](#cache-clearing-optional)

If your application caches compiled translation catalogues, configure a callback to clear the cache after importing:

```
// config/po.php

'cache' => [
    'clear_callback' => function ($locale) {
        Cache::forget("catalogue:{$locale}");
        File::delete(storage_path("app/cache/catalogue:{$locale}"));
    },
],
```

Usage
-----

[](#usage)

### Export Translations to PO Files

[](#export-translations-to-po-files)

Export all translations for the default language:

```
php artisan po:export
```

Export translations for specific languages:

```
php artisan po:export fr de es
```

This will create PO files in your configured export directory (default: `lang/export/`):

```
lang/export/
├── fr.po
├── de.po
└── es.po

```

#### Export Options

[](#export-options)

**Export all enabled languages:**

```
php artisan po:export --all
```

**Clear export directory before generating:**

```
php artisan po:export --clear
```

### Import PO Files to Laravel

[](#import-po-files-to-laravel)

Import all available PO files:

```
php artisan po:import
```

Import specific languages:

```
php artisan po:import fr de
```

#### Import Options

[](#import-options)

**Include fuzzy translations:**

```
php artisan po:import --fuzzy
```

**Filter to specific translation keys:**

```
php artisan po:import --only=actions.*
php artisan po:import --only=messages.* --only=actions.*
```

**Replace existing translations instead of merging:**

```
php artisan po:import --replace
```

By default, imports will merge new translations with existing ones. Use `--replace` to completely replace the translation files.

### Download from POEditor

[](#download-from-poeditor)

Download PO files from POEditor (requires POEditor configuration):

```
# Download all enabled languages
php artisan po:download --all

# Download specific languages
php artisan po:download fr de es
```

Downloaded files will be saved to your import directory. Then run the import command:

```
php artisan po:import
```

Workflow Example
----------------

[](#workflow-example)

### Working with POEditor

[](#working-with-poeditor)

1. **Export your current translations:**

    ```
    php artisan po:export
    ```
2. **Upload PO files to POEditor** (manually or via their API)
3. **Translators work on translations in POEditor**
4. **Download updated translations:**

    ```
    php artisan po:download --all
    ```
5. **Import the translations:**

    ```
    php artisan po:import
    ```
6. **Commit the updated translation files to your repository**

### Working with Translation Agencies

[](#working-with-translation-agencies)

1. **Export translations:**

    ```
    php artisan po:export fr de es
    ```
2. **Send PO files** from `lang/export/` to your translation agency
3. **Receive translated PO files** and place them in `lang/import/`
4. **Import the translations:**

    ```
    php artisan po:import
    ```

How It Works
------------

[](#how-it-works)

### Placeholder Conversion

[](#placeholder-conversion)

The package automatically converts between Laravel and gettext placeholder formats:

**Laravel format (in PHP files):**

```
'welcome' => 'Hello :name, you have :count messages'
```

**Gettext format (in PO files):**

```
msgid "Hello {name}, you have {count} messages"

```

This conversion happens automatically during export and import.

### Translation Grouping

[](#translation-grouping)

Laravel translations are organized into groups (files), and the package maintains this structure:

**PHP files:**

```
lang/en/
├── actions.php
├── messages.php
└── errors.php

```

**PO file structure:**

```
msgctxt "actions.save"
msgid "Save"
msgstr "Sauvegarder"

msgctxt "messages.welcome"
msgid "Welcome"
msgstr "Bienvenue"

msgctxt "errors.not_found"
msgid "Not found"
msgstr "Non trouvé"

```

The first part before the dot (e.g., `actions`, `messages`) determines which PHP file the translation belongs to.

### Nested Translations

[](#nested-translations)

Nested arrays are automatically flattened to dot notation:

**PHP:**

```
// lang/en/messages.php
return [
    'user' => [
        'welcome' => 'Welcome :name',
        'goodbye' => 'Goodbye :name',
    ],
];
```

**PO:**

```
msgctxt "messages.user.welcome"
msgid "Welcome {name}"
msgstr "..."

msgctxt "messages.user.goodbye"
msgid "Goodbye {name}"
msgstr "..."

```

Testing
-------

[](#testing)

Run the test suite:

```
cd ~/Sites/packages/laravel-po
composer test
```

The package includes comprehensive tests covering:

- Export functionality
- Import functionality with merge/replace modes
- Placeholder conversion
- Fuzzy translation handling
- POEditor API integration (with HTTP mocking - no POEditor account required!)
- Pattern filtering
- Language auto-detection

**Note:** Tests use HTTP mocking for POEditor API calls, so you don't need a POEditor account or project to run the tests.

For detailed testing instructions, see [TESTING.md](TESTING.md).

Directory Structure
-------------------

[](#directory-structure)

```
your-laravel-app/
└── lang/
    ├── export/          # Generated PO files (add to .gitignore)
    ├── import/          # PO files to be imported (add to .gitignore)
    ├── en/
    │   ├── actions.php
    │   ├── messages.php
    │   └── ...
    ├── fr/
    │   ├── actions.php
    │   ├── messages.php
    │   └── ...
    └── de/
        ├── actions.php
        ├── messages.php
        └── ...

```

**Recommended `.gitignore`:**

```
/lang/export/*
!/lang/export/.gitignore

/lang/import/*
!/lang/import/.gitignore
```

This keeps the directories tracked while ignoring the PO files themselves.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [WebHappens](https://webhappens.co.uk)
- Built with [gettext/gettext](https://github.com/php-gettext/Gettext)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance89

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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 ~21 days

Recently: every ~30 days

Total

7

Last Release

55d ago

PHP version history (2 changes)v0.1.0PHP ^8.2|^8.3|^8.4

v0.6.0PHP ^8.3|^8.4|^8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/319829?v=4)[Sam Leicester](/maintainers/sleicester)[@sleicester](https://github.com/sleicester)

---

Top Contributors

[![sleicester](https://avatars.githubusercontent.com/u/319829?v=4)](https://github.com/sleicester "sleicester (19 commits)")

---

Tags

laravellocalizationi18ntranslationsgettextpoPoeditor

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webhappens-laravel-po/health.svg)

```
[![Health](https://phpackages.com/badges/webhappens-laravel-po/health.svg)](https://phpackages.com/packages/webhappens-laravel-po)
```

###  Alternatives

[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.6M17](/packages/barryvdh-laravel-translation-manager)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)[laravel-lang/publisher

Localization publisher for your Laravel application

2167.7M24](/packages/laravel-lang-publisher)[tio/laravel

Add this package to localize your Laravel application (PHP, JSON or GetText).

170318.5k](/packages/tio-laravel)[outhebox/laravel-translations

Manage your Laravel translations with a beautiful UI. Add, edit, delete, import, and export translations with ease.

80687.6k](/packages/outhebox-laravel-translations)[vemcogroup/laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor

135304.0k2](/packages/vemcogroup-laravel-translation)

PHPackages © 2026

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