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

Should untranslated file be using "other" value for pluralized strings? #47

Closed
jcbwlkr opened this issue Jan 29, 2016 · 2 comments
Closed

Comments

@jcbwlkr
Copy link

jcbwlkr commented Jan 29, 2016

This is more of a question than a bug report. Given that I am starting a new project which I will want to serve in English and German let's say I start with this file

~/i18n ᐳ cat en-US.all.json 
[
  {
    "id": "point_count",
    "translation": {
      "one": "Only {{ .Count }} Point...",
      "other": "{{ .Count }} Points!"
    }
  }
]

When I generate the untranslated file I get this

~/i18n ᐳ goi18n *all.json
~/i18n ᐳ cat de-de.untranslated.json 
[
  {
    "id": "point_count",
    "translation": {
      "one": "{{ .Count }} Points!",
      "other": "{{ .Count }} Points!"
    }
  }
]

If I send that to be translated they won't know how English handles the one case to generate an appropriate German translation. This seems to be expected by the test files under goi18n/testdata/expected/ but it was unexpected to me. Is this intended?

Thanks!

@nicksnyder
Copy link
Owner

Good question @jcbwlkr; this is intentional.

You are assuming that the "one" category corresponds to the number "1" in all languages; it doesn't. For example, the "one" category in Belarusian corresponds to most numbers that end in the digit "1". You probably don't intend to have the sentence "Only 100001 Points!" in Belarusian.

The same is true for all the other categories: "zero" doesn't necessarily mean "0" and "two" doesn't necessarily mean "2".

If you want to use different variations of a sentence for specific numbers, you can't rely on plural categories so you need to put this logic in code. Each translation should represent a single formation of a sentence.

switch points {
case 0:
  T("zeroPoints") // "No points!"
case 1:
  T("onePoint") // "Only 1 point..."
default:
  T("manyPoints", points) // "{{ .Count }} Points!"
}

Make sense?

@jcbwlkr
Copy link
Author

jcbwlkr commented Feb 1, 2016

@nicksnyder makes sense. Thanks for clearing that up.

@jcbwlkr jcbwlkr closed this as completed Feb 1, 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

2 participants