PHPackages                             nmilosavljevic/po-editor - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. nmilosavljevic/po-editor

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

nmilosavljevic/po-editor
========================

PHP librabry which provides PHP web interface to edit or create po files

213PHP

Since Apr 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/neske89/po-editor)[ Packagist](https://packagist.org/packages/nmilosavljevic/po-editor)[ RSS](/packages/nmilosavljevic-po-editor/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PoEditor
========

[](#poeditor)

PHP library which provides PHP web interface to edit or create po files.

Credits
-------

[](#credits)

Library heavily relies on .

Licence
-------

[](#licence)

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

Instalation
-----------

[](#instalation)

Using composer

`composer require nmilosavljevic/po-editor`

Functionalities
---------------

[](#functionalities)

#### Generate translation keywords

[](#generate-translation-keywords)

Translations keywords could be generated from **php code files** or **twig files**, Support for more formats will be available in the future. PHP code file and twig file translations could be mergded to form single translation file. After each generation, unused keywords will be removed and new ones will be added to the list of the translations.

#### Reading .PO file

[](#reading-po-file)

Existing translations could be read from PO file.

#### Provides premade user interface for translating

[](#provides-premade-user-interface-for-translating)

Users could use already pre-made translations form, or you could build your own UI for translating.

#### Export to .PO &amp; ,MO files

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

With the location of files provided created or edited translations could be exported to .PO and .MO file.

Usage examples
--------------

[](#usage-examples)

### Instantiating

[](#instantiating)

```
	 $editor = new \NMilosavljevic\PoEditor\PoEditor();
	 //editor class has internal reference of translations
	 // $editor->translations

```

### Generating translations from PHP code file

[](#generating-translations-from-php-code-file)

```
	$phpTranslations = $editor->fromPHPCodeFile([
	'functions' => ['__' => 'gettext'],
	'directories' => ['App/Helpers/']]);

```

### Generating translations from TWIG file

[](#generating-translations-from-twig--file)

```
	$twigTranslations = $editor->fromTwigFile([
	'functions' => ['__' => 'gettext'],
	'directories' => [sprintf('%s/Helper', 'App/Template/)]]);

```

#### If TWIG file uses custom function to translate

[](#if-twig-file-uses-custom-function-to-translate)

Twig:

```
	{{ __("who_are_we") }}

```

PHP:

```
$twigTranslations = $editor->fromTwigFile([
'parser' => 'raw', //required
'functions' => ['__' => 'gettext'], //name of the function in twig file is __
 //path to the directory which contain multiple twigfiles
'directories' => [sprintf('%s/Template/Default', $portalPath)]]);`

```

#### Merge translations

[](#merge-translations)

```
 $twigTranslations->mergeWith($phpTranslations);

```

#### Read from PO file

[](#read-from-po-file)

```
$editor->readFromPOFile('App/Locale/en/translations.po');

```

#### SaveTranslations

[](#savetranslations)

```
$editor->saveTranslationFiles('App/Locale/en/',$twigTranslations,'en','messages');
//or
$editor->SaveTranslationsToPoMoFile('App/Locale/en/');
//in this case, $editor->translations are used

```

#### Get Editor HTML

[](#get-editor-html)

```
  $editor = new \NMilosavljevic\PoEditor\PoEditor();
   $shortcode = 'it';
  $portalPath = str_replace('Dashboard', 'Portal', PROJECT_DIR);
  $poFilePath = sprintf('%s/Locale/%s/LC_MESSAGES/messages.po',$portalPath,$shortcode);

   try{
        $twigTranslations = $editor->fromTwigFile([
             'parser' => 'raw',
             'functions' => ['__' => 'gettext'],
             'directories' => [sprintf('%s/Template/Default', $portalPath)]]);

        $phpTranslations = $editor->fromPHPCodeFile([
            'functions' => ['__' => 'gettext'],
             'directories' => [sprintf('%s/Helper', $portalPath)]]);

        //variables $twigTranslations and $phpTranslations are not used here, they are just declared
        //to show that function could return exported translations

        //in this case, translations exported from twig and php files are merged into $editor->translations
        //translations read from PO file will also be merged into $editor->translations

        $editor->readFromPOFile($poFilePath);
        $html = $editor->getEditorHTML();

        //render html in framework of your choice

```

#### Save translations Using Editor

[](#save-translations-using-editor)

Submiting the translations from the editor (by clicking save button) will send post request to the same url with parameters translations and optional parameter language.

Those parameters should be passed to saveFromEditor function

```
    $editor = new \NMilosavljevic\PoEditor\PoEditor();
    $shortcode = 'it';
    $portalPath = str_replace('Dashboard', 'Portal', PROJECT_DIR);
    $directory = sprintf('%s/Locale/%s/LC_MESSAGES/',$portalPath,$shortcode);
    $success = $editor->saveFromEditor($directory,$translations,'messages',$shortcode);
    //handle sending OK response here so that page could refresh.

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 86.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.

### Community

Maintainers

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

---

Top Contributors

[![neshke89](https://avatars.githubusercontent.com/u/4339671?v=4)](https://github.com/neshke89 "neshke89 (13 commits)")[![neske89](https://avatars.githubusercontent.com/u/43369947?v=4)](https://github.com/neske89 "neske89 (2 commits)")

### Embed Badge

![Health badge](/badges/nmilosavljevic-po-editor/health.svg)

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M227](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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