當前位置: 首頁>>代碼示例>>Golang>>正文


Golang i18n.Tfunc函數代碼示例

本文整理匯總了Golang中github.com/nicksnyder/go-i18n/i18n.Tfunc函數的典型用法代碼示例。如果您正苦於以下問題:Golang Tfunc函數的具體用法?Golang Tfunc怎麽用?Golang Tfunc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Tfunc函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Init

func Init(config core_config.ReadWriter) go_i18n.TranslateFunc {
	var T go_i18n.TranslateFunc
	var err error

	locale := config.Locale()
	if locale != "" {
		pieces := strings.Split(locale, "_")
		err = loadFromAsset(locale, pieces[1])
		if err == nil {
			T, err = go_i18n.Tfunc(config.Locale(), DEFAULT_LOCALE)
		}
	} else {
		var userLocale string
		userLocale, err = initWithUserLocale()
		if err != nil {
			userLocale = mustLoadDefaultLocale()
		}

		T, err = go_i18n.Tfunc(userLocale, DEFAULT_LOCALE)
	}

	if err != nil {
		panic(err)
	}

	return T
}
開發者ID:nttlabs,項目名稱:cli,代碼行數:27,代碼來源:init.go

示例2: Init

func Init(config core_config.ReadWriter, detector detection.Detector) go_i18n.TranslateFunc {
	var T go_i18n.TranslateFunc
	var err error

	locale := config.Locale()
	if locale != "" {
		err = loadFromAsset(locale)
		if err == nil {
			T, err = go_i18n.Tfunc(config.Locale(), DEFAULT_LOCALE)
		}
	} else {
		var userLocale string
		userLocale, err = initWithUserLocale(detector)
		if err != nil {
			userLocale = mustLoadDefaultLocale()
		}

		T, err = go_i18n.Tfunc(userLocale, DEFAULT_LOCALE)
	}

	if err != nil {
		panic(err)
	}

	return T
}
開發者ID:tools-alexuser01,項目名稱:cli,代碼行數:26,代碼來源:init.go

示例3: LoadLocale

func LoadLocale(locale string) i18n.TranslateFunc {
	if locale != "" {
		T, _ = i18n.Tfunc(locale)
	} else {
		T, _ = i18n.Tfunc("en-US")
	}

	return T
}
開發者ID:newestindustry,項目名稱:go-form,代碼行數:9,代碼來源:locale.go

示例4: GetTranslationsAndLocale

func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
	headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
	if locales[headerLocale] != "" {
		translations, _ := i18n.Tfunc(headerLocale)
		return translations, headerLocale
	}

	translations, _ := i18n.Tfunc(model.DEFAULT_LOCALE)
	return translations, model.DEFAULT_LOCALE
}
開發者ID:jessezwd,項目名稱:platform,代碼行數:10,代碼來源:i18n.go

示例5: TfuncWithFallback

func TfuncWithFallback(pref string) i18n.TranslateFunc {
	t, _ := i18n.Tfunc(pref)
	return func(translationID string, args ...interface{}) string {
		if translated := t(translationID, args...); translated != translationID {
			return translated
		}

		t, _ := i18n.Tfunc(model.DEFAULT_LOCALE)
		return t(translationID, args...)
	}
}
開發者ID:loafoe,項目名稱:platform,代碼行數:11,代碼來源:i18n.go

示例6: lookup

/**
 * Request that the LCS start a lookup process for a particular URL.
 * @param {string} lookupURL - The URL to try to find in the distributed cache
 */
func lookup(lookupURL string) Result {
	response, err := http.Get(BundleLookupURL(Configuration, lookupURL))
	T, _ := i18n.Tfunc(os.Getenv("CENOLANG"), "en-us")
	if err != nil {
		fmt.Println(T("error_cli", map[string]interface{}{
			"Message": err.Error(),
		}))
		return Result{ERR_NO_CONNECT_LCS, err.Error(), false, false, ""}
	} else if response == nil || response.StatusCode != 200 {
		errMsg := T("lcs_not_ready_cli")
		fmt.Println(errMsg)
		return Result{ERR_LCS_NOT_READY, errMsg, false, false, ""}
	}
	decoder := json.NewDecoder(response.Body)
	var result Result
	err = decoder.Decode(&result)
	if err != nil {
		decodeErrorMessage := T("decode_error_cli", map[string]interface{}{
			"Message": err.Error(),
		})
		fmt.Println(decodeErrorMessage)
		reachedLCS := HandleCCError(ERR_MALFORMED_LCS_RESPONSE, err.Error(), ErrorState{
			"requestURL": DecodeErrReportURL(Configuration),
		})
		if reachedLCS {
			return Result{ERR_MALFORMED_LCS_RESPONSE, decodeErrorMessage, false, false, ""}
		} else {
			errMsg := T("no_reach_lcs_cli")
			return Result{ERR_NO_CONNECT_LCS, errMsg, false, false, ""}
		}
	}
	return result
}
開發者ID:nametoolong,項目名稱:ceno,代碼行數:37,代碼來源:client.go

