-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Symfony translator shows curly braces around vars #39854
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
Comments
After some digging I have found a few suspicious points. 1. File namesHaving 2. Translator::trans()
As I understand, it selects between ICU format and "normal". For our example it should choose the 3. MessageCatalogue
It seems that if you pass normal, non-ICU domain, it checks for both normal and ICU messages. But if you pass ICU domain, it can check only ICU messages. I find this asymmetry confusing and bug-like. 4. Translator::addResource()It's domain actually depends not on filename passed as 2nd argument, but on 4th argument. If, for my example project, we change this line
to this
everything starts work as expected:
Final thoughtsSomething doesn't wire together. I'm not able to wrap my head around Symfony architecture, as I always find it overengineered, and indeed it's quite complex and hard to understand. So I cannot propose super useful ideas here. The authors can invent solutions and fixes the best. I suppose "convention over configuration" thingie should be removed in favor of clear "configuration". At least with this line of code
|
hm, see #37371 that seems to be a bugfix for 5.x only 🤔 can you try v5 of the translator component? i believe it'll then work, as the formatter will also handle the
|
As you discovered, the If you don't add the In 5.0, the old formatter is removed and intl is the only supported format. That resolves all inconsistencies. I think it makes sense to deprecate the I'm going to close this issue, as I don't think there is anything to do here. However, if you think I'm wrong please leave a comment and we can always reopen. Thanks for understanding! @ro0NL #37371 is unrelated afaics. That PR was about passing intl format strings to |
@wouterj yes you're right, i confused addResource() with trans() im tempted if we can infer the icu modifier from the resource, applying the domain suffix as needed. AFAIK we cant just deprecate this +intl-icu modifier, given translator component may need to support both type of formats |
If I remember correctly, intl is the only supported format in Symfony 5+. |
Hey, thanks for the elaborations! But I still don't understand completely.
https://symfony.com/doc/current/translation/message_format.html Whenever, as pointed there, I write
I get composer.json with content
I had no idea that Looking at https://github.com/symfony/translation/releases I now see that they actually do exist. Should the symfony/translation github page be updated also? As for me, poorly familiar with Symfony, it was quite confusing. Indeed, I don't need any backward compatibility, I would be happy to stick with ICU format only. But, I read the github page, installed the package as directed, got version I guess I may reopen this issue and now ask the docs to be updated by someone? |
the issue is https://symfony.com/doc/current/translation.html relies on framework integration, eg. translator as a service - ready to use out-of-the box Setting up the translator standalone is still briefly documented at the component level: https://github.com/symfony/translation/blob/5.x/README.md It could use a mention how to enable intl icu formatter i agree. btw, for me composer installs latest stable :)
|
Uh, seems version Then, finally we have only the problem https://symfony.com/doc/current/translation/message_format.html , pointing out about availability of both "normal" and ICU formats, right? |
I'll take care of investigating this (and either reporting back here or fixing the doc). Thanks a lot for your time and detailed information! |
see also https://symfony.com/doc/current/translation/templates.html ;) AFAIK only |
OK, I updated my PHP to version 8, updated packages as well - composer pulled out Welp, barely any improvements. https://github.com/symfony/translation/blob/5.x/README.md
^ this needs to be added for the example to work. https://github.com/symfony/translation/blob/5.x/Translator.php
They look more complex than of 4.4 though. And finally
still doesn't work as expected, producing an output with curly braces. It still requires
^ this thing surely works. |
Ah, yes. Both formats are still supported - the non-intl format is only handling the simple placeholder replacements. In that case, the
Can you make a PR to the 4.4 branch fixing this in https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Translation/README.md ? |
For the example to work it needs the line with $translator->addLoader(). Fixed it for request at symfony#39854 (comment)
…ample (Ser5) This PR was merged into the 4.4 branch. Discussion ---------- [Translator] Added $translator->addLoader() to README example For the example to work it needs the line with $translator->addLoader(). Fixed it for request at #39854 (comment) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. --> Commits ------- ba29d2a Added $translator->addLoader()
For the example to work it needs the line with $translator->addLoader(). Fixed it for request at symfony/symfony#39854 (comment)
For the example to work it needs the line with $translator->addLoader(). Fixed it for request at symfony/symfony#39854 (comment)
Symfony version(s) affected: 4.4.18
Description
See there for the reproduction project:
https://github.com/Ser5/SymfonyTranslatorBug
I want to use the Symfony validators library in standalone mode. Therefore, AFAIK, I should also use the translator library, but during experiments with it I found that it doesn't work as I expected.
According to these docs
https://symfony.com/doc/current/components/form.html
I installed
symfony/config
andsymfony/translation
packages via Composer.According to these
https://symfony.com/doc/current/translation/message_format.html
created messages file and
index.php
file.Then ran
index.php
.expected:
got:
How to reproduce
Possible Solution
May be one of these problems:
Additional context
Windows 10
PHP 7.2.4
The text was updated successfully, but these errors were encountered: