简单易用的lib用于在Go项目中使用缓存管理翻译和文本

简单易用的lib用于在Go项目中使用缓存管理翻译和文本

Go 其它杂项

访问GitHub主页

共13Star

详细介绍

About

Simple and easy lib. to manage translations and texts, with cache, in Go project.

Installation

go get -u github.com/pagedegeek/textsbox

Usage

// main.go
package main

import (
        "github.com/pagedegeek/textsbox"
)

func main() {
        tb := textsbox.New()

        tb.LoadFile("./config/locales/en.yml")
        tb.LoadFile("./config/locales/fr.yml")

        tb.AddKeyAlias("en", "en-En")
        tb.AddKeyAlias("fr", "fr-Fr", "fr-FR")

        // ...
        // locale := session.Get("locale") // can be: en, en-En, fr, fr-Fr, fr-FR

        txt, _ := tb.Find(locale, "messages.welcome")
        welcomeMsg := txt.(string)
        view.render(welcomeMsg)
}
# config/locales/en.yml
en:
  messages:
    welcome: Hello World !
# config/locales/fr.yml
fr:
  messages:
    welcome: Bonjour tout le monde !

Other features

Load YAML content

tb.LoadFile("...") // load from file
tb.Load(reader) // load from io.Reader

Reset cache

tb.ResetCache()
推荐源码