示例7: init

func init() {

	cmd, err := notify.NewCmd("telegram-cli", "-C")

	if err != nil {
		log.Fatal("NewCmd error", err)
	}

	botConf = Conf{
		Limit: 10,
		Url:   "localhost",
		Rpms:  500,
		Cmd:   cmd,
	}

	//Init Data Mapper
	c, err := beeconf.NewConfig("ini", "../../conf/app.conf")

	if err != nil {
		log.Fatal(err)
	}

	TestConfig, err := conf.Initialize("test", c)
	if err != nil {
		log.Fatal(err)
	}

	if err := M.DbOpen(TestConfig.Db); err != nil {
		log.Fatal(err)
	}

	M.PrepareTables(&M.Cand{})
	Tfn, _ := i18n.Tfunc("en-us", "en-us", "en-us")
	M.T = Tfn
}
開發者ID:grr89,項目名稱:hrkb,代碼行數:35,代碼來源:bot_test.go

示例8: main

func main() {
	// Configure the i18n library to use the preferred language set in the CENOLANG environement variable
	setLanguage := os.Getenv("CENOLANG")
	if setLanguage == "" {
		os.Setenv("CENOLANG", "en-us")
		setLanguage = "en-us"
	}
	i18n.MustLoadTranslationFile("./translations/" + setLanguage + ".all.json")
	T, _ := i18n.Tfunc(setLanguage, "en-us")
	// Read an existing configuration file or have the user supply settings
	if conf, err := ReadConfigFile(CONFIG_FILE); err != nil {
		fmt.Println(T("no_config_cli", map[string]interface{}{"Location": CONFIG_FILE}))
		Configuration = GetConfigFromUser()
	} else {
		Configuration = conf
	}
	// Create an HTTP proxy server
	http.HandleFunc("/lookup", directHandler)
	http.HandleFunc("/", proxyHandler)
	fmt.Println(T("listening_msg_cli", map[string]interface{}{"Port": Configuration.PortNumber}))
	err := http.ListenAndServe(Configuration.PortNumber, nil)
	if err != nil {
		panic(err)
	}
}
開發者ID:nametoolong,項目名稱:ceno,代碼行數:25,代碼來源:client.go

示例9: SendEmailPasswordResetToken

// SendEmailPasswordResetToken sends a password reset token via email.
func SendEmailPasswordResetToken(to string, token string, locale string) error {
	T, _ := i18n.Tfunc(locale)
	err := email.SendEmailFromAdmin(to,
		T("reset_password_title"),
		T("link")+" : "+config.HostURL+"/reset/password/"+token,
		T("reset_password_content")+"<br/><a href=\""+config.HostURL+"/reset/password/"+token+"\" target=\"_blank\">"+config.HostURL+"/reset/password/"+token+"</a>")
	return err
}
開發者ID:wangmingjob,項目名稱:goyangi,代碼行數:9,代碼來源:password.go

示例10: SendEmailVerfication

// SendEmailVerfication sends an email verification token via email.
func SendEmailVerfication(to string, token string, locale string) error {
	T, _ := i18n.Tfunc(locale)
	err := email.SendEmailFromAdmin(to,
		T("verify_email_title"),
		T("link")+" : "+config.HostURL+"/verify/email/"+token,
		T("verify_email_content")+"<br/><a href=\""+config.HostURL+"/verify/email/"+token+"\" target=\"_blank\">"+config.HostURL+"/verify/email/"+token+"</a>")
	return err
}
開發者ID:wangmingjob,項目名稱:goyangi,代碼行數:9,代碼來源:verification.go

示例11: GetUserTranslations

func GetUserTranslations(locale string) i18n.TranslateFunc {
	if _, ok := locales[locale]; !ok {
		locale = model.DEFAULT_LOCALE
	}

	translations, _ := i18n.Tfunc(locale)
	return translations
}
開發者ID:bitbackofen,項目名稱:platform,代碼行數:8,代碼來源:i18n.go

