Exemple #1
0
// TestUpdate tests whether dictionary entries for certain languages need to be
// updated. For some languages, some of the headers may be empty or they may be
// identical to the parent. This code detects if such entries need to be updated
// after a table update.
func TestUpdate(t *testing.T) {
	tests := []struct {
		d   *Dictionary
		tag string
	}{
		{ModernStandardArabic, "ar-001"},
		{AmericanEnglish, "en-US"},
		{EuropeanSpanish, "es-ES"},
		{BrazilianPortuguese, "pt-BR"},
		{SimplifiedChinese, "zh-Hans"},
	}

	for _, tt := range tests {
		_, i, _ := matcher.Match(language.MustParse(tt.tag))
		if !reflect.DeepEqual(tt.d.lang, langHeaders[i]) {
			t.Errorf("%s: lang table update needed", tt.tag)
		}
		if !reflect.DeepEqual(tt.d.script, scriptHeaders[i]) {
			t.Errorf("%s: script table update needed", tt.tag)
		}
		if !reflect.DeepEqual(tt.d.region, regionHeaders[i]) {
			t.Errorf("%s: region table update needed", tt.tag)
		}
	}
}
Exemple #2
0
func ExampleNamer() {
	supported := []string{
		"en-US", "en-GB", "ja", "zh", "zh-Hans", "zh-Hant", "pt", "pt-PT", "ko", "ar", "el", "ru", "uk", "pa",
	}

	en := display.Languages(language.English)

	for _, s := range supported {
		t := language.MustParse(s)
		fmt.Printf("%-20s (%s)\n", en.Name(t), display.Self.Name(t))
	}

	// Output:
	// American English     (American English)
	// British English      (British English)
	// Japanese             (日本語)
	// Chinese              (中文)
	// Simplified Chinese   (简体中文)
	// Traditional Chinese  (繁體中文)
	// Portuguese           (português)
	// European Portuguese  (português europeu)
	// Korean               (한국어)
	// Arabic               (العربية)
	// Greek                (Ελληνικά)
	// Russian              (русский)
	// Ukrainian            (українська)
	// Punjabi              (ਪੰਜਾਬੀ)
}
Exemple #3
0
func TestTag(t *testing.T) {
	tests := []struct {
		dict string
		tag  string
		name string
	}{
		{"nl", "nl", "Nederlands"},
		{"nl", "nl-BE", "Vlaams"},
		{"en", "en", "English"},
		{"en", "en-GB", "British English"},
		{"en", "en-US", "American English"}, // American English in CLDR 24+
		{"ru", "ru", "русский"},
		{"ru", "ru-RU", "русский (Россия)"},
		{"ru", "ru-Cyrl", "русский (Кириллица)"},
		{"en", lastLang2zu.String(), "Zulu"},
		{"en", firstLang2aa.String(), "Afar"},
		{"en", lastLang3zza.String(), "Zaza"},
		{"en", firstLang3ace.String(), "Achinese"},
		{"en", firstTagAr001.String(), "Modern Standard Arabic"},
		{"en", lastTagZhHant.String(), "Traditional Chinese"},
		{"en", "aaa", ""},
		{"en", "zzj", ""},
		// If full tag doesn't match, try without script or retion.
		{"en", "aa-Hans", "Afar (Simplified Han)"},
		{"en", "af-Arab", "Afrikaans (Arabic)"},
		{"en", "zu-Cyrl", "Zulu (Cyrillic)"},
		{"en", "aa-GB", "Afar (United Kingdom)"},
		{"en", "af-NA", "Afrikaans (Namibia)"},
		{"en", "zu-BR", "Zulu (Brazil)"},
		// Correct inheritance and language selection.
		{"zh", "zh-TW", "中文 (台湾)"},
		{"zh", "zh-Hant-TW", "繁体中文 (台湾)"},
		{"zh-Hant", "zh-TW", "中文 (台灣)"},
		{"zh-Hant", "zh-Hant-TW", "繁體中文 (台灣)"},
		// Some rather arbitrary interpretations for Serbian. This is arguably
		// correct and consistent with the way zh-[Hant-]TW is handled. It will
		// also give results more in line with the expectations if users
		// explicitly use "sh".
		{"sr-Latn", "sr-ME", "Srpski (Crna Gora)"},
		{"sr-Latn", "sr-Latn-ME", "Srpskohrvatski (Crna Gora)"},
		// Double script and region
		{"nl", "en-Cyrl-BE", "Engels (Cyrillisch, België)"},
		// Canonical equivalents.
		{"ro", "ro-MD", "moldovenească"},
		{"ro", "mo", "moldovenească"},
	}
	for i, tt := range tests {
		d := Tags(language.MustParse(tt.dict))
		if n := d.Name(language.Raw.MustParse(tt.tag)); n != tt.name {
			t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.tag, n, tt.name)
		}
	}
}
Exemple #4
0
func dictTags() (tag []language.Tag) {
	// TODO: replace with language.Common.Tags() once supported.
	const str = "af am ar ar-001 az bg bn ca cs da de el en en-US en-GB " +
		"es es-ES es-419 et fa fi fil fr fr-CA gu he hi hr hu hy id is it ja " +
		"ka kk km kn ko ky lo lt lv mk ml mn mr ms my ne nl no pa pl pt pt-BR " +
		"pt-PT ro ru si sk sl sq sr sv sw ta te th tr uk ur uz vi zh zh-Hans " +
		"zh-Hant zu"

	for _, s := range strings.Split(str, " ") {
		tag = append(tag, language.MustParse(s))
	}
	return tag
}
Exemple #5
0
func TestRegion(t *testing.T) {
	tests := []struct {
		dict string
		reg  string
		name string
	}{
		{"nl", "NL", "Nederland"},
		{"en", "US", "United States"},
		{"en", "ZZ", "Unknown Region"},
		{"en", "UM", "U.S. Outlying Islands"},
		{"en-GB", "UM", "U.S. Minor Outlying Islands"},
		{"en-GB", "NL", "Netherlands"},
		// Canonical equivalents
		{"en", "UK", "United Kingdom"},
		// No region
		{"en", "pt", "Unknown Region"},
		{"en", "und", "Unknown Region"},
		// Don't introduce regions with canonicalization.
		{"en", "mo", "Unknown Region"},
	}
	for i, tt := range tests {
		d := Regions(language.MustParse(tt.dict))
		var x interface{}
		if unicode.IsUpper(rune(tt.reg[0])) {
			// Region
			x = language.MustParseRegion(tt.reg)
			tag, _ := language.Raw.Compose(x)
			if n := d.Name(tag); n != tt.name {
				t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.reg, n, tt.name)
			}
		} else {
			// Tag
			x = language.Raw.MustParse(tt.reg)
		}
		if n := d.Name(x); n != tt.name {
			t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.reg, n, tt.name)
		}
	}
}
Exemple #6
0
func TestScript(t *testing.T) {
	tests := []struct {
		dict string
		scr  string
		name string
	}{
		{"nl", "Arab", "Arabisch"},
		{"en", "Arab", "Arabic"},
		{"en", "Zzzz", "Unknown Script"},
		{"zh-Hant", "Hang", "韓文字"},
		{"zh-Hant-HK", "Hang", "韓文字母"},
		{"zh", "Arab", "阿拉伯文"},
		{"zh-Hans-HK", "Arab", "阿拉伯文"}, // same as zh
		{"zh-Hant", "Arab", "阿拉伯文"},
		{"zh-Hant-HK", "Arab", "阿拉伯文"}, // same as zh
		// Canonicalized form
		{"en", "Qaai", "Inherited"},    // deprecated script, now is Zinh
		{"en", "sh", "Unknown Script"}, // sh canonicalizes to sr-Latn
		{"en", "en", "Unknown Script"},
		// Don't introduce scripts with canonicalization.
		{"en", "sh", "Unknown Script"}, // sh canonicalizes to sr-Latn
	}
	for i, tt := range tests {
		d := Scripts(language.MustParse(tt.dict))
		var x interface{}
		if unicode.IsUpper(rune(tt.scr[0])) {
			x = language.MustParseScript(tt.scr)
			tag, _ := language.Raw.Compose(x)
			if n := d.Name(tag); n != tt.name {
				t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.scr, n, tt.name)
			}
		} else {
			x = language.Raw.MustParse(tt.scr)
		}
		if n := d.Name(x); n != tt.name {
			t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.scr, n, tt.name)
		}
	}
}
Exemple #7
0
	"reflect"
	"testing"
	"unicode"

	"code.google.com/p/go.text/language"
)

