Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Plurals and xgettext #3

Closed
versae opened this Issue · 5 comments

4 participants

Javier de la Rosa Rob Wu Martin Tajur Alex Sexton
Javier de la Rosa

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.

Javier de la Rosa

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 Wu

@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
)
Javier de la Rosa

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

Martin Tajur

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

Martin Tajur

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

Alex Sexton SlexAxton closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.