Symfony 6 (php8) XLIFF plurals now working - symfony

Im working with symfony 6.1.1 + php8.1.7 and have problem with translations (XLIFF)
If translation file without translation all fine but pluralization wont work correctly with translation key in file
Translation call in Twig
{{ "{0}Any item found|{1}One item found|]1,Inf[ Found %count% items" | trans({'%count%': paginated_data.totalItemCount}) }}
Result with deleted translation from .xlf
And result with existing translation in file (In picture you can see, that translator give translation from correct target block)
There is part of xliff file with translation
<trans-unit id="Y9p7sja1" resname="{0}Any item found|{1}One item found|]1,Inf[ Found %count% items">
<source>{0}Any item found|{1}One item found|]1,Inf[ Found %count% items</source>
<target>{0}Any item found1|{1}One item found2|]1,Inf[ Found %count% items3</target>
</trans-unit>
In debug panel all fine and Symfony says that pluralization working

Related

Defining a locale for twig template translations when using `translation:update`

I'm having a bit of trouble with Symfony twig translations, and I hope someone here can clarify.
Say I have a file /templates/general/hello_world.twig , with the contents:
{% trans with {
'%name%': name,
} %}
"Hello %name%"
{% endtrans %}
When I call bin/console translation:update --output-format=yaml fr --force , the output file translations/messages+intl-icu.fr.yaml now contains the contents:
'"Hello %name%"': '__"Hello %name%"'
This is only the case with Twig files - I have other files in translations where they are locale-suffixed, and those are properly translated into french. I'm not clear what has to happen in order to get the translation:update command to recognize that the original content is in English?
I'm not asking how to choose a locale based on the user request. I'm specifically wanting to generate missing translations for contents in my twig templates, and I'd love to have this command available to get me started. The command works a treat for translations actually in the /translations/ folder.
Update 2
// hello.twig
{% trans with {
'%name%': name,
} %}hello_world{% endtrans %}
//messages.en.yaml
hello_world: "Hello %name%"

Is it possible to output message keys in Symfony

I have a Symfony 5 website that uses Twig templates containing messages translated with
{% trans %}some.message.key{% endtrans %}
Is there a way to have Symfony output the message key itself instead of the translation? This can be helpful during development and translation work.
To demonstrate what I want, have a look at https://en.wikipedia.org/wiki/Main_Page?uselang=qqx, which shows such behavior in the MediaWiki software.

Pluralize string in Symfony 3

Are there any ways for pluralizing a string in Symfony 3? For example: I have "Object" and I would like to get "Objects".
pluralization is a very complex topic and Symfony embraces it as part if the Translation Component:
Message pluralization is a tough topic as the rules can be quite complex.
So you basically would need to activate translations for your system and translate the needed strings using the transChoice() method of the translator service or the 'transchoice' tag / filter in your twig template.
To handle this, use the transChoice() method or the transchoice tag/filter in your template.
using the translator service
// the %count% placeholder is assigned to the second argument...
$translator->transChoice(
'There is one apple|There are %count% apples',
10
);
// ...but you can define more placeholders if needed
$translator->transChoice(
'Hurry up %name%! There is one apple left.|There are %count% apples left.',
10,
// no need to include %count% here; Symfony does that for you
array('%name%' => $user->getName())
);
twig tags
{% trans %}Hello %name%{% endtrans %}
{% transchoice count %}
{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples
{% endtranschoice %}
UPDATE
If you do not know the string beforehand you can use the internal Inflector Component, but be aware of the disclaimer and the fact that this would only work for strings in English:
This component is currently marked as internal. Do not use it in your own code. Breaking changes may be introduced in the next minor version of Symfony, or the component itself might even be removed completely.
An alternative would be to create your own inflector class, e.g. something like this and create a service from it.

eZPublish & Twig trans filter : chinese translation

I'm currently working on the translation aspect of an eZPublish5 website which will contain 4 languages : french, english, russian and chinese, with french as original language and locale fallback.
Translation of content in backend is working just fine but I'm struggling with translating template parts, which I have encapsulated in {% trans %} filters. I don't think it's directly related to a locale issue because {% trans %} tags are working with french, english and russian, but not in chinese.
To do so I used
php ezpublish/console translation:update --output-format=xlf locale bundle --force witch generated messages.fr.xlf, messages.en.xlf, and messages.ru.xlf.
When in chinese, if I dump the locale in twig using {{ app.request.locale }} I get zh_TW for result, so I generated a messages.zh_TW.xlf, without any result.
After a loooong web search regarding language codes of all sort, I started losing patience and generated :
messages.chi.xlf
messages.chi-TW.xlf
messages.cn.xlf
messages.zh.xlf
messages.zh-tw.xlf
messages.zh_TW.xlf
to no avail.
This project is my first with eZpublish and I my first multilanguage under the Twig/Symfony logic.
Some code to show language declaration:
//ezpublish/config/ezpublish.yml
ezpublish:
system:
chi:
languages:
- chi-TW
- fre-FR
session:
name: eZSESSID
Any idea what am I doing wrong ?
Soooo.
I found a solution to solve my problem, and I'm quite ashamed to share it here.
-------Huge Revelation !-------
$php app/console cache:clear
The first three language files had been created quite a while ago and cache had been cleared a lot since, so that's why these trans files were working. I cleared the cache and now everything is working just fine.
BTW the answer to my own question was : messages.zh_TW.xlf
Now I'm gonna hide myself for a while.

Get Jekyll collection item name (HRU)

I'm making a Jekyll site destinated for GitHub Pages, and pre-testing it on local Windows 8.1 PC with Jekyll 2.5.3, Ruby 2.0.0p598 (2014-11-13) [x64-mingw32] and Gem 2.0.14.
In Jekyll, I have a collection named albums.
Directory structure for _albums is similar to the following:
_albums
foo.md
bar.md
baz.md
Each file has Front Matter containing values such as title, description etc.
In some site page I'm making a Liquid loop such as following:
{% for album in site.albums %}
/* need to get album name here */
{% endfor %}
The question is:
How can I get a bare name for collection item — like foo or bar (without extension, containing folders etc.)
Jekyll documentation says something about name variable, but album variable only has following properties: output, content, path, relative_path, url, collection (and also title and description I set in Front Matter)
album.path has value similar to: d:/repo/<project_name>/_albums/foo.md
A workaround I use for now is:
{% assign album_name = album.path | split:"/" | last | split:"." | first %}
Could you please suggest any better way?
Thank you in advance.

Resources