// TODO: test that tables are properly dropped by the linker for various use
// cases.

var (
	firstLang2aa  = language.MustParseBase("aa")
	lastLang2zu   = language.MustParseBase("zu")
	firstLang3ace = language.MustParseBase("ace")
	lastLang3zza  = language.MustParseBase("zza")
	firstTagAr001 = language.MustParse("ar-001")
	lastTagZhHant = language.MustParse("zh-Hant")
)

func TestSupported(t *testing.T) {
	supportedTags := Supported.Tags()
	if len(supportedTags) != numSupported {
		t.Errorf("number of supported was %d; want %d", len(supportedTags), numSupported)
	}

	tags := make(map[language.Tag]bool)
	namers := make(map[Namer]bool)
	// isNil verifies that the namer is unique and returns whether it is nil.
	isNil := func(n Namer) bool {
		if n != nil {
			if namers[n] {
Exemple #8
0
	data  string
	index []uint16
}

var head = `// Generated by running
//		maketables -url=%s
// DO NOT EDIT

package %s

// Version is the version of CLDR used to generate the data in this package.
var Version = %#v

`

var self = language.MustParse("mul")

// generate builds and writes all tables.
func (b *builder) generate() {
	fmt.Printf(head, *url, *pkg, cldr.Version)

	b.filter()
	b.setData("lang", func(g *group, loc language.Tag, ldn *cldr.LocaleDisplayNames) {
		if ldn.Languages != nil {
			for _, v := range ldn.Languages.Language {
				tag := tagForm.MustParse(v.Type)
				if tags.contains(tag) {
					g.set(loc, tag.String(), v.Data())
				}
			}
		}