php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
688 stars 134 forks source link

PO file generator issues #295

Closed EvilBozkurt closed 3 months ago

EvilBozkurt commented 5 months ago

I want to ask two questions. How can I define headers when using the PO file generator? And after I translate, when I produce a file, all the translated words disappear. How should I deal with this problem?

oscarotero commented 5 months ago

Headers are added in the Translations instance.

$translations->getHeaders()->set('key', 'value');

And then you have to pass the translations instance to the Po generator:

$poGenerator = new PoGenerator();

$poGenerator->generateFile($translations, 'locales.po');
EvilBozkurt commented 4 months ago

Headers are added in the Translations instance.

$translations->getHeaders()->set('key', 'value');

And then you have to pass the translations instance to the Po generator:

$poGenerator = new PoGenerator();

$poGenerator->generateFile($translations, 'locales.po');

Thanks. Thanks to you I can make it work like this.

foreach ($phpScanner->getTranslations() as $domain => $translations) {
    //seems to work, but po file does not seem to have the "language" header
    $translations->setLanguage($domain);

    $dosya_yolu = 'locales/' . $domain . '.po';

    $translations->getHeaders()->set('Last-Translator', 'Mehmet Bozkurt');

    if (file_exists($dosya_yolu)) {
        $mevcut_translations = $loader->loadFile($dosya_yolu);
        $updatedEntries = $translations->mergeWith($mevcut_translations);
        $generator->generateFile($updatedEntries, "locales/$domain.po");
    } else {
        $generator->generateFile($translations, "locales/$domain.po");
    }
}