Example #1
0
func TestInterval(t *testing.T) {
	expect := map[float64]string{
		-1e-30: "outside",
		0:      "inside",
		.5:     "inside",
		.99999: "inside",
		1:      "outside",
	}

	contents := map[string]string{
		"plurals:t0:range(0,1)": "inside",
		"plurals:t0:default":    "outside",
	}

	code := "l6"

	ginta.Register(simple.New().AddLanguage(code, code, contents))

	if p, err := parse([]string{"t0"}); err == nil {
		for key, val := range expect {
			if str := p.Converter().Convert(ginta.Locale(code), key).(string); str != val {
				t.Error(key, val, str)
			}
		}
	} else {
		t.Error(p, err)
	}
}
Example #2
0
func en() {
	p := simple.New().AddLanguage("en", "English", map[string]string{
		TimeFormatRoot + ":" + DateFormat + ":" + OptionDefault: "Jan 02, 2006",
	})

	ginta.Register(p)
	internal.Activate("en")
}
Example #3
0
func de() {
	p := simple.New().AddLanguage("de", "Deutsch", map[string]string{
		TimeFormatRoot + ":" + DateTimeFormat + ":" + OptionLong: "Monday, 02. January 2006, um 15:04",
		SubstitutionsResourceBundle + ":Wednesday":               "Mittwoch",
		SubstitutionsResourceBundle + ":May":                     "Mai",
	})

	ginta.Register(p)
	internal.Activate("de")
}
Example #4
0
func doTest(t *testing.T, expect map[int64]string, contents map[string]string, code string) {
	ginta.Register(simple.New().AddLanguage(code, code, contents))

	if p, err := parse([]string{"t0"}); err == nil {
		for key, val := range expect {
			if str := p.Converter().Convert(ginta.Locale(code), key).(string); str != val {
				t.Error(key, val, str)
			}
		}
	} else {
		t.Error(p, err)
	}
}
Example #5
0
func TestInputTypes(t *testing.T) {
	expect := []interface{}{
		inter{},
		int(1),
		int8(2),
		int16(3),
		int32(4),
		int64(5),
		uint(6),
		uint8(7),
		uint16(8),
		uint32(9),
		uint64(10),
		float32(11),
		float64(12),
	}

	ginta.Register(simple.New().AddLanguage("lx", "Language 3", map[string]string{
		"plurals:t0:eq1":  "1",
		"plurals:t0:eq2":  "2",
		"plurals:t0:eq3":  "3",
		"plurals:t0:eq4":  "4",
		"plurals:t0:eq5":  "5",
		"plurals:t0:eq6":  "6",
		"plurals:t0:eq7":  "7",
		"plurals:t0:eq8":  "8",
		"plurals:t0:eq9":  "9",
		"plurals:t0:eq10": "10",
		"plurals:t0:eq11": "11",
		"plurals:t0:eq12": "12",
		"plurals:t0:eq0":  "0",
	}))

	if p, err := parse([]string{"t0"}); err == nil {
		var b bytes.Buffer
		for _, val := range expect {
			str := p.Converter().Convert(ginta.Locale("lx"), val).(string)
			b.WriteString(str)
		}

		if b.String() != "0123456789101112" {
			t.Error(b.String())
		}
	} else {
		t.Error(p, err)
	}
}
Example #6
0
func TestOneTwoThree(t *testing.T) {
	expect := map[int64]string{
		1: "one",
		2: "two",
		3: "three",
	}

	ginta.Register(simple.New().AddLanguage("l1", "Language 1", map[string]string{
		"plurals:t0:eq1": "one",
		"plurals:t0:eq2": "two",
		"plurals:t0:eq3": "three",
	}))

	if p, err := parse([]string{"t0"}); err == nil {
		for key, val := range expect {
			if str := p.Converter().Convert(ginta.Locale("l1"), key).(string); str != val {
				t.Error(key, val, str)
			}
		}
	} else {
		t.Error(p, err)
	}
}