Documentation
¶
Overview ¶
Package yamlfile implements reading and writing of YAML translation files.
The expected file format is a nested YAML map with string leaf values:
greeting: Hello nav: home: Home about: About
Rails i18n style (locale as the top-level key) is also supported:
en:
greeting: Hello
nav:
home: Home
Leaf values with empty strings are treated as untranslated. Non-string leaves (numbers, booleans, arrays) are passed through unchanged. The package preserves the source file structure and key order on round-trip.
Index ¶
- func SyncKeys(src, target *File)
- type Entry
- type File
- func (f *File) Get(path string) (string, bool)
- func (f *File) Keys() []string
- func (f *File) Marshal() ([]byte, error)
- func (f *File) Set(path, value string) bool
- func (f *File) SourceValues() map[string]string
- func (f *File) Stats() (int, int, float64)
- func (f *File) UntranslatedKeys() []string
- func (f *File) WriteFile(path string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
// Path is the dot-joined key path (e.g. "nav.home").
Path string
// Value is the current translation (empty = untranslated).
Value string
// Style is the original yaml scalar style for round-trip fidelity.
Style yaml.Style
}
Entry represents a single translatable leaf value.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a parsed YAML translation file.
func NewTranslationFile ¶
NewTranslationFile creates an empty target File with the same structure as srcFile but with all values cleared (ready for translation). The targetLocale is used when the source file uses Rails i18n style.
func (*File) Marshal ¶
Marshal serialises the file back to YAML, preserving the original structure and scalar styles.
func (*File) Set ¶
Set updates the value for the given path. Returns false if the path is not in the file.
func (*File) SourceValues ¶
SourceValues returns a map of path → value (for use as translation source).
func (*File) UntranslatedKeys ¶
UntranslatedKeys returns paths whose value is empty.