Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extractors\PhpCode does not extract d__() and other domain-related gettext functions #108

Closed
marcandrews opened this issue Apr 27, 2016 · 7 comments

Comments

@marcandrews
Copy link

Extractors\PhpCode does not appear to be able to extract d__() and other domain-related gettext functions.

@oscarotero
Copy link
Member

Yes, you're right. This is something that I have in the roadmap but I couldn't find any time yet to implement.
I will add this to 3.6 version

@marcandrews
Copy link
Author

Thanks!

oscarotero added a commit that referenced this issue Apr 27, 2016
@marcandrews
Copy link
Author

First off, thanks for the update.

Am I doing this right? I wish to load two domains and then use Extractors\PhpCode to extract code from domain-related gettext function

require_once 'CldrToGettext/src/autoloader.php';
require_once 'Gettext/src/autoloader.php';

use Gettext\GettextTranslator;

$t = new GettextTranslator();
$t->setLanguage($lang);
$t->loadDomain('common', 'path/to/common/domain/Locale');
$t->loadDomain('local', 'path/to/local/domain/Locale', false);

$t->register();

$extraction = Gettext\Extractors\PhpCode::fromFile('path/file.php');

When I run Extractors\PhpCode, __(), __e() get extracted, but d__('local', 'original') or d__e('local', 'original') are still missed.

Seems like the class is failing here. Does Extractors\PhpCode not support multiple domains?

I even tried loading just one domain and it still does not work. Is there something else I'm missing?

@marcandrews
Copy link
Author

Yes, if I comment out && $domain === $translations->getDomain() from here, it works. Is there a reason you're checking the domain?

@oscarotero
Copy link
Member

The Translations instance contains only one domain. So you have to define which domain you want to get before extract the code. Example:

use Gettext\Translations;

//Create a empty Translations
$translations = new Translations();

//Set the domain
$translations->setDomain('local');

//Extract the entries of this domain:
$translations->addFromPhpCodeFile('path/file.php');

//Save the file
$translations->toMoFile('path/to/local/domain/Locale/en/LC_MESSAGES/messages.mo');

@oscarotero
Copy link
Member

The reason of $domain === $translations->getDomain() is to do not mix entries of different domains.

@marcandrews
Copy link
Author

Thanks! Got it working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants