Plurals and xgettext #3

Closed
versae opened this Issue Jun 9, 2012 · 5 comments

Projects

None yet

4 participants

@versae
versae commented Jun 9, 2012

Hi,

I'm trying to get my messages.po from Javascript files using Jed. I'm using xgettext and this command:

  xgettext --keyword=translate --from-code utf-8 -L Perl `find . -iname "*.js"`

It seems to work fine, but the problem comes when xgettext finds plurals like the next ones:

i18n.translate("Pass through %1$s %2$s").fetch(var1, var2);

Because it doesn't recognizes $ as a valid character. Is there any work around using xgettext, or otherwise, any other way to use a different numbering method xgettext-compatible?

Thanks.

@versae
versae commented Jun 9, 2012

OK, I did the work around changing my strings from:

  i18n.translate("Pass through %1$s %2$s").fetch(var1, var2);

To:

  i18n.translate("Pass through %s %s").fetch(var1, var2);

But maybe, if there were dictionaries support would be a great improvement:

  i18n.translate("Pass through %(number)s %(type)s").fetch({number: "three", type: "houses"});
@Rob--W
Contributor
Rob--W commented Sep 8, 2012

@versae By your comment, it looks like that dictionaries are not supported. This is not the case, dicts are supported. I have annotated the relevant regular expression in the source code, which clearly shows that named groups are supported (see first non-captured group, second case (starting right before # $2:):

\x25                #   %
(?:
(                   # $1:
        [1-9]\d*    #   Any integer
    )
    \$              #   followed by $
|                   # OR
    \(              #   A parenthesis
    (               # $2:
        [^\)]+      #   followed by any non-parenthesis
    )
    \)              #   followed by parenthesis
)?
(                   # $3:
    \+              #   +
)?
(                   # $4:
    0               #   0
|                   # OR
    '[^$]           #   ' followed by any non-$
)?
(                   # $5:
    -               #   -
)?
(                   # $6:
    \d+             #   Any integer
)?
(?:
    \.              #   -
    (               # $7:
        \d+         #   Any integer
    )
)?
(                   # $8:
    [b-fosuxX]      #   One of b c d e f o s u x X
)
@versae
versae commented Sep 8, 2012

Thanks @Rob--W, I will try with named groups and dictionaries then.

@martintajur

Thanks @Rob--W for the answer. Can you provide a few examples of using variables in the syntax, as I have trouble getting strings like this to work properly and replacements made: %(something)s of %(somethingElse)s

@martintajur

I got it working with using the following format: %1$s of %2$s

@SlexAxton SlexAxton closed this Sep 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment