Browse Source

x/text: tiny improvements

Frédéric G. MARAND 1 year ago
parent
commit
30a25b2e68

+ 0 - 11
.idea/runConfigurations/xtext_01_basic.xml

@@ -1,11 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="xtext/01 basic" type="GoApplicationRunConfiguration" factoryName="Go Application">
-    <module name="go__i18n_demo" />
-    <working_directory value="$PROJECT_DIR$/xtext" />
-    <kind value="FILE" />
-    <package value="xtext" />
-    <directory value="$PROJECT_DIR$" />
-    <filePath value="$PROJECT_DIR$/xtext/01basic/01basic.go" />
-    <method v="2" />
-  </configuration>
-</component>

+ 0 - 11
.idea/runConfigurations/xtext_02_plural.xml

@@ -1,11 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="xtext/02 plural" type="GoApplicationRunConfiguration" factoryName="Go Application">
-    <module name="go__i18n_demo" />
-    <working_directory value="$PROJECT_DIR$/xtext" />
-    <kind value="FILE" />
-    <package value="xtext" />
-    <directory value="$PROJECT_DIR$" />
-    <filePath value="$PROJECT_DIR$/xtext/02plural/02plural.go" />
-    <method v="2" />
-  </configuration>
-</component>

+ 0 - 11
.idea/runConfigurations/xtext_03_interpolations.xml

@@ -1,11 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="xtext/03 interpolations" type="GoApplicationRunConfiguration" factoryName="Go Application">
-    <module name="go__i18n_demo" />
-    <working_directory value="$PROJECT_DIR$/xtext" />
-    <kind value="FILE" />
-    <package value="xtext" />
-    <directory value="$PROJECT_DIR$" />
-    <filePath value="$PROJECT_DIR$/xtext/03interpolation/03interpolation.go" />
-    <method v="2" />
-  </configuration>
-</component>

+ 11 - 2
xtext/01basic/01basic.go

@@ -13,16 +13,25 @@ const (
 
 func init() {
 	message.SetString(language.French, Flowers, "Il y a %d fleurs dans notre jardin.\n")
+	message.SetString(language.German, Flowers, "In unserem Garten stehen %d Blumen.\n")
 }
 
 func main() {
-	pUK := message.NewPrinter(language.BritishEnglish)
-	pUK.Printf(Flowers, 1500)
 
 	frFR, err := language.Parse("fr_FR") // Also: ParseBase, ParseRegion, Composer
 	if err != nil {
 		log.Fatalf("parsing fr_FR: %v", err)
 	}
+	deDE, err := language.Parse("de_DE") // Also: ParseBase, ParseRegion, Composer
+	if err != nil {
+		log.Fatalf("parsing de_DE: %v", err)
+	}
+
+	pUK := message.NewPrinter(language.BritishEnglish)
+	dFR := message.NewPrinter(deDE)
 	pFR := message.NewPrinter(frFR)
+
+	pUK.Printf(Flowers, 1500)
 	pFR.Printf(Flowers, 1500)
+	dFR.Printf(Flowers, 1500)
 }

+ 3 - 3
xtext/02plural/02plural.go

@@ -17,16 +17,16 @@ func init() {
 	message.Set(language.French, Problem,
 		plural.Selectf(1, "%d",
 			"=0", "Vous n'avez aucun problème\n",
-			"=1", "Vous avez un problème\n",
+			plural.One, "Vous avez un problème\n",
 			"other", "Vous avez %d problèmes\n",
 		),
 	)
 	message.Set(language.AmericanEnglish, Problem,
 		plural.Selectf(1, "%d",
 			"=0", "You do not have a problem\n",
-			"=1", "You have a problem\n",
+			plural.One, "You have a problem\n",
 			"=2", "You have a couple of problems\n",
-			"other", "You have %d problems\n",
+			plural.Other, "You have %d problems\n",
 		),
 	)
 }

+ 10 - 2
xtext/03interpolation/03interpolation.go

@@ -16,18 +16,26 @@ const (
 func init() {
 	message.Set(language.French, Lateness,
 		catalog.Var("minutes", plural.Selectf(1, "%d",
+			"=0", "minute",
 			"=1", "minute",
-			"other", "minutes",
+			plural.Other, "minutes",
 		)),
 		catalog.String("Vous êtes en retard de %[1]d ${minutes}\n"),
 	)
+	message.Set(language.AmericanEnglish, Lateness,
+		catalog.Var("minutes", plural.Selectf(1, "%d",
+			"=1", "minute",
+			plural.Other, "minutes",
+		)),
+		catalog.String("You are %[1]d ${minutes} late\n"),
+	)
 }
 
 func main() {
 	for _, lang := range []language.Tag{language.French, language.AmericanEnglish} {
 		fmt.Printf("Language: %v\n", lang)
 		p := message.NewPrinter(lang)
-		for i := 1; i <= 2; i++ {
+		for i := 0; i <= 2; i++ {
 			fmt.Print("\t")
 			p.Printf(Lateness, i)
 		}