// Localization
// GetTranslator returns Translator inside a Carbon instance if exist,
// otherwise it creates a new Translator with "en" as default locale
965451
func (c *Carbon) GetTranslator() (*Translator, error) {
	if c.Translator == nil {
		c.Translator = translator()
	}

	return c.Translator, nil
}
1053901
func getCollator(locale string) *collate.Collator {

	defer func() {
		recover()
	}()

	tag := language.Make(locale)

	if tag == language.Und {
		return nil
	}
	return collate.New(tag)
}
487045
func (manager *Manager) GetTransactor(channel string, privateCredential, publicCredential []byte) (Transactor, error) {
	ledger, err := manager.LedgerManager.GetLedgerReader(channel)
	if err != nil {
		return nil, errors.Wrapf(err, "failed getting ledger for channel: %s", channel)
	}
	return &plain.Transactor{Ledger: ledger, PublicCredential: publicCredential}, nil
}
710400
func (k RuleTranslator) TranslateEgress(r *api.EgressRule, result *policy.TranslationResult) error {

	defer r.SetAggregatedSelectors()
	err := k.depopulateEgress(r, result)
	if err != nil {
		return err
	}
	if !k.Revert {
		err := k.populateEgress(r, result)
		if err != nil {
			return err
		}
	}
	return nil
}
879354
func (k RuleTranslator) Translate(r *api.Rule, result *policy.TranslationResult) error {
	for egressIndex := range r.Egress {
		err := k.TranslateEgress(&r.Egress[egressIndex], result)
		if err != nil {
			return err
		}
	}
	return nil
}
1103503
func NewTranslator(dirname string, fields ...string) (lt *Translator, err error) {
	lt = &Translator{
		dirname: dirname,
		fields:  make(map[string]*FieldTranslator),
	}
	for _, field := range fields {
		lft, err := NewFieldTranslator(dirname, field)
		if err != nil {
			return nil, errors.Wrap(err, "making FieldTranslator")
		}
		lt.fields[field] = lft
	}
	return lt, err
}
557983
func Translator(toCharset, fromCharset string, invalid rune) (charset.Translator, error) {
	cto, cfrom := C.CString(toCharset), C.CString(fromCharset)
	cd, err := C.iconv_open(cto, cfrom)

	C.free(unsafe.Pointer(cfrom))
	C.free(unsafe.Pointer(cto))

	if cd == C.iconv_open_error {
		if err == syscall.EINVAL {
			return nil, errors.New("iconv: conversion not supported")
		}
		return nil, err
	}
	t := &iconvTranslator{cd: cd, invalid: invalid}
	runtime.SetFinalizer(t, func(*iconvTranslator) {
		C.iconv_close(cd)
	})
	return t, nil
}
863505
func GetLanguage() (l string) {
	l = language
	if l != "" {
		goto STRIP
	}
	if l = os.Getenv("LANGUAGE"); l != "" {
		goto STRIP
	}
	if l = os.Getenv("LC_ALL"); l != "" {
		goto STRIP
	}
	if l = os.Getenv("LANG"); l != "" {
		goto STRIP
	}
	//fallback to US English
	l = "en_US"
STRIP:
	// Deal with any locale names like en_US.utf8
	if i := strings.IndexRune(l, '.'); i != -1 {
		l = l[0:i]
	}
	return
}
407512
func (t translator) translatableStruct(t1, t2 reflect.Type) bool {
	if t1.NumField() != t2.NumField() || t1.Name() != t2.Name() {
		return false
	}
	for i := 0; i < t1.NumField(); i++ {
		t1f := t1.Field(i)
		t2f, ok := t2.FieldByName(t1f.Name)

		if !ok {
			return false
		}
		if !t.translatable(t1f.Type, t2f.Type) && !t.hasTranslator(t1f.Type, t2f.Type) {
			return false
		}
	}
	return true
}
286501
func NewTransitionParser() TransitionParser {
	return TransitionParser{
		lookup: []string{},
		tokens: []*tcontainer.TrieNode{},
		stack:  []ParserStateID{},
	}
}
221914
func (t *UniversalTranslator) FindTranslator(locales ...string) (trans Translator, found bool) {

	for _, locale := range locales {

		if trans, found = t.translators[strings.ToLower(locale)]; found {
			return
		}
	}

	return t.fallback, false
}
127900
func (t translator) translate(vFrom, vTo reflect.Value) {
	tFrom := vFrom.Type()
	tTo := vTo.Type()
	if fnv := t.getTranslator(tFrom, tTo); fnv.IsValid() {
		vTo.Set(fnv.Call([]reflect.Value{vFrom})[0])
		return
	}
	if t.translatable(tFrom, tTo) {
		t.translateSameType(vFrom, vTo)
		return
	}

	panic(fmt.Sprintf("Translator not defined for %v to %v", tFrom, tTo))
}
1159528
func LoadTranslations(root string, getLanguageFn func() string) error {
	if getLanguageFn == nil {
		getLanguageFn = loadSystemLanguage
	}

	langStr := findLanguage(root, getLanguageFn)
	translationFiles := []string{
		fmt.Sprintf("%s/%s/LC_MESSAGES/k8s.po", root, langStr),
		fmt.Sprintf("%s/%s/LC_MESSAGES/k8s.mo", root, langStr),
	}

	klog.V(3).Infof("Setting language to %s", langStr)
	// TODO: list the directory and load all files.
	buf := new(bytes.Buffer)
	w := zip.NewWriter(buf)

	// Make sure to check the error on Close.
	for _, file := range translationFiles {
		filename := "translations/" + file
		f, err := w.Create(file)
		if err != nil {
			return err
		}
		data, err := generated.Asset(filename)
		if err != nil {
			return err
		}
		if _, err := f.Write(data); err != nil {
			return nil
		}
	}
	if err := w.Close(); err != nil {
		return err
	}
	gettext.BindTextdomain("k8s", root+".zip", buf.Bytes())
	gettext.Textdomain("k8s")
	gettext.SetLocale(langStr)
	return nil
}
135477
func (backend *Backend) LoadTranslations() (translations []*i18n.Translation) {
	backend.DB.Find(&translations)
	return translations
}
1224934
func (g *Generator) getLocalizedPath(path string) string {
	if strings.HasSuffix(path, ".go") {
		path, _ = filepath.Split(path)
	}
	if localized, ok := g.localizationCache[path]; ok {
		return localized
	}
	directories := strings.Split(path, string(filepath.Separator))
	numDirectories := len(directories)
	vendorIndex := -1
	for i := 1; i <= numDirectories; i++ {
		dir := directories[numDirectories-i]
		if dir == "vendor" {
			vendorIndex = numDirectories - i
			break
		}
	}

	toReturn := path
	if vendorIndex >= 0 {
		toReturn = filepath.Join(directories[vendorIndex+1:]...)
	} else if filepath.IsAbs(path) {
		toReturn = calculateImport(g.packageRoots, path)
	}

	// Enforce '/' slashes for import paths in every OS.
	toReturn = filepath.ToSlash(toReturn)

	g.localizationCache[path] = toReturn
	return toReturn
}
1059064
func (mat *T) SetTranslation(v *vec2.T) *T {
	mat[2][0] = v[0]
	mat[2][1] = v[1]
	return mat
}
1157241
func (p *PushEventRepository) GetLanguage() string {
	if p == nil || p.Language == nil {
		return ""
	}
	return *p.Language
}