messages

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 6 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

messages Go license codecov PkgGoDev Go version

提供了本地化消息的序列化和提取

  • serialize 本地化消息的序列化
  • extract 本地化消息的提取

gomsg 将当前包的内容打包成了一个二进制文件。 可以直接在 go:generate 中使用。

安装

go get github.com/issue9/messages

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

Documentation

Overview

Package messages 本地化信息的定义

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Case

type Case struct {
	Case  string `xml:"case,attr" json:"case" yaml:"case" toml:"case"`
	Value string `xml:",chardata" json:"value" yaml:"value" toml:"value"`
}

type File

type File struct {
	XMLName   struct{}       `xml:"language" json:"-" yaml:"-" toml:"-"`
	Languages []language.Tag `xml:"languages>language" json:"languages" yaml:"languages" toml:"languages"` // 如果用字符串,还需要处理大小写以及不同值表示同一个 language.Tag 对象的问题
	Messages  []Message      `xml:"message" json:"messages" yaml:"messages" toml:"messages"`
}

File 单个本地化语言组成的文件

func (*File) Catalog

func (f *File) Catalog(b *catalog.Builder) (err error)

Catalog 将本地化信息附加在 catalog.Catalog 上

func (*File) Join

func (l *File) Join(l2 *File)

Join 将 l2.Messages 并入 l.Messages

执行以下操作:

-如果 l2 的 [Message.Key] 存在于 l,则覆盖 l 的项;
-如果 l2 的 [Message.Key] 不存在于 l,则写入 l;

func (*File) MergeTo

func (f *File) MergeTo(log LogFunc, dest *File, destFile string)

Merge 将 l.Messages 写入 dest

这将会执行以下几个步骤:

-删除只存在于 dest 元素中而不存在于 l 的内容;
-将 l 独有的项写入 dest;

最终内容是 dest 为准。 log 所有删除的记录都将通过此输出; destFile 最终输出的文件名,该值仅在错误信息中;

type LogFunc

type LogFunc = func(localeutil.Stringer)

type Message

type Message struct {
	Key     string `xml:"key" json:"key" yaml:"key" toml:"key"`
	Message Text   `xml:"message" json:"message" yaml:"message" toml:"message"`
}

Message 单条本地化内容

type Select

type Select struct {
	Arg    int     `xml:"arg,attr" json:"arg" yaml:"arg" toml:"arg"`
	Format string  `xml:"format,attr,omitempty" json:"format,omitempty" yaml:"format,omitempty" toml:"format,omitempty"`
	Cases  []*Case `xml:"case,omitempty" json:"cases,omitempty" yaml:"cases,omitempty" toml:"cases,omitempty"`
}

type Text

type Text struct {
	Msg    string  `xml:"msg,omitempty" json:"msg,omitempty" yaml:"msg,omitempty" toml:"msg,omitempty"`
	Select *Select `xml:"select,omitempty" json:"select,omitempty" yaml:"select,omitempty" toml:"select,omitempty"`
	Vars   []*Var  `xml:"var,omitempty" json:"vars,omitempty" yaml:"vars,omitempty" toml:"vars,omitempty"`
}

type Var

type Var struct {
	Name   string  `xml:"name,attr" json:"name" yaml:"name" toml:"name"`
	Arg    int     `xml:"arg,attr" json:"arg" yaml:"arg" toml:"arg"`
	Format string  `xml:"format,attr,omitempty" json:"format,omitempty" yaml:"format,omitempty" toml:"format,omitempty"`
	Cases  []*Case `xml:"case,omitempty" json:"cases,omitempty" yaml:"cases,omitempty" toml:"cases,omitempty"`
}

Directories

Path Synopsis
Package extract 提供从 Go 源码中提取本地化内容的功能
Package extract 提供从 Go 源码中提取本地化内容的功能
Package locales 本地化内容
Package locales 本地化内容
Package serialize 提供对 message 包的序列化操作
Package serialize 提供对 message 包的序列化操作

Jump to

Keyboard shortcuts

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