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

Call to a member function insert() on boolean #228

Closed
mihaikelemen opened this issue Oct 9, 2019 · 7 comments
Closed

Call to a member function insert() on boolean #228

mihaikelemen opened this issue Oct 9, 2019 · 7 comments

Comments

@mihaikelemen
Copy link

Scanning PHP code fails on v4.7 for the this type of translation __("Foo %s", "bar")

This is working on v4.6.3

PHP Fatal error:  Uncaught Error: Call to a member function insert() on boolean in /vendor/gettext/gettext/src/Utils/FunctionsScanner.php:77
Stack trace:
#0 /vendor/gettext/gettext/src/Extractors/PhpCode.php(68): Gettext\Utils\FunctionsScanner->saveGettextFunctions(Array, Array)
#1 /vendor/gettext/gettext/src/Extractors/PhpCode.php(51): Gettext\Extractors\PhpCode::fromStringMultiple('<?php\nnamespace...', Array, Array)
#2 /vendor/gettext/gettext/src/Extractors/Extractor.php(18): Gettext\Extractors\PhpCode::fromString('<?php\nnamespace...', Object(Gettext\Translations), Array)
#3 [internal function]: Gettext\Extractors\Extractor::fromFile('/file_path/en_US/messages...', Object(Gettext\Translations), Array)
#4 /vendor/gettext/gettext/src/Translations.php(174): call_user_func('Gettext\\Extract...', '/file_path/en_US/messages...', Object(Gettext\Translations), Array)
#5 file_path: Gettext\Translations->__call( in /vendor/gettext/gettext/src/Utils/FunctionsScanner.php on line 77

@oscarotero
Copy link
Member

Ok, I guess this is a bug introduced in #223
@briedis could you please fix this? I don't have free time these days.

@briedis
Copy link
Contributor

briedis commented Oct 11, 2019

I'll check it out

@briedis
Copy link
Contributor

briedis commented Oct 16, 2019

@mihaikelemen Could you provide more info?

  1. Can you give me a code example that is failing?
  2. What is the __ function, why does it have two arguments in your example? Is that a domain, context method?
  3. Can you show the function configuration - which function is considered which?

By default, __ should have only one argument:
image

@mihaikelemen
Copy link
Author

Hi @briedis ,

Sorry for the late response. I'm using this approach with the second argument for quite a while, based on the docs (see bellow). It is a handful approach.

Selecție_20191018

Mihai

@mihaikelemen
Copy link
Author

This the actual code (part of it) that generates the po file for a given locale (in this case ro_RO)

$files->files()
->name('/(.*)\.(tpl|php)/')
->depth('>=1')
->in($dirs);

$translations = new Translations();
$translations->setLanguage('ro_RO');
$translations->setDomain('messages');

# locale directory path
$dir = sprintf('%s%s/', $config->get('environment.locales'), 'ro_RO');
$potfile = sprintf('%s%s.po', $dir, $translations->getDomain());

if (!$filesystem->exists($dir)) {
    $filesystem->mkdir($dir, 0755);
    $filesystem->touch($potfile);
}

foreach ($files as $file) {
    $translations->addFromPhpCodeFile($file->getPathname());
}

if ($filesystem->exists($potfile)) {
    $translations->mergeWith(Translations::fromPoFile($potfile));
}

$translations->toPoFile($potfile);

@briedis
Copy link
Contributor

briedis commented Nov 14, 2019

Sorry @mihaikelemen for the delay, but I managed to run into this issue on my own too. A PR is created for the v4 branch. Actually the code to reproduce the issue was much simpler - just scan a file for one domain, but the file contains a single pgettext call without any strings from the domain you are searching for.

@mihaikelemen
Copy link
Author

Hi @briedis ,
Thanks for your response. For now I'm using 4.6.3 until otherwise; eventually I will upgrade my code to run with the newer v5 branch.

Mihai

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

3 participants