php-gettext / Gettext

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

[Question] Any official way to add new gettext functions? #174

Open OwenMelbz opened 6 years ago

OwenMelbz commented 6 years ago

Hi,

We're in the process of translating a prebuilt wordpress site that uses _e to echo translations.

Currently we're using your extractor, by pushing a custom function to the extractor config using

Gettext\Extractors\PhpCode::$options['functions']['_e'] = 'gettext';

Is there an official method/api to do this? Or would this be considered as acceptable?

Thanks

oscarotero commented 6 years ago

Hi. This is the only way in version v3.x In v4 you can pass the options as an argument:

$translations = Translations::fromPhpCodeFile('my-file.php', [
    'functions' => [
        '_e' => 'gettext'
    ]
]);
swissspidy commented 6 years ago

@OwenMelbz You might be also interested in https://github.com/wp-cli/i18n-command and how we did that there.