Skip to content
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

Translator chokes on numerical IDs #83

Closed
georgms opened this issue Nov 21, 2012 · 7 comments
Closed

Translator chokes on numerical IDs #83

georgms opened this issue Nov 21, 2012 · 7 comments

Comments

@georgms
Copy link

georgms commented Nov 21, 2012

The translator / extractor chokes on numerical IDs. The steps to replicate this are quite simple:

  1. Have a file that has a numerical translation key, ie. in a Twig template: {{ 1 | trans }}

  2. Run the translation:extract command with --output-format=yml

  3. In the messages file a new line like 1: '1' # FIXME will be added

  4. ...everything fine so far

  5. Now run the extraction again, and this time the command will throw an exception:

    [JMS\TranslationBundle\Exception\RuntimeException]
    You can only merge messages with the same id. Expected id "1", but got "1".

While translating numbers seems quite silly, the problem is that the whole extraction process goes awry.

The issue is caused by this part in Model/Message.php:

public function mergeExisting(Message $message)
{
    if ($this->id !== $message->getId()) {
        throw new RuntimeException(sprintf('You can only merge messages with the same id. Expected id "%s", but got "%s".', $this->id, $message->getId()));
    }
    ....

The extracted message's ID ($this->id) is a String, while the existing message's ID ($message->getId()) is an int. Now, the obvious fix would be just use != to compare, but this may very well have other implications.

@nurikabe
Copy link
Contributor

Just ran afoul of this.

@jirikrepl
Copy link

happend to me when I was translating true (evaluated to 1) of some variable (not string). I am using my twig variable extractor. Code in below caused this error.

views/Others/deathCalc.html.twig/jms:reference-file 1 1

@Nyholm
Copy link
Collaborator

Nyholm commented Mar 24, 2016

Thank you for reporting this. This issue is very old, do you have the same problem with the latest release?

@georgms
Copy link
Author

georgms commented Mar 26, 2016

Unfortunately we are still running an old version so I have no easy way of reproducing this. Sorry!

@Nyholm
Copy link
Collaborator

Nyholm commented Mar 26, 2016

Okey.
Im about to close this issue. If you are able to reproduce this feel free to open the issue again.

@Nyholm Nyholm closed this as completed Mar 26, 2016
@elernonelma
Copy link

elernonelma commented Jun 28, 2016

I reproduced it, even with the newest version. The strange thing is that "/** Ignore */" tag has no effect on it. I "fixed" the problem by adding quotes to the integer value.

@Nyholm
Copy link
Collaborator

Nyholm commented Aug 4, 2016

Fixed by #384

@Nyholm Nyholm closed this as completed Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants