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

Handle pluralization better #14

Open
Nevon opened this issue Feb 2, 2016 · 0 comments
Open

Handle pluralization better #14

Nevon opened this issue Feb 2, 2016 · 0 comments

Comments

@Nevon
Copy link

Nevon commented Feb 2, 2016

If you take a look at the standard gettext method calls, you have more than one key in one method call, in the case of pluralization. For example:

i18n.ngettext('apple', 'apples', num)

gettext-loader would only pick up on 'apple'.

Even if we add %d to the strings, it will still only care about the first argument, so while I would like to get an entry like:

msgid "%d apple"
msgid_plural "%d apples"
msgstr[0] ""
msgstr[1] ""

I will just get:

msgid "%d apple"
msgstr[0] ""
msgstr[1] ""

I'm not sure how to work around this, but it seems to me that it would be a decent start to differentiate between function calls for singular translation and pluralized translations, and in the case of pluralized translations calls, record both the first and the second argument.

Something like this:

exports default {
  gettext: key => {
    // ... translate
  },
  gettextn: (singular, plural, num) => {
    // ... translate
  }
}

With this config:

export default {
  methods: {
    singular: ['gettext'],
    plural: ['gettextn']
  }
}
import {gettext, gettextn} from 'i18n'

gettext('Foo bar')

gettextn('One child', '%d children', 3)

Would result in:

msgid "Foo bar"
msgstr ""

msgid "A child"
msgid_plural "%d children"
msgstr[0] ""
msgstr[1] ""
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

1 participant