labels

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package labels offes types and functions to load and save XLIFF v1 and TYPO3 locallang XML files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Label

type Label struct {
	ID           string         `json:"id"`
	Translations []*Translation `json:"trans"`
}

Label is a single label, containing one or more translations

type Labels

type Labels struct {
	File      string   `json:"documentTitle"`
	Type      XMLType  `json:"format"`
	FromFile  string   `json:"-"`
	SrcXlif   *Xliff   `json:"-"`
	SrcLegacy *T3Root  `json:"-"`
	Languages []string `json:"languages"`
	Data      []*Label `json:"labels"`
}

Labels is the root object of all translations

func New

func New(name string) (*Labels, error)

New create a new Labels object for the given file That file should not exist yet, because its content will be overwritten upon the first save

func Open

func Open(src string) (*Labels, error)

Open creates a new Labels object with the content of the given file

func (*Labels) Save

func (l *Labels) Save() error

Save will marshal the labels to the given XML type and store its result to disk

type LangFile

type LangFile interface {
	Labels() *Labels
	IndentChar() string
}

LangFile describes a reader for Labels from a XML source

type LocallangConverter

type LocallangConverter struct {
	// contains filtered or unexported fields
}

LocallangConverter translates a Labels structure to a T3Root structure that can be marshalled to XML

func (*LocallangConverter) File

func (c *LocallangConverter) File() string

File returns the file name and path of the source

func (*LocallangConverter) XML

func (c *LocallangConverter) XML() LangFile

XML will convert the Labels in src into a LangFile

type T3Data

type T3Data struct {
	Type      string    `xml:"type,attr,omitempty"`
	Languages []*T3Lang `xml:"languageKey,omitempty"`
}

T3Data is the blocks of translations

type T3Label

type T3Label struct {
	Key     string `xml:"index,attr"`
	Content string `xml:",innerxml"`
}

T3Label is a singe label and key pair

func (*T3Label) MarshalXML

func (l *T3Label) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML will marshal a labels content to a XML element

type T3Lang

type T3Lang struct {
	Type     string     `xml:"type,attr,omitempty"`
	Language string     `xml:"index,attr,omitempty"`
	Labels   []*T3Label `xml:"label,omitempty"`
}

T3Lang is a list of labels for a single language

type T3Meta

type T3Meta struct {
	Type    string `xml:"type,attr,omitempty"`
	For     string `xml:"type,omitempty"`
	Content string `xml:"description,omitempty"`
}

T3Meta is the meta block of a legacy XML

type T3Root

type T3Root struct {
	XMLName    string  `xml:"T3locallang"`
	Meta       *T3Meta `xml:"meta,omitempty"`
	Data       *T3Data `xml:"data"`
	SourceFile string  `xml:"-"`
}

T3Root is the root element of a legacy XML

func (*T3Root) IndentChar added in v0.4.0

func (t *T3Root) IndentChar() string

IndentChar determines the string for indentation or XML tags

func (*T3Root) Labels

func (t *T3Root) Labels() *Labels

Labels returns all Labels of a XML

type Translation

type Translation struct {
	Content  string `json:"content"`
	Approved string `json:"approved"`
	Language string `json:"lng"`
}

Translation is the text of a label in the given language

type XMLType

type XMLType string

XMLType sets the type of XML schema a file has

const (
	// XMLXliffv1 is the new XLIF schema
	XMLXliffv1 XMLType = "xlf"
	// XMLLegacy is the old TYPO3 schema
	XMLLegacy XMLType = "xml"
)

type Xliff

type Xliff struct {
	SourceFile string
	Files      []*XliffRoot
}

Xliff is the root of all languages and labels

func (*Xliff) Labels

func (x *Xliff) Labels() *Labels

Labels converts a Xliff tree into a Labels tree

type XliffBody

type XliffBody struct {
	Units []*XliffUnit `xml:"trans-unit,omitempty"`
}

XliffBody contains the units of a Xliff document

type XliffConverter

type XliffConverter struct {
	// contains filtered or unexported fields
}

XliffConverter will convert a Xliff structure to struct Labels

func (*XliffConverter) File

func (c *XliffConverter) File() string

File determines the desired target file of this document

func (*XliffConverter) XML

func (c *XliffConverter) XML() LangFile

XML will return the Xliff structure of a Labels structure

type XliffFile

type XliffFile struct {
	SrcLang  string       `xml:"source-language,attr"`
	ToLang   string       `xml:"target-language,attr,omitempty"`
	Orig     string       `xml:"original,attr"`
	Datatype string       `xml:"datatype,attr"`
	Name     string       `xml:"product-name,attr,omitempty"`
	Date     string       `xml:"date,attr,omitempty"`
	Header   *XliffHeader `xml:"header,omitempty"`
	Body     *XliffBody   `xml:"body,omitempty"`
}

XliffFile is the actual root node of a Xliff document

type XliffHeader

type XliffHeader struct {
	Skl      string `xml:"skl,omitempty"`
	PhaseGrp string `xml:"phase-group,omitempty"`
	Glossary string `xml:"glossary,omitempty"`
	Ref      string `xml:"reference,omitempty"`
	CountGrp string `xml:"count-group,omitempty"`
	Tool     string `xml:"tool,omitempty"`
	PopGrp   string `xml:"pop-group,omitempty"`
	Note     string `xml:"note,omitempty"`

	// Non-standard, but common in TYPO3
	Type        string `xml:"type,omitempty"`
	Description string `xml:"description,omitempty"`
	AuthName    string `xml:"authorName,omitempty"`
	AuthMail    string `xml:"authorEmail,omitempty"`
	AuthCompany string `xml:"authorCompany,omitempty"`
	Generator   string `xml:"generator,omitempty"`
}

XliffHeader is a collection of common metadata

type XliffRoot

type XliffRoot struct {
	XMLName    string     `xml:"xliff"`
	Version    string     `xml:"version,attr,omitempty"`
	XMLNS      string     `xml:"xmlns,attr,omitempty"`
	File       *XliffFile `xml:"file,omitempty"`
	Language   string     `xml:"-"`
	SourceFile string     `xml:"-"`
}

XliffRoot is the virtual root node of a XML document

func (*XliffRoot) IndentChar added in v0.4.0

func (x *XliffRoot) IndentChar() string

IndentChar determines the string for indentation or XML tags

func (*XliffRoot) Labels

func (x *XliffRoot) Labels() *Labels

Labels in this implementation has no function, because the calling party handles the conversion

type XliffUnit

type XliffUnit struct {
	ID       string `xml:"id,attr,omitempty"`
	ResName  string `xml:"resname,attr,omitempty"`
	Approved string `xml:"approved,attr,omitempty"`
	Src      string `xml:"source"`
	To       string `xml:"target,omitempty"`
}

XliffUnit is a single ID + Content unit of a Xliff document

Jump to

Keyboard shortcuts

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