i18n

package
v2.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

i18n 多语言资源

资源文件

文件名格式

  • locale.[lang].json | locale.[lang].ini => locale.en-US.json | locale.zh-CN.ini

内容格式

  • locale.[lang].json
{
  "name": "value",
  "name2": "value2",
  ...
}
  • locale.[lang].ini
name=value
name2=value2
...

使用本地加载资源

i18n.SetLocalPath(localPath string)

使用内置FS加载资源

i18n.SetLocalFS(localFS *embed.FS, localFSPath string)

语言切换

i18n.Switch(lang consts.LANGUAGE)

静态资源注册

i18n.RegisterResource(name, value string)

变量资源注册

i18n.RegisterVarResource(name string, value *string)

获取资源

i18n.Resource(name string) string

Documentation

Overview

Package i18n Multilingual resources

Resource usage file loading
File name format: locale.[lang].json | locale.[lang].ini => locale.en-US.json | locale.zh-CN.ini

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterResource

func RegisterResource(name, value string)

RegisterResource

注册资源, 在代码中手动设置在静态资源

func RegisterVarResource

func RegisterVarResource(name string, value *string)

RegisterVarResource

注册变量资源, 在代码中手动设置, 切换资源时变量值会被同步

func Resource

func Resource(name string) string

Resource

返回资源-优先在静态资源中查找

func SetLocalFS

func SetLocalFS(localFS emfs.IEmbedFS, localFSPath string)

SetLocalFS

设置本地资源在FS中加载-优先
lFS: 内置对象
lFSPath: 资源所在目录 to/path

func SetLocalPath

func SetLocalPath(localPath string)

SetLocalPath

设置本地资源在本地目录加载

func Switch

func Switch(lang consts.LANGUAGE)

Switch

 切换语言
	默认先在内置FS中加载

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL