Skip to content

michlabs/bottext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BotText

BotText is a Go package that help you:

  • Translate your bot into multiple languages,
  • Make your bot more interesting by expressing the same thing in different ways.

Installation

Make sure you have setup GOPATH

go get github.com/michlabs/bottext

Example

Create a new language file named text.yml:

vi:
  welcome:
    - Xin chào %s!
    - Hi %s
en:
  welcome:
    - Hello %s!
    - Welcome %s!
    - Hi %s

Then in your source code:

package main 

import (
    "fmt"
    "github.com/michlabs/bottext"
)

func main() {
    bottext.MustLoad("text.yml")
    var T1 bottext.BotTextFunc
    T1 = bottext.New("en")
    for i := 0; i < 10; i ++ {
        fmt.Printf(T1("welcome") + "\n", "Donald Trump")    
    }

    T2 := bottext.New("vi")
    for i := 0; i < 10; i ++ {
        fmt.Printf(T2("welcome"), "Đỗ Nam Trung")   
    }
}

Document

Read in Godoc

Releases

No releases published

Packages

No packages published

Languages