示例12: NewTranslation

// NewTranslation obtains a translation function object for the
// specified locales
func NewTranslation(userLocale string, defaultLocale string) (t i18n.TranslateFunc, err error) {
	t, err = i18n.Tfunc(userLocale, userLocale)
	if err != nil {
		return t, err
	}

	return t, err
}
開發者ID:jharlap,項目名稱:beego-mgo,代碼行數:10,代碼來源:messages.go

示例13: init

func init() {
	// TO DO : find another way maybe with assets, go bind-data
	out1, _ := Asset("en-us.all.yaml")
	out2, _ := Asset("fr-be.all.yaml")
	i18n.ParseTranslationFileBytes("en-us.all.yaml", out1)
	i18n.ParseTranslationFileBytes("fr-be.all.yaml", out2)
	Tr, _ = i18n.Tfunc("fr-be")
}
開發者ID:olivier5741,項目名稱:stock-manager,代碼行數:8,代碼來源:translation.go

示例14: Example

func Example() {
	i18n.MustLoadTranslationFile("../goi18n/testdata/expected/en-us.all.json")

	T, _ := i18n.Tfunc("en-US")

	bobMap := map[string]interface{}{"Person": "Bob"}
	bobStruct := struct{ Person string }{Person: "Bob"}

	fmt.Println(T("program_greeting"))
	fmt.Println(T("person_greeting", bobMap))
	fmt.Println(T("person_greeting", bobStruct))

	fmt.Println(T("your_unread_email_count", 0))
	fmt.Println(T("your_unread_email_count", 1))
	fmt.Println(T("your_unread_email_count", 2))
	fmt.Println(T("my_height_in_meters", "1.7"))

	fmt.Println(T("person_unread_email_count", 0, bobMap))
	fmt.Println(T("person_unread_email_count", 1, bobMap))
	fmt.Println(T("person_unread_email_count", 2, bobMap))
	fmt.Println(T("person_unread_email_count", 0, bobStruct))
	fmt.Println(T("person_unread_email_count", 1, bobStruct))
	fmt.Println(T("person_unread_email_count", 2, bobStruct))

	fmt.Println(T("person_unread_email_count_timeframe", 3, map[string]interface{}{
		"Person":    "Bob",
		"Timeframe": T("d_days", 0),
	}))
	fmt.Println(T("person_unread_email_count_timeframe", 3, map[string]interface{}{
		"Person":    "Bob",
		"Timeframe": T("d_days", 1),
	}))
	fmt.Println(T("person_unread_email_count_timeframe", 3, map[string]interface{}{
		"Person":    "Bob",
		"Timeframe": T("d_days", 2),
	}))

	// Output:
	// Hello world
	// Hello Bob
	// Hello Bob
	// You have 0 unread emails.
	// You have 1 unread email.
	// You have 2 unread emails.
	// I am 1.7 meters tall.
	// Bob has 0 unread emails.
	// Bob has 1 unread email.
	// Bob has 2 unread emails.
	// Bob has 0 unread emails.
	// Bob has 1 unread email.
	// Bob has 2 unread emails.
	// Bob has 3 unread emails in the past 0 days.
	// Bob has 3 unread emails in the past 1 day.
	// Bob has 3 unread emails in the past 2 days.
}
開發者ID:RadekD,項目名稱:go-i18n,代碼行數:55,代碼來源:example_test.go

示例15: validateURL

/**
 * Check if a provided URL is well-formed.  If not, serve an error page.
 * This call terminates requests when the return value is false (i.e. invalid URL).
 * @param {string} URL - The URL being requested
 * @param {ResponseWriter} w - The object handling writing responses to the client
 * @param {*Request} r - Information about the request
 */
func validateURL(URL string, w http.ResponseWriter, r *http.Request) bool {
	isValid, err := regexp.MatchString(URL_REGEX, URL)
	T, _ := i18n.Tfunc(os.Getenv("CENOLANG"), "en-us")
	if !isValid || err != nil {
		HandleCCError(ERR_MALFORMED_URL, T("malformed_url_cli", map[string]interface{}{
			"URL": URL,
		}), ErrorState{"responseWriter": w, "request": r})
		return false
	}
	return true
}
開發者ID:nametoolong,項目名稱:ceno,代碼行數:18,代碼來源:client.go


注:本文中的github.com/nicksnyder/go-i18n/i18n.Tfunc函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。