zgo.at/z18n/msgfile Index | Files

package msgfile

import "zgo.at/z18n/msgfile"

Package msgfile manages message files.


Package Files

find_go.go find_tpl.go fmt_go.go fmt_list.go fmt_toml.go msgfile.go new.go


const (
    UpdatedRemoved = "removed"
    UpdatedChanged = "changed"

type Entries

type Entries map[string]Entry

Entries are a list of translatable entries.

func FindGo

func FindGo(dir string, funs ...string) (Entries, error)

Go finds all translatable strings in dir.

func FindTemplate

func FindTemplate(dir string, ext []string, funs ...string) (Entries, error)

FindTemplate finds all strings in Go templates.

func (Entries) Equal

func (e Entries) Equal(cmp Entries) bool

Equal reports if all entries in cmp are equal.

func (Entries) Merge

func (e Entries) Merge(src Entries)

Merge strings from src in to this Entries.

func (Entries) Sorted

func (e Entries) Sorted() []Entry

Sorted returns a list of entries sorted by ID.

func (Entries) Untranslated

func (e Entries) Untranslated() int

Untranslated reports the number of untranslated messages.

type Entry

type Entry struct {
    ID      string   `toml:"id" json:"id"`                               // Translation ID.
    Loc     []string `toml:"loc" json:"loc"`                             // Locations in code.
    Context string   `toml:"context,omitempty" json:"context,omitempty"` // Translation context.
    Updated string   `toml:"updated,omitempty" json:"updated,omitempty"` // Updated?

    // Messages.
    Default string `toml:"default,omitempty" json:"default,omitempty"`
    Zero    string `toml:"zero,omitempty" json:"zero,omitempty"`
    One     string `toml:"one,omitempty" json:"one,omitempty"`
    Two     string `toml:"two,omitempty" json:"two,omitempty"`
    Few     string `toml:"few,omitempty" json:"few,omitempty"`
    Many    string `toml:"many,omitempty" json:"many,omitempty"`

Entry is a single translatable entry.

func (Entry) Empty

func (e Entry) Empty() bool

Empty reports if all messages are empty.

type File

type File struct {
    // Is this a template file?
    Template bool `toml:"template,omitempty" json:"template,omitempty"`

    // Don't update with "z18n update"
    NoUpdate bool `toml:"no-update,omitempty" json:"no_update,omitempty"`

    // Updated date.
    Generated time.Time `toml:"generated,omitempty" json:"generated,omitempty"`

    // Language this is for.
    Language string `toml:"language" json:"language"`

    // Maintainer(s) of this file.
    Maintainers []string `toml:"maintainers" json:"maintainers"`

    // Comments for translators.
    Comments string `toml:"comments" json:"comments"`

    // CLI options; only if template=true.
    Options map[string]interface{} `toml:"options,omitempty" json:"options,omitempty"`

    // Translate strings.
    Strings Entries `toml:"strings" json:"strings"`

    // File path; used internally.
    Path string `toml:"-" json:"-"`

File is a translation file.

func FromTOML

func FromTOML(t string) (File, error)

FromTOML reads a message file from a TOML string.

func New

func New(fsys fs.FS, language string) (File, error)

TODO: what we really want is a new "Dir" type; would come in handy in a few other places too.

func ReadFile

func ReadFile(fsys fs.FS, path string) (File, error)

ReadFile reads a message file.

func (File) List

func (f File) List() (string, error)

List all entries in this file.

func (File) TOML

func (f File) TOML() (string, error)

TOML formats all entries as TOML.

TODO: Implement MarshalTOML instead.

func (*File) UnmarshalTOML

func (f *File) UnmarshalTOML(d interface{}) error

Custom unmarshal to treat __meta__ as special.

func (File) WriteTo

func (f File) WriteTo(path string) error

WriteTo writes out a message file.

v0.0.0-20220606095325-513ddb98b28f (latest)
Jun 6, 2022
21 packages (graph)
Last checked
1 week ago

Tools for package owners.