translate

package module
v0.0.0-...-8f05a37 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Unlicense Imports: 7 Imported by: 0

README

translate

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertSourceMessagesToTranslationUnits

func ConvertSourceMessagesToTranslationUnits(srcChan <-chan dotstrings.Message, tf *xliff.TranslationFile) (<-chan xliff.TranslationUnit, <-chan error)

ConvertSourceMessagesToTranslationUnits will convert a channel containing dotstrings Messages into XLIFF translation units. If the passed in translation file has a TargetLanguage set then a translation unit will also contain the Str field from the Message copied into Target field.

func ConvertTargetMessagesToTranslationUnits

func ConvertTargetMessagesToTranslationUnits(tgtChan <-chan dotstrings.Message, tf *xliff.TranslationFile) (<-chan xliff.TranslationUnit, <-chan error)

ConvertTargetMessagesToTranslationUnits will convert a channel containing dotstrings Messages into XLIFF translation units. If the passed in translation file has a TargetLanguage set then a translation unit will also contain the Str field from the Message copied into Target field.

func ConvertTranslationUnitsToSourceMessages

func ConvertTranslationUnitsToSourceMessages(xliffChan <-chan xliff.TranslationUnit) <-chan dotstrings.Message

ConvertTranslationUnitsToSourceMessages will take ID, Source and Note fields of a translation unit and create a message out of it where the Note is used as the Ctx, the ID as the ID and the Source as the Str. The channel of messages can then be save to a source .strings file.

func ConvertTranslationUnitsToTargetMessages

func ConvertTranslationUnitsToTargetMessages(xliffChan <-chan xliff.TranslationUnit) <-chan dotstrings.Message

ConvertTranslationUnitsToTargetMessages will take ID, Source and Target fields of a translation unit and create a message out of it where the Source is used as the Ctx, the ID as the ID and the Target as the Str. The channel of messages can then be save to a target .strings file.

func LoadLines

func LoadLines(srcFile io.Reader) (<-chan string, <-chan error)

LoadLines reads the text stream from io.Reader and outputs lines on a channel it returns. This function will run asynchronously and return before the whole text stream has been processed.

func SaveLines

func SaveLines(lineChan <-chan string, tgtFile io.Writer) (n int)

SaveLines will take a channel with text lines and stream them to writer in unix text format (i.e. adding a linefeed character after every line). The function will return when all lines have been written. The goroutine feeding lineChan should close the channel once it has finished. The closing of the channel indicates to SaveLines that it can finish too. The function then returns the number of lines it has written. Note that no BOM is being written to the tgtFile to indicate the encoding of the text stream (which is most likely utf-8).

func TranslateIDs

func TranslateIDs(srcChan <-chan string, translations map[string]dotstrings.Message, translationsFallback map[string]dotstrings.Message) <-chan string

TranslateIDs will translate a channel of strings where the strings are treated as IDs in a translation map. The translationsFallback map normally contains the original source language and is used to fill in the gaps where translations haven't been provided yet using strings from the source language. The idea being that it is better to show a string instead of an id.

func TranslateIDsFile

func TranslateIDsFile(srcFile io.Reader, translations map[string]dotstrings.Message, translationsFallback map[string]dotstrings.Message, tgtFile io.Writer) (n int, err error)

func TranslateMessages

func TranslateMessages(srcChan <-chan dotstrings.Message, translations map[string]dotstrings.Message) <-chan dotstrings.Message

TranslateMessages will translate the strings file entries it takes from srcReader and then using a translation it finds in the translations map assemble a translation and write it out as a strings file entry to dstWriter. In case there is no translation available for a source entry, it will write the source entry out to the destination and mark it as Fuzzy. While translating TranslateString will detect whether the original text to translate (Context) has changed between the entry found in the source and the entry on which the translation was based. In this case the translation is still written but marked as fuzzy and the context is also changed to the new contetx from the source entry.

func TranslateMessagesFile

func TranslateMessagesFile(srcFile io.Reader, translations map[string]dotstrings.Message, tgtFile io.Writer) (n int, err error)

func TranslateMessagesXLIFF

func TranslateMessagesXLIFF(srcChan <-chan dotstrings.Message, translations map[string]string) (<-chan dotstrings.Message, <-chan error)

TranslateMessagesXLIFF will asynchronously take a channel of dotstrings messages and then using the translations table (loaded from an XLIFF file) translate the messages and write the translated messages to another channel. This function returns 2 channels, a channel that gets the translated messages and a channel of error values that is used by this function to push an error onto before terminating. The error channel is one way of delivering errors from an asynchronously called function.

func TranslatePlistEntries

func TranslatePlistEntries(entryChan <-chan plist.Entry, translations map[string]dotstrings.Message) <-chan plist.Entry

func TranslatePlistFile

func TranslatePlistFile(srcFile io.Reader, translations map[string]dotstrings.Message, tgtFile io.Writer) (n int, err error)

func TranslateText

func TranslateText(srcChan <-chan string, translations map[string]dotstrings.Message) <-chan string

TranslateText will translate a channel of strings where the strings are treated as context values in the translations map. Note that translating this way does not handle situations where the Context of different translation units is the same. The last translation in the translation map will win out and shadow the other entries. FIXME: TranslateText does not handle the difference in escaping between lines

of text read from the srcChan and the translations map.

func TranslateTextFile

func TranslateTextFile(srcFile io.Reader, translations map[string]dotstrings.Message, tgtFile io.Writer) (n int, err error)

Types

This section is empty.

Directories

Path Synopsis
cmd
xliff
Usage: #Translate Read the strings from -in <file> .strings file, then translate them using the translation from -xlf <file> XLIFF file and write out to -out <file> .strings file.
Usage: #Translate Read the strings from -in <file> .strings file, then translate them using the translation from -xlf <file> XLIFF file and write out to -out <file> .strings file.

Jump to

Keyboard shortcuts

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