8000 Allow to define an empty prefix for translation:update command · Issue #20044 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Allow to define an empty prefix for translation:update command #20044

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

Closed
javiereguiluz opened this issue Sep 24, 2016 · 11 comments
Closed

Allow to define an empty prefix for translation:update command #20044

javiereguiluz opened this issue Sep 24, 2016 · 11 comments

Comments

@javiereguiluz
Copy link
Member
javiereguiluz commented Sep 24, 2016

Context

When using the translation:update command to generate a translation file, the translated strings are just the original strings with the __ prefix (e.g. original Contact us, "translation": __Contact us). This value can be changed with the --prefix option.

Problem

When generating the translation file for the original language, I want to use an empty prefix. It seems impossible to do that because of the way Symfony Console options work:

$ ./bin/console translation:update en --dump-messages
# translation prefix = '__';

$ ./bin/console translation:update en --dump-messages --prefix=""
# translation prefix = '__';   <-- ERROR: I expected here an empty prefix

$ ./bin/console translation:update en --dump-messages --prefix=" "
# translation prefix = ' ';

$ ./bin/console translation:update en --dump-messages --prefix="aaa"
# translation prefix = 'aaa';

I think in the past we had some issues reported for the way console options work, but I can't find the issues. Considering that setting an option with an empty value is the same as not setting that option looks confusing and it could even be considered a bug.

@javiereguiluz javiereguiluz changed the title Allow to define an empty prefix for translation:update command Allow to define an empty prefix for translation:update command Sep 24, 2016
@linaori
Copy link
Contributor
linaori commented Sep 24, 2016

@javiereguiluz are you referring to this one? #19946, it's merged already 👍

@javiereguiluz
Copy link
Member Author

@iltar thanks for the heads up. I totally missed the fix made by the great @chalasr !

Closing it as fixed then.

@lordjancso
Copy link

@javiereguiluz I think it's still not working with empty string. Did you test it?

@chalasr
Copy link
Member
chalasr commented Oct 7, 2016

@lordjancso Empty values for command options should be correctly handled since releases v2.7.19, v2.8.12 and v3.1.5 (they should be resolved as null). Could you elaborate?

@lordjancso
Copy link

@chalasr I'm using 3.1.5 and its still not working. When I execute translation:update with --prefix="" its still not an empty string, because it passes NULL instead of empty string. And as far as I know, NULL is not an empty string.

@chalasr
Copy link
Member
chalasr commented Oct 7, 2016

@lordjancso Yeah, this is the expected behavior (see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Input/ArgvInput.php#L224-L227). The issue is about that the option was not considered to be set at all, throwing an exception if the option requires a value. Now it converts any empty value into null (as it was expected to do before the fix).

If you think it should not be converted (that I can perfectly understand), please open an issue/PR for proposing to change this.

Please note that $argv does not return empty strings, just no value:

// argv.php
<?php
var_dump($argv);
$ php argv.php --prefix=""
# array(2) {
#   [0]=>
#   string(18) "argv.php"
#   [1]=>
#   string(6) "--prefix="
# }

@lordjancso
Copy link

@chalasr I see your point but this issue is about allowing to define empty string prefix for translation:update command and since it's still not working, I suggest to re-open it.

@chalasr
Copy link
Member
chalasr commented Oct 8, 2016

@javiereguiluz @lordjancso See #20184

@chalasr
Copy link
Member
chalasr commented Oct 8, 2016

@javiereguiluz The following example:

$ ./bin/console translation:update en --dump-messages --prefix=""
# $prefix = '__';   <-- ERROR: I expected here an empty prefix

Should be:

$ ./bin/console translation:update en --dump-messages --prefix=""
# $prefix = null;   <-- ERROR: I expected here an empty string

Could you please update the description?

@javiereguiluz
Copy link
Member Author

@chalasr I was referring to the effective prefix used for translations instead of the value of the $prefix variable. But you are right and I've just updated the description to avoid confusion. Thanks!

@chalasr
Copy link
Member
chalasr commented Oct 8, 2016

@javiereguiluz Yeah, sorry I forgot to precise it needs to be updated since #19946 only

fabpot added a commit that referenced this issue Oct 9, 2016
…n translation:update (chalasr)

This PR was merged into the 2.7 branch.

Discussion
----------

[FrameworkBundle] Convert null prefix to an empty string in translation:update

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20044
| License       | MIT
| Doc PR        | n/a

This command needs the ability to use an empty string as prefix, which is not possible using `bin/console translation:update --prefix=""` because `$argv` doesn't parse empty strings thus the value is converted to `null` by `ArgvInput` (only since #19946, before the option was not considered to be set, giving the default `'__'` thus this should be fine from a BC pov).

Here I propose to explicitly convert the `prefix` value to an empty string if set to `null`, as it is a very specific need and we can't guess that from `ArgvInput`.
An other way to fix it could be to add a `--no-prefix` option to the command but I don't think it is worth it, and it couldn't be treated as a bug fix thus not fixed before `3.2`.

Commits
-------

f02b687 [FrameworkBundle] Convert null prefix to an empty string in translation:update command
@fabpot fabpot closed this as completed Oct 9, 2016
@xabbuh xabbuh reopened this Nov 7, 2016
fabpot added a commit that referenced this issue Nov 11, 2016
…date (chalasr)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Add --no-prefix option to translation:update

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20044
| License       | MIT
| Doc PR        | n/a

This adds an option `--no-prefix` to the `translation:update` command, allowing to use an empty string as prefix. I guess it should be treated as a feature as it adds a new option to the command, but it indeed fixes the bug reported in #20044 (yeah, really this time).

Commits
-------

b5a1584 [FrameworkBundle] Add --no-prefix option to translation:update
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this issue Nov 11, 2016
…date (chalasr)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Add --no-prefix option to translation:update

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#20044
| License       | MIT
| Doc PR        | n/a

This adds an option `--no-prefix` to the `translation:update` command, allowing to use an empty string as prefix. I guess it should be treated as a feature as it adds a new option to the command, but it indeed fixes the bug reported in #20044 (yeah, really this time).

Commits
-------

b5a1584 [FrameworkBundle] Add --no-prefix option to translation:update
@fabpot fabpot closed this as completed Nov 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0