xlns

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: BSD-2-Clause Imports: 16 Imported by: 1

Documentation

Overview

bcp47 contains:

information correlating ISO 639 and ISO 3166 codes,
see http://www.rfc-editor.org/rfc/bcp/bcp47.txt

iso3166 contains information about ISO 3166 country codes.

iso639 contains information about ISO 639 language and language group codes.

words provides information on what languages we have translations (words) for.

xlns.go Google Cloud API translate functions for words files.

Common translation tools.

Index

Constants

View Source
const (
	PROJECT_ID = "project_id"
)
View Source
const WORDS_SUFFIX = ".words"

Variables

This section is empty.

Functions

func CountryForIso3166

func CountryForIso3166(iso3166 string) string

CountryForIso3166 returns the country name for the given ISO-3166 code. Will return "" if the code is not present.

func CountryHasLanguage

func CountryHasLanguage(country, language string) bool

CountryHasLanguage tells whether a language is spoken in the given country.

func HasColonialLanguage

func HasColonialLanguage(country string) bool

HasLanguagesForCountry returns whether or not a country has English, French, German, Dutch, or Spanish as a language.

func HasLanguagesForCountry

func HasLanguagesForCountry(country string) bool

HasLanguagesForCountry tells whether we have language information for the country.

func IsEs419

func IsEs419(country string) bool

IsEs419 returns true if the given country is part of Spanish speaking Latin America. This helps with BCP-47 code es-419.

func Iso3166Countries

func Iso3166Countries() []string

Iso3166Countries returns the list of ISO-3166 countries.

func Iso3166ForCountry

func Iso3166ForCountry(country string) string

Iso3166ForCountry returns the ISO-3166 code for a country. Will return "" if the country is not found.

func Iso3166FromBcp47

func Iso3166FromBcp47(bcp47 string) string

Iso3166FromBcp47 extracts the ISO 3166 country code from the BCP-47 code if it exists. Note that in BCP-47 there are special codes that are not ISO 3166.

func Iso639ForLanguage

func Iso639ForLanguage(language string) string

Iso639ForLanguage returns the ISO-639 code for a language. Will return "" if the language is not found.

func Iso639FromBcp47

func Iso639FromBcp47(bcp47 string) string

Iso639FromBcp47 extracts the ISO 639 language code from the BCP-47 code.

func LanguageForCountry

func LanguageForCountry(country string) string

LanguageForCountry returns the primary language for a country. Returns "" if unknown.

func LanguageForIso639

func LanguageForIso639(iso639 string) string

LanguageForIso639 return the first applicable language name for the given ISO 639 code (some languages have more than one name). Will return "" if the code is not present.

func WordsCheck

func WordsCheck(wordsDir string) error

WordsCheck does very simplistic verification that a wordsDir is consistent.

func WordsFilename

func WordsFilename(wordsDir, iso639 string) string

WordsFilename returns the path of the words file for the given language.

func WordsGetWords

func WordsGetWords(wordsDir, iso639 string) ([]string, error)

WordsGetWords returns the words for the given language.

func WordsHasLanguage

func WordsHasLanguage(wordsDir, lang string) (bool, error)

WordsHasLanguage returns whether or not we have a translation words file for the given code. This used to check for strict ISO-639 languages and not be case sensitive.

func WordsLanguages

func WordsLanguages(wordsDir string) ([]string, error)

WordsLanguages returns a list of ISO-639 or BCP-47 codes from the available words files.

func WordsLanguagesMap added in v1.1.2

func WordsLanguagesMap(wordsDir string) (map[string]bool, error)

WordsLanguagesMap returns a map of language to bool for the languages in wordsDir.

func WordsMerge

func WordsMerge(toWordsDir, fromWordsDir string) error

WordsMerge adds the words in fromWordsDir to toWordsDir. If toWordsDir has more languages than fromWordsDir it bails.

func WordsWriteWords

func WordsWriteWords(wordsDir, iso639 string, words []string) error

WordsWriteWords writes the words for a language.

func XlnsAdd

func XlnsAdd(wordsDir, credentialsJson, mainLang string, newLangs []string) error

XlnsAdd adds new languages to a meaning ordered words directory.

func XlnsSupported

func XlnsSupported(credentialsJson, lang string) error

XlnsSupported outputs the list of Google Cloud Translate API supported languages.

func XlnsUpdate

func XlnsUpdate(wordsDir, credentialsJson, mainLang string) error

XlnsUpdate updates all meaning ordered words files based by translating from mainLang. It retranslates the whole file.

Types

type XlnsMap

type XlnsMap map[string]string

func NewXlnsMap

func NewXlnsMap(base1, base2 io.Reader) (XlnsMap, error)

TranslationMap takes two lists of words ordered by meaning and creates a map from the first to the second.

func WordsXlnsMap

func WordsXlnsMap(wordsDir, sourceIso639, targetIso639 string) (XlnsMap, error)

WordsXlnsMap creates an XlnsMap object for the given languages.

func XlnsMapFromFiles

func XlnsMapFromFiles(w1, w2 string) (XlnsMap, error)

XlnsMapFromFiles creates a XlnsMap from the files w1 and w2.

func (XlnsMap) Key

func (xm XlnsMap) Key() []string

Key returns the "key" words as a sorted slice.

func (XlnsMap) Translate

func (xm XlnsMap) Translate(source, target string) string

Translate a string using the translation map. Use target if there is no other tranlation.

func (XlnsMap) TranslateByLine

func (xm XlnsMap) TranslateByLine(source string) string

TranslateByLine translates source looking for entire lines. If that fails it will translate by word (see TranslateText).

func (XlnsMap) TranslateText

func (xm XlnsMap) TranslateText(text string) string

TranslateText by word.

func (XlnsMap) TranslateWords

func (xm XlnsMap) TranslateWords(words []string) []string

TranslateWords translates a list of words. If there is no translation for a word it will be skipped.

Jump to

Keyboard shortcuts

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