2024-07-10 17:24:58 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-07-11 13:47:21 +08:00
|
|
|
"embed"
|
2024-07-10 17:24:58 +08:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/yuninks/langx"
|
|
|
|
|
)
|
|
|
|
|
|
2024-07-11 13:47:21 +08:00
|
|
|
//go:embed lang
|
|
|
|
|
var assetsFs embed.FS
|
|
|
|
|
|
2024-07-10 17:24:58 +08:00
|
|
|
func main() {
|
2024-07-11 13:47:21 +08:00
|
|
|
demoEmbed()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func demoEmbed() {
|
|
|
|
|
err := langx.RegisterEmbed(assetsFs)
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
2024-07-11 21:12:01 +08:00
|
|
|
code, msg := langx.GetTransFormat("zh", "success", map[string]string{})
|
2024-07-11 13:47:21 +08:00
|
|
|
fmt.Println(code, msg)
|
|
|
|
|
code, msg = langx.GetTransFormat("en", "error", map[string]string{
|
|
|
|
|
"msg": "这是失败的原因",
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(code, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func demo1() {
|
2024-07-10 17:24:58 +08:00
|
|
|
langx.RegisterDir("./lang")
|
|
|
|
|
|
2024-07-10 18:28:53 +08:00
|
|
|
code, msg := langx.GetTransFormat("zh", "success", map[string]string{})
|
2024-07-10 17:24:58 +08:00
|
|
|
fmt.Println(code, msg)
|
2024-07-10 18:28:53 +08:00
|
|
|
code, msg = langx.GetTransFormat("en", "error", map[string]string{
|
|
|
|
|
"msg": "这是失败的原因",
|
2024-07-10 17:24:58 +08:00
|
|
|
})
|
|
|
|
|
fmt.Println(code, msg)
|
|
|
|
|
}
|