Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Translator] Intl message converter#28486
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| $kernel =$this->getApplication()->getKernel(); | ||
| // Define Root Paths | ||
| $transPaths =$kernel->getProjectDir().'/translations'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
$transPaths = $kernel->getProjectDir().'/translations';
🔽$transPaths = $kernel->getProjectDir().DIRECTORY_SEPARATOR.'translations';
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you
| EOF; | ||
| $standardRules =array(); | ||
| foreach ($partsas$part) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
What if$parts is empty ? I would have add a check not to continue ifempty($parts) is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I dont know.. When will parts be empty?
I adding a small fix.
nicolas-grekas commentedOct 1, 2018
If#28375 goes well, wemight close this one and save us some work. \o/ |
fabpot commentedOct 10, 2018
Why could we close this one? We still need a way to move old messages to the new format, right? |
nicolas-grekas commentedOct 10, 2018
We don'tneed one because we don't plan to deprecate the current format. It could be nice to provide the command if ppl want to move to intl, but there is no real reason to do it so I'm not sure it's worth it. |
fabpot commentedOct 10, 2018
I get that, but I think people will want to migrate to the new format as it is more powerful. |
stof commentedOct 11, 2018
@nicolas-grekas at least for pluralized message, itis deprecated currently (as APIs consuming it are deprecated) |
nicolas-grekas commentedOct 11, 2018
@stof not really, see#28375 (comment) |
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
please rebase and move to short arrays.
fabpot commentedDec 3, 2019
@Nyholm Do you have any plans to finish this one? I think it would be a very nice and useful addition. |
Nyholm commentedDec 3, 2019
Yes, I will make sure to complete this PR. Thank you for the ping |
welcoMattic commentedJul 1, 2020
Nyholm commentedJul 1, 2020
Yes. I will |
fabpot left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Quick review (mostly about style) as a nice ping/reminder :)
| <argumenttype="service"id="translation.writer" /> | ||
| <argumenttype="service"id="translation.reader" /> | ||
| <tagname="console.command"command="translation:convert-to-intl-messages" /> | ||
| </service> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should be moved to the new PHP config file.
| protectedfunctionconfigure() | ||
| { | ||
| $this | ||
| ->setDescription('Convert from Symfony 3 plural format to ICU message format.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would remove 3 here.
| ; | ||
| } | ||
| protectedfunctionexecute(InputInterface$input,OutputInterface$output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
: int
| } | ||
| } | ||
| $this->writer->write(newMessageCatalogue($locale,$updated),$input->getOption('output-format'),array('path' =>$transPaths)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
return 0;
| } | ||
| /** | ||
| * Get an ICU like array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Gets
| namespaceSymfony\Component\Translation\Util; | ||
| /** | ||
| * Convert from Symfony 3's plural syntax to Intl message format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would remove the reference to 3 here as well.
| publicstaticfunctionconvert(string$message,string$variableDelimiter ='%'):string | ||
| { | ||
| $array =self::getMessageArray($message); | ||
| if (empty($array)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We try to avoid usingempty in Symfony.if (!$array) seems enough here.
| returnself::replaceVariables($message,$variableDelimiter); | ||
| } | ||
| $icu =self::buildIcuString($array,$variableDelimiter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
temp var could be removed
| privatestaticfunctionreplaceVariables(string$message,string$variableDelimiter):string | ||
| { | ||
| $regex =sprintf('|%s(.*?)%s|s',$variableDelimiter,$variableDelimiter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would inline the regexp
nicolas-grekas commentedSep 7, 2020
I'm closing here because this staled and apparently this is not critical, since this gathered very little feedback from the community. Let's reopen when someone actually needs this (I'd invite that person to adopt the patch here to make the new PR). |
Uh oh!
There was an error while loading.Please reload this page.
As discussed in#28375, we need a command to convert from "Symfony 3" plural format to Intl message format.
Before
{{'simple_key|trans({"%name%": "foo"}) }} <br>{{'plural_key|transchoice(2, {"%name%":"foo"}) }}After
{{'simple_key'|trans({"name":"foo"}) }} <br>{{'plural_key'|trans({"COUNT":2,"name":"foo"}) }}As you can see, the user needs to modify their twig templates, "
%name%" => "name". To use "{%name%}" in the translation message is not valid syntax.TODO
I need to add more tests of plural messages. Feel free to add a comment with a "Symfony style" plural string and I'll add it to the tests.
We also need a way to modify the the
%name%placeholder. Users may use#name#or any other arbitrary string.