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

x/text: gotext with french numbers above 1,000,000 #27052

Open
clamb opened this issue Aug 17, 2018 · 1 comment
Open

x/text: gotext with french numbers above 1,000,000 #27052

clamb opened this issue Aug 17, 2018 · 1 comment

Comments

@clamb
Copy link

@clamb clamb commented Aug 17, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10.3 darwin/amd64

Does this issue reproduce with the latest release?

YES

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/Users/christophe/go/bin"
GOCACHE="/Users/christophe/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/christophe/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/85/01ftf7594x1_01_ps0ypv76h0000gn/T/go-build291898772=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

In french, when expressing quantities, you have to distinguish between less than 1,000,000 and more. For example, one have to say:

  • For numbers from 2 up to and including 999'999, we have to say/write:

Il y a 999'999 habitants.
Il y a 999'999 chiens.

  • And for numbers from 1'000'000 and up, we have to say/write:

Il y a 1'000'000 d'habitants.
Il y a 1'000'000 de chiens.

With the following program:

package main

//go:generate gotext -srclang=en update -out=catalog/catalog.go -lang=fr,en

import (
	"fmt"

	_ "github.com/clamb/arcaciel/aws/scrapbook/catalog"

	"golang.org/x/text/language"
	"golang.org/x/text/message"
)

func main() {
	tr := message.NewPrinter(language.French)

	num := 999999
	tr.Printf("There are %d dog(s)", num)
	fmt.Println()
	num = 1000000
	tr.Printf("There are %d dog(s)", num)
	fmt.Println()
	num = 1000001
	tr.Printf("There are %d dog(s)", num)
	fmt.Println()
}

I tried using many (not sure how exactly about how to write this, but this is not the point):

 {
            "id": "There are {Num} dog(s)",
            "message": "There are {Num} dog(s)",
            "translation": {
                "select": {
                    "feature": "plural",
                    "arg": "Num",
                    "cases": {
                        "=0": "Il n'y a pas de chien",
                        "one": "Il y a {Num} chien",
                        "many": "Il y a {Num} de chiens",
                        "other": "Il y a {Num} de chiens"
                    }
                }
            },
            "placeholders": [{
                "id": "Num",
                "string": "%[1]d",
                "type": "int",
                "underlyingType": "int",
                "argNum": 1,
                "expr": "num"
            }]
        },

However many is not supported for language fr.

gotext: generation failed: error: plural: form "many" not supported for language "fr"
test.go:3: running "gotext": exit status 1

Then I tried using "<1000000":

        {
            "id": "There are {Num} dog(s)",
            "message": "There are {Num} dog(s)",
            "translation": {
                "select": {
                    "feature": "plural",
                    "arg": "Num",
                    "cases": {
                        "=0": "Il n'y a pas de chien",
                        "one": "Il y a {Num} chien",
                        "<1000000": "Il y a {Num} chiens",
                        "other": "Il y a {Num} de chiens"
                    }
                }
            },
            "placeholders": [{
                "id": "Num",
                "string": "%[1]d",
                "type": "int",
                "underlyingType": "int",
                "argNum": 1,
                "expr": "num"
            }]
        },

As the number 1,000,000 is read as an int16, gotext raises an error:

gotext: generation failed: error: plural: invalid number in selector "<1000000": strconv.ParseUint: parsing "1000000": value out of range
test.go:3: running "gotext": exit status 1

What did you expect to see?

Il y a 999 999 chiens
Il y a 1 000 000 de chiens
Il y a 1 000 001 de chiens

What did you see instead?

gotext: generation failed: error: plural: invalid number in selector "<1000000": strconv.ParseUint: parsing "1000000": value out of range
test.go:3: running "gotext": exit status 1
@gopherbot gopherbot added this to the Unreleased milestone Aug 17, 2018
@fgm

This comment has been minimized.

Copy link

@fgm fgm commented Dec 13, 2018

French user here: three aspects of this issue are problematic:

  • none of the 4 sentences below are representative of fr-FR formatting, since this locale does not use quotes as a thousands separator:
    Il y a 999'999 habitants.
    Il y a 999'999 chiens.
    Il y a 1'000'000 d'habitants.
    Il y a 1'000'000 de chiens.
  • the "de" is used when numbers are spelled out, like "il y a un million de chiens", but I do not remember ever seeing the "de" used as in this example with the numeric representation of the number
  • even in the previous case, "de" is only used for round numbers with rounding at 1E6, 1E9, 12E12...:
    • 1000000: il y a un million de chiens
    • 1200000: il y a un million deux cent mille chiens <- no "de"
    • 1000000000: il y a un milliard de chiens
    • 1002000000: il y a un milliard deux cent millions de chiens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.