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] Dump translation constants as tree instead of simple list#14434

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
gepo wants to merge1 commit intosymfony:2.7fromgepo:yaml_tree_dumper

Conversation

@gepo
Copy link
Contributor

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

Dump translations constants as tree based on '.' character as a delimeter in path.

YamlFileDumper converts constants like these:

'foo.bar1' => 'test1','foo.bar2' => 'test2'

to next .yml file:

foo.bar1: 'test1'foo.bar2: 'test2'

This PR convert the same input to this:

foo:    bar1: 'test1'    bar2: 'test2'

Which is more useful if you use translation import/export tools while storing translations in YAML files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

methods should be protected (there is no reason to make them extension points yet)

@stof
Copy link
Member

I think this should be configurable through an option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should be:

$elem[$part] =array();

@aitboudad
Copy link
Contributor

This look nice addition, what do you think to move this feature into `yaml dumper' ?

@jakzal
Copy link
Contributor

@aitboudad I wouldn't add this feature to the yaml component as it's not part of the yaml standard.

@gepo
Copy link
ContributorAuthor

I think this should be configurable through an option

ok, sure, did it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is not how it should work. It should rely on options passed to the dump method (see the interface)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

FileDumper doesn't pass this options to format, so their several ways to do it:

  1. Override dump() function, save options internally and reset them after format() call
  2. Change FileDumper - add optional third parameter to format function and pass it in dump() function.
  3. Copy-paste&edit dump function from FileDumper to YamlFileDumper (bad, very bad).
  4. or leave it as setter function because if we need it dumping as tree we probably need it in whole application, not just in one case.

I think, way 2. is most suitable, but I'm not sure that it's not BC-break. Is this way ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd prefer2. it's not a BC break but it must be documented in the UPGRADE file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

protectedfunction format(MessageCatalogue$messages,$domain,$options =array());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

with a typehint on the options argument

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the BC break is fine by looking at implementations of this outside Symfony:http://packanalyst.com/class?q=Symfony\Component\Translation\Dumper\FileDumper

Drupal and Prezent are extending the YamlFileDumper to implement this feature, meaning their upgrade path will be easy: switch to the core one.

And then, we could even submit PRs ourselves to Sulu and Kdyby to update their implementations

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I certantly can't just add third option to format() in FileDumper without BC break. With introducing two new abstract classes I gain full BC, check it pls. Also, I'm not sure about new class names...

todo:

  1. cleanup tests
  2. write doc block
  3. update UPGRADE file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The new abstract class makes the component more complex without any real benefit IMO.

And if you want to make the tree logic reusable, the right way would be to put it in its own class used as a collaborator of the dumper instead of using an abstract parent class. It would be much more reusable (and easier to test as you could test the tree logic on its own btw)

@gepo
Copy link
ContributorAuthor

Also add this behavior to json and php dumpers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

if (isset($options['as_tree'])) {}

@gepo
Copy link
ContributorAuthor

squash all commits into one to easy review.

move expandToTree to separate class and use it only in YamlFileDumper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you should updateCHANGELOG of Translation and the target should be2.8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This function is already documented inFileDumper, so useinheritdoc

/** * {@inheritdoc}*/

@gepogepoforce-pushed theyaml_tree_dumper branch 3 times, most recently fromab97816 tof9a6412CompareApril 27, 2015 09:11
@aitboudad
Copy link
Contributor

👍, ping @symfony/deciders

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

array should bestring[]

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 above the YAML componentuse statement.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It was fixed

@xabbuh
Copy link
Member

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this could be simplified:

$inline =isset($options['inline']) &&$options['inline'] >0;return Yaml::dump($data,$inline);

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yaml:dump second parameter is integer with default value 2 - "The level where you switch to inline YAML".

So, it can't be simplified neither like this nor

Yaml::dump($data,isset($options['inline']) ? (int)$options['inline'] :2);

because default value for argument can be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

oops. sorry :) argument name is misleading.

@aitboudad
Copy link
Contributor

I got some conflicts when I attempt to merge into2.8,@gepo would you mind to fix the conflicts and open new PR for 2.8 branch to make it easy for me :) ?

@jakzal
Copy link
Contributor

@aitboudad@gepo a rebase would probably work just fine, no need for a new PR. You'll then be able to switch the target branch while merging.

@stof
Copy link
Member

@jakzal no we can't. After the rebase, the PR would include all 2.8 commits in the diff too, which means that it will totally mess the merging with GH.
The branch switching works fine when we rebase during the switching branch, not when the rebase is done previously without changing the target branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this is not a BC layer, given that it is the one child class should implement now.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

change it to

* Override this function in child class if $options is used for message formatting.

it it more correct?

@jakzal
Copy link
Contributor

@stof I didn't mean rebasing to 2.8. It needs rebasing to 2.7. Can be
merged to 2.8.
On Wed, 13 May 2015 at 18:35, Christophe Coevoetnotifications@github.com
wrote:

@jakzalhttps://github.com/jakzal no we can't. After the rebase, the PR
would include all 2.8 commits in the diff too, which means that it will
totally mess the merging with GH.
The branch switching works fine when we rebase during the switching
branch, not when the rebase is done previously without changing the target
branch.


Reply to this email directly or view it on GitHub
#14434 (comment).

…mp messages as tree instead of simple list.Dump messages as tree based on '.' character as a delimeter in path.For example this rray('foo.bar' => 'value') will be converted to array('foo' => array('bar' => 'value')).Correctly process cases like this ['foo.bar' => 'test1', 'foo' => 'test2'].
@gepo
Copy link
ContributorAuthor

create#14630 for 2.8 branch

@aitboudad
Copy link
Contributor

@jakzal it work only if there is not conflict.

@aitboudad
Copy link
Contributor

closed in favor of#14630.

aitboudad added a commit that referenced this pull requestMay 20, 2015
…d of simple list (gepo)This PR was merged into the 2.8 branch.Discussion----------[Translator] Dump translation constants as tree instead of simple list| Q             | A| ------------- | ---| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | no| Fixed tickets || License       | MIT| Doc PR        |PR#14434 for 2.8 branchCommits-------29ec5ca [Translation] add options 'as_tree', 'inline' to YamlFileDumper to dump messages as tree instead of simple list.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@gepo@stof@aitboudad@jakzal@xabbuh@stloyd

[8]ページ先頭

©2009-2025 Movatter.jp