Beispiel #1
0
func initWithUserLocale(packageName, i18nDirname string) (string, error) {
	userLocale, err := jibber_jabber.DetectIETF()
	if err != nil {
		userLocale = DEFAULT_LOCALE
	}

	language, err := jibber_jabber.DetectLanguage()
	if err != nil {
		language = DEFAULT_LANGUAGE
	}

	userLocale = strings.Replace(userLocale, "-", "_", 1)
	err = loadFromAsset(packageName, i18nDirname, userLocale, language)
	if err != nil {
		locale := SUPPORTED_LOCALES[language]
		if locale == "" {
			userLocale = DEFAULT_LOCALE
		} else {
			userLocale = locale
		}
		err = loadFromAsset(packageName, i18nDirname, userLocale, language)
	}

	return userLocale, err
}
Beispiel #2
0
func Init(packageName string, i18nDirname string) go_i18n.TranslateFunc {
	userLocale, err := jibber_jabber.DetectIETF()
	if err != nil {
		userLocale = DEFAULT_LOCAL
	}

	// convert IETF format to XCU format
	userLocale = strings.Replace(userLocale, "-", "_", 1)
	loadFromAsset(packageName, i18nDirname, userLocale)
	// if err != nil {
	// 	panic(err)
	// }

	T, err := go_i18n.Tfunc(userLocale, DEFAULT_LOCAL)
	if err != nil {
		panic(err)
	}

	return T
}
Beispiel #3
0
			})

			It("returns a usable T function for complex strings (interpolated)", func() {
				T := i18n.Init(configRepo)
				Ω(T).ShouldNot(BeNil())

				translation := T("Deleting domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{"DomainName": "foo.com", "Username": "******"})
				Ω("Deleting domain foo.com as Anand...").Should(Equal(translation))
			})
		})
	})

	Describe("When a user does not have a locale configuration set", func() {
		BeforeEach(func() {
			//All these tests require the system language to be English
			Ω(jibber_jabber.DetectIETF()).Should(Equal("en-US"))
		})

		Context("creates a valid T function", func() {
			BeforeEach(func() {
				os.Setenv("LC_ALL", "en_US.UTF-8")
			})

			It("returns a usable T function for simple strings", func() {
				T := i18n.Init(configRepo)
				Ω(T).ShouldNot(BeNil())

				translation := T("Change user password")
				Ω("Change user password").Should(Equal(translation))
			})
func (detector *JibberJabberDetector) DetectIETF() (string, error) {
	return jibber_jabber.DetectIETF()
}