Skip to content

[Translation] not including fallback locales in cache meta files #20420

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

Closed
msheakoski opened this issue Nov 5, 2016 · 1 comment
Closed

[Translation] not including fallback locales in cache meta files #20420

msheakoski opened this issue Nov 5, 2016 · 1 comment

Comments

@msheakoski
Copy link

msheakoski commented Nov 5, 2016

When using the Translation component in debug mode, I noticed that the .meta files being generated do not include references to fallback locale files, even though the actual cache file contains messages from the fallback locales. This is an issue because any changes made to one of the fallback locale files will not take effect unless the cache is deleted.

Interestingly, in the example, when instantiating the translator with the locale of "fr" instead of "fr_FR", the .meta file correctly contains references to the main locale and fallback locales.

example.php:

<?php declare(strict_types = 1);

use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\PhpFileLoader;

// require symfony/translation and symfony/config in composer.json
require "vendor/autoload.php";

$path = pathinfo(__FILE__);
$frResourceFile = "{$path["filename"]}.trans.fr.php";
$enResourceFile = "{$path["filename"]}.trans.en.php";

file_put_contents($frResourceFile, '<?php return ["greeting" => "Salut!"];');
file_put_contents($enResourceFile, '<?php return ["greeting" => "Hello!"];');

$trans = new Translator("fr_FR", null, ".", true);
$trans->setFallbackLocales(["en"]);
$trans->addLoader("php", new PhpFileLoader());
$trans->addResource("php", $frResourceFile, "fr");
$trans->addResource("php", $enResourceFile, "en");

echo $trans->trans("greeting");

Expected catalogue.fr.xxxxx.php.meta to contain:

a:2:{i:0;C:46:"Symfony\Component\Config\Resource\FileResource":76:{s:68:
"/path/to/example.trans.fr.php"
;}i:1;C:46:"Symfony\Component\Config\Resource\FileResource":76:{s:68:
"/path/to/example.trans.en.php";}}

But instead received:

a:1:{i:0;C:46:"Symfony\Component\Config\Resource\FileResource":76:{s:68:
"/path/to/example.trans.fr.php";}}

As a temporary workaround for anyone else having this issue, you can pass null to the third parameter while developing and it won't create cache files, avoiding the issue:

$debug = (getenv("DEBUG_MODE") === "true");
$cacheDir = $debug ? null : "/path/to/cache";
$trans = new Translator("fr_FR", null, $cacheDir, $debug);
@msheakoski msheakoski changed the title Translation component not including fallback locales in cache meta files [Translation] not including fallback locales in cache meta files Nov 6, 2016
@aitboudad
Copy link
Contributor

see #20422

fabpot added a commit that referenced this issue Nov 6, 2016
…talogues. (aitboudad)

This PR was merged into the 2.7 branch.

Discussion
----------

[Translation][fallback] add missing resources in parent catalogues.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20420
| License       | MIT
| Doc PR        | ~

Commits
-------

27c91e5 [Translation][fallback] add missing resources in parent catalogues.
@fabpot fabpot closed this as completed Nov 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants