Coder Social home page Coder Social logo

zero-other combination bug about go-i18n HOT 2 CLOSED

nicksnyder avatar nicksnyder commented on July 30, 2024 1
zero-other combination bug

from go-i18n.

Comments (2)

toby3d avatar toby3d commented on July 30, 2024 1

It's funny that in compiled .untranslated.json files I also get completely different results:

// en-us.untranslated.json
[
    {
        "id": "sample_test",
        "translation": {
            "one": "{{.Type}} by {{.Owner}}",
            "other": "{{.Type}} by {{.Owner}}"
        }
    }
]
// ru-ru.untranslated.json
[
    {
        "id": "sample_test",
        "translation": {
            "few": "{{.Type}} by {{.Owner}}",
            "many": "{{.Type}} by {{.Owner}}",
            "one": "{{.Type}} by {{.Owner}}",
            "other": "{{.Type}} ΠΎΡ‚ {{.Owner}}"
        }
    }
]

from go-i18n.

nicksnyder avatar nicksnyder commented on July 30, 2024

There are a couple things you need to understand about pluralization in languages.

1) zero != 0

You can't assume that plural categories like zero, one, two map to specific numbers like 0, 1, 2. In some languages the "two" category might be used for any number that ends in the number 2 (e.g. 2, 12, 22, etc.).

If you want to have special logic for specific numbers like 0, 1, 2, then you need to write code and have different translations for each of these cases.

// gross pseudocode
if x == 0 {
    t("no_apples")
} else {
    t("some_apples", x)
}

2) Plural categories depend on the language

English has two plural categories: one ("I have 1 apple") and other ("I have 0 apples", "I have 2 apples", etc.). There is no zero category in English because the pluralization for zero is not special.

Russian has four categories: few, many, one, other (and does not have a zero category). You need to provide a translation for all of the four categories unless you are ok with saying the equivalent of "I have 1 apples".

The goi18n tool understands which pluralizations belong to which languages, so it will drop useless pluralizations (e.g. zero in English, and zero in Russian) and add pluralizations that you need to translate (e.g. few, many, one, other in Russian).

The .untranslated.json file is what you send to translators to translate so it include all keys with either the known translation or the source English translation. Since Russian has a few category and English does not, it defaults to copying over the other source string from English. It is up to the translator to decide what translation make sense.

I hope this clarifies some things for you. From what I can tell, all of the behavior that you have observed is expected.

from go-i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.