GithubHelp home page GithubHelp logo

go-i18n-helper's Introduction

Simple wrapper functions based go-i18n package

How to usage:

package main

import (
	"encoding/json"
	"github.com/dualface/go-i18n-helper/i18h"
	"log"
)

func main() {
	langs := map[string]string{
		"zh-cn": "tests/zh-cn.json",
		"en":    "tests/en.json",
	}
	err := i18h.Load(langs, "json", json.Unmarshal)
	if err != nil {
		log.Panic(err)
	}

	T := i18h.Lang("zh-cn")
	println(T("hello", "World"))
	println(T("not_found_dbtable", 3099, "admin_db", "users"))
	println()
	println()

	T = i18h.Lang("en")
	println(T("hello", "World"))
	println(T("not_found_dbtable", 3099, "admin_db", "users"))
	println()
	println()

	T = i18h.Lang("invalid-language")
	println(T("hello", "World"))
	println(T("not_found_dbtable", 3099, "admin_db", "users"))
	println()
	println()
}

Output:

你好,World
错误代码 [3099] 在数据库 'admin_db' 中没有找到表格 'users'


Hello, World
ERR_CODE 3099: NOT FOUND TABLE 'users' IN DB 'admin_db'


#I18N MISS# hello []interface {}{"World"}
#I18N MISS# not_found_dbtable []interface {}{3099, "admin_db", "users"}

- EOF -

go-i18n-helper's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.