Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
Nyholm wants to merge7 commits intosymfony:masterfromNyholm:icu-converter

Conversation

@Nyholm
Copy link
Member

@NyholmNyholm commentedSep 17, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

As discussed in#28375, we need a command to convert from "Symfony 3" plural format to Intl message format.

Before

<trans-unitid="xx0"resname="simple_key">  <source>simple_key</source>  <target>Hello %name%</target></trans-unit><trans-unitid="xx1"resname="plural_key">  <source>plural_key</source>  <target>{0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf] %name%, there are %count% apples</target></trans-unit>
{{'simple_key|trans({"%name%": "foo"}) }} <br>{{'plural_key|transchoice(2, {"%name%":"foo"}) }}

After

<trans-unitid="xx0"resname="simple_key">  <source>simple_key</source>  <target>Hello {name}</target></trans-unit><trans-unitid="xx1"resname="plural_key">  <source>plural_key</source>  <target>{ COUNT, plural,    =0 {{name}, there are no apples}    =1 {{name}, there is one apple}    other {{name}, there are # apples}}</target>
{{'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.

ro0NL, jvasseur, sstok, yceruto, and welcoMattic reacted with heart emoji
$kernel =$this->getApplication()->getKernel();

// Define Root Paths
$transPaths =$kernel->getProjectDir().'/translations';

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 ?

Copy link
MemberAuthor

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) {

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

Copy link
MemberAuthor

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.

BenjaminRbt reacted with thumbs up emoji
@NyholmNyholm changed the title[Translator] WIP: Intl message converter[Translator] WIP: Icu message converterSep 22, 2018
@NyholmNyholm changed the title[Translator] WIP: Icu message converter[Translator] Icu message converterSep 22, 2018
@NyholmNyholm changed the title[Translator] Icu message converter[Translator] Intl message converterSep 22, 2018
@nicolas-grekas
Copy link
Member

If#28375 goes well, wemight close this one and save us some work. \o/

@fabpot
Copy link
Member

Why could we close this one? We still need a way to move old messages to the new format, right?

jvasseur and sstok reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

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.

sstok reacted with eyes emoji

@fabpot
Copy link
Member

I get that, but I think people will want to migrate to the new format as it is more powerful.

sstok reacted with thumbs up emoji

@stof
Copy link
Member

@nicolas-grekas at least for pluralized message, itis deprecated currently (as APIs consuming it are deprecated)

@nicolas-grekas
Copy link
Member

@stof not really, see#28375 (comment)

Copy link
Member

@nicolas-grekasnicolas-grekas left a 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.

Nyholm reacted with thumbs up emoji
@fabpot
Copy link
Member

@Nyholm Do you have any plans to finish this one? I think it would be a very nice and useful addition.

welcoMattic reacted with thumbs up emoji

@Nyholm
Copy link
MemberAuthor

Yes, I will make sure to complete this PR.

Thank you for the ping

@welcoMattic
Copy link
Member

This PR could be very useful alongside#37462 to automate intl conversion of messages stored in a translation SaaS.
@Nyholm do you plan to finish it before 5.2 release (which is the release we target for#37462)?

@Nyholm
Copy link
MemberAuthor

Yes. I will

welcoMattic reacted with heart emoji

Copy link
Member

@fabpotfabpot left a 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>
Copy link
Member

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.')
Copy link
Member

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)
Copy link
Member

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));
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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)) {
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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).

@nicolas-grekasnicolas-grekas modified the milestones:next,5.2Oct 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot requested changes

+1 more reviewer

@BenjaminRbtBenjaminRbtBenjaminRbt left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.2

Development

Successfully merging this pull request may close these issues.

8 participants

@Nyholm@nicolas-grekas@fabpot@stof@welcoMattic@BenjaminRbt@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp