Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var FileLocators = map[string]FileLocator{ "LANG-NAME": LangNameLocator{identityMapper}, "3-CHAR-LANG-NAME": LangNameLocator{langCodeMapper2To3}, "3-CHAR-LOC-DIR": LocDirLocator{langCodeMapper2To3}, "LOC-DIR": LocDirLocator{identityMapper}}
var Formats = map[string]func() Format{ "KEYVALUEJSON": func() Format { return new(KeyValueJson) }, "FLATTENXMLTOJSON": func() Format { return new(FlattenXmlToJson) }}
factory methods for creating a format object
Functions ¶
This section is empty.
Types ¶
type FileLocator ¶
type FileLocator interface { // path - the path to the directory containing the translation files (or root of the tree for looking up the files) // lang - the language of the translation file // name - the name of the file (or base name) // ext - the extension of the file Find(path, lang, name, ext string) string List(path, name, ext string) (map[string]string, error) }
Strategy for creating the path to a translation file
type FlattenXmlToJson ¶
type FlattenXmlToJson struct {
// contains filtered or unexported fields
}
A format which takes nested xml that has the translations as the text of the leaf nodes since the xml can be nested and the nodes can have attributes, the path to the leaf node is encoded as the key of the Json. the format that is uploaded to transifex will be a valid Json key value formatted file
func (*FlattenXmlToJson) Clean ¶
func (f *FlattenXmlToJson) Clean(content []byte) ([]byte, string, error)
func (*FlattenXmlToJson) Ext ¶
func (f *FlattenXmlToJson) Ext() string
func (*FlattenXmlToJson) Init ¶
func (f *FlattenXmlToJson) Init(initParams map[string]interface{})
func (FlattenXmlToJson) Write ¶
func (f FlattenXmlToJson) Write(rootDir, langCode, srcLang, filename, translation string, fileLocator FileLocator) error
type Format ¶
type Format interface { // initialize the format with any extra paramaters available in the configuration Init(map[string]interface{}) // Returns the extension of the format files Ext() string // takes the raw data read from file // returns: // * cleaned bytes // * new i18nType - it is possible that the format decided that in order to make the format useable it needed to convert it to a new type // * an error or nil if no errors occurred Clean([]byte) ([]byte, string, error) // Write a new translation to the correct translation file // * rootDir - path to the root of the translation files directory tree // * langCode - the language code of the translation // * srcLang - the source language // * translation - the translation text // * fileLocator - strategy for creating the path to the translation file Write(rootDir, langCode, srcLang, filename, translation string, fileLocator FileLocator) error }
A Format is responsible for cleaning up the translation file. For example: * A json file with empty string key should be deleted * A json file with empty values should be converted to a string with a single space * An xml file with nested tags should be flattened
type KeyValueJson ¶
type KeyValueJson struct{}
func (KeyValueJson) Ext ¶
func (f KeyValueJson) Ext() string
func (*KeyValueJson) Init ¶
func (f *KeyValueJson) Init(initParams map[string]interface{})
func (KeyValueJson) Write ¶
func (f KeyValueJson) Write(rootDir, langCode, srcLang, filename, translation string, fileLocator FileLocator) error
type LangNameLocator ¶
type LangNameLocator struct {
// contains filtered or unexported fields
}
All translation files in same directory and have pattern: lang-name.ext
func (LangNameLocator) Find ¶
func (l LangNameLocator) Find(path, lang, name, ext string) string
type LocDirLocator ¶
type LocDirLocator struct {
// contains filtered or unexported fields
}
Locate translation file with a directory structure as follows: <root> -- en
-- name.<ext>
-- fr
-- name.<ext>
func (LocDirLocator) Find ¶
func (l LocDirLocator) Find(path, lang, name, ext string) string