Documentation ¶
Overview ¶
bcp47 contains:
information correlating ISO 639 and ISO 3166 codes, see http://www.rfc-editor.org/rfc/bcp/bcp47.txt
translate Commands for translating words and phrases using Google APIs and caching the results to minimize future API calls.
iso3266-2.go source: https://en.wikipedia.org/wiki/ISO_3166-2 on February 28, 2022 I has to combine the subdivisions by hand.
iso639-2.go from the Library of Congress Standards https://www.loc.gov/standards/iso639-2/ISO-639-2_8859-1.txt downloaded on February 28, 2022.
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
- func CountryForIso3166(iso3166code string) string
- func CountryHasLanguage(country, language string) bool
- func HasColonialLanguage(country string) bool
- func HasLanguagesForCountry(country string) bool
- func IsCamelCase(s string) bool
- func IsEs419(country string) bool
- func Iso3166Countries() []string
- func Iso3166ForCountry(country string) string
- func Iso3166FromBcp47(bcp47 string) string
- func Iso639ForLanguage(language string) string
- func Iso639FromBcp47(bcp47 string) string
- func LanguageForCountry(country string) string
- func LanguageForIso639(iso639code string) string
- func WordsCheck(wordsDir string) error
- func WordsFilename(wordsDir, lang string) string
- func WordsGetLang(wordsDir, bcp47 string) (string, error)
- func WordsGetWords(wordsDir, bcp47 string) ([]string, error)
- func WordsHasLanguage(wordsDir, bcp47 string) bool
- func WordsLanguages(wordsDir string) ([]string, error)
- func WordsLanguagesMap(wordsDir string) (map[string]bool, error)
- func WordsMerge(toWordsDir, fromWordsDir string) error
- func WordsWriteWords(wordsDir, lang string, words []string) error
- func XlnsAdd(wordsDir, credentialsJson, mainLang string, newLangs []string) error
- func XlnsSupported(credentialsJson, lang string) error
- func XlnsUpdate(wordsDir, credentialsJson, mainLang string) error
- type Iso3166_2
- type Iso639_2
- type XlnsMap
- func (xm XlnsMap) Key() []string
- func (xm XlnsMap) Translate(source, target string) string
- func (xm XlnsMap) TranslateByLine(source string) string
- func (xm XlnsMap) TranslateByLineWithAlternate(source, altSource string, limit int) string
- func (xm XlnsMap) TranslateText(text string) string
- func (xm XlnsMap) TranslateWords(words []string) []string
Constants ¶
const (
PROJECT_ID = "project_id"
)
const (
RAW_ISO3166_2 = `` /* 9720-byte string literal not displayed */
)
const (
RAW_ISO639_2 = `` /* 15592-byte string literal not displayed */
)
const WORDS_SUFFIX = ".words"
Variables ¶
This section is empty.
Functions ¶
func CountryForIso3166 ¶
CountryForIso3166 returns the country name for the given ISO-3166 code. Will return "" if the code is not present.
func CountryHasLanguage ¶
CountryHasLanguage tells whether a language is spoken in the given country.
func HasColonialLanguage ¶
HasLanguagesForCountry returns whether or not a country has English, French, German, Dutch, or Spanish as a language.
func HasLanguagesForCountry ¶
HasLanguagesForCountry tells whether we have language information for the country.
func IsCamelCase ¶
IsCamelCase return true if the string is camelCase.
func IsEs419 ¶
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 ¶
Iso3166ForCountry returns the ISO-3166 code for a country. Will return "" if the country is not found.
func Iso3166FromBcp47 ¶
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 ¶
Iso639ForLanguage returns the ISO-639 code for a English name. Will return "" if the language is not found.
func Iso639FromBcp47 ¶
Iso639FromBcp47 extracts the ISO 639 language code from the BCP-47 code.
func LanguageForCountry ¶
LanguageForCountry returns the primary language for a country. Returns "" if unknown.
func LanguageForIso639 ¶
LanguageForIso639 return the first applicable English 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 ¶
WordsCheck does very simplistic verification that a wordsDir is consistent.
func WordsFilename ¶
WordsFilename returns the path of the words file for the given language.
func WordsGetLang ¶
WordsGetLang returns the words file language to use for locale 'bcp47'.
func WordsGetWords ¶
WordsGetWords returns the words for the given language.
func WordsHasLanguage ¶
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 ¶
WordsLanguages returns a list of ISO-639 or BCP-47 codes from the available words files.
func WordsLanguagesMap ¶
WordsLanguagesMap returns a map of language to bool for the languages in wordsDir.
func WordsMerge ¶
WordsMerge adds the words in fromWordsDir to toWordsDir. If toWordsDir has more languages than fromWordsDir it bails.
func WordsWriteWords ¶
WordsWriteWords writes the words for a language.
func XlnsSupported ¶
XlnsSupported outputs the list of Google Cloud Translate API supported languages.
func XlnsUpdate ¶
XlnsUpdate updates all meaning ordered words files based by translating from mainLang. It retranslates the whole file.
Types ¶
type Iso3166_2 ¶
type Iso3166_2 struct {
Code, Country, Subdivisions string
}
func Iso3166_2s_all ¶
func Iso3166_2s_all() []Iso3166_2
type Iso639_2 ¶
func Iso639_2_all ¶
func Iso639_2_all() []Iso639_2
Iso639_2_all returns all of the processed ISO 639-2 data.
type XlnsMap ¶
func NewXlnsMap ¶
TranslationMap takes two lists of words ordered by meaning and creates a map from the first to the second.
func WordsXlnsMap ¶
WordsXlnsMap creates an XlnsMap object for the given languages.
func XlnsMapFromFiles ¶
XlnsMapFromFiles creates a XlnsMap from the words files w1 and w2.
func (XlnsMap) Translate ¶
Translate a string using the translation map. Use target if there is no other tranlation.
func (XlnsMap) TranslateByLine ¶
TranslateByLine translates source looking for entire lines. If that fails it will translate by word (see TranslateText).
func (XlnsMap) TranslateByLineWithAlternate ¶
TranslateByLineWithAlternate translates like TranslateByLine but if the translation is too long translates alternative text instead.
func (XlnsMap) TranslateText ¶
TranslateText by word.
func (XlnsMap) TranslateWords ¶
TranslateWords translates a list of words. If there is no translation for a word it will be skipped.