Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mappings between various representation of languages #45

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,6 @@ func AllLanguagesWithLatinScript() []Language {
return allLanguagesWithScript(latin)
}

// GetLanguageFromIsoCode639_1 returns the language for the given
// ISO 639-1 code.
func GetLanguageFromIsoCode639_1(isoCode IsoCode639_1) Language {
for _, language := range AllLanguages() {
if language.IsoCode639_1() == isoCode {
return language
}
}
return -1
}

// GetLanguageFromIsoCode639_3 returns the language for the given
// ISO 639-3 code.
func GetLanguageFromIsoCode639_3(isoCode IsoCode639_3) Language {
for _, language := range AllLanguages() {
if language.IsoCode639_3() == isoCode {
return language
}
}
return -1
}

func allLanguagesWithScript(script alphabet) (languages []Language) {
for _, language := range AllLanguages() {
Expand Down
355 changes: 355 additions & 0 deletions mapping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,355 @@
package lingua

var stringToIsoCode639_1 = map[string]IsoCode639_1 {
"AF": AF,
"AR": AR,
"AZ": AZ,
"BE": BE,
"BG": BG,
"BN": BN,
"BS": BS,
"CA": CA,
"CS": CS,
"CY": CY,
"DA": DA,
"DE": DE,
"EL": EL,
"EN": EN,
"EO": EO,
"ES": ES,
"ET": ET,
"EU": EU,
"FA": FA,
"FI": FI,
"FR": FR,
"GA": GA,
"GU": GU,
"HE": HE,
"HI": HI,
"HR": HR,
"HU": HU,
"HY": HY,
"ID": ID,
"IS": IS,
"IT": IT,
"JA": JA,
"KA": KA,
"KK": KK,
"KO": KO,
"LA": LA,
"LG": LG,
"LT": LT,
"LV": LV,
"MI": MI,
"MK": MK,
"MN": MN,
"MR": MR,
"MS": MS,
"NB": NB,
"NL": NL,
"NN": NN,
"PA": PA,
"PL": PL,
"PT": PT,
"RO": RO,
"RU": RU,
"SK": SK,
"SL": SL,
"SN": SN,
"SO": SO,
"SQ": SQ,
"SR": SR,
"ST": ST,
"SV": SV,
"SW": SW,
"TA": TA,
"TE": TE,
"TH": TH,
"TL": TL,
"TN": TN,
"TR": TR,
"TS": TS,
"UK": UK,
"UR": UR,
"VI": VI,
"XH": XH,
"YO": YO,
"ZH": ZH,
"ZU": ZU,
}


var isoCode639_1ToLanguage = map[IsoCode639_1]Language {
AF: Afrikaans,
AR: Arabic,
AZ: Azerbaijani,
BE: Belarusian,
BG: Bulgarian,
BN: Bengali,
BS: Bosnian,
CA: Catalan,
CS: Czech,
CY: Welsh,
DA: Danish,
DE: German,
EL: Greek,
EN: English,
EO: Esperanto,
ES: Spanish,
ET: Estonian,
EU: Basque,
FA: Persian,
FI: Finnish,
FR: French,
GA: Irish,
GU: Gujarati,
HE: Hebrew,
HI: Hindi,
HR: Croatian,
HU: Hungarian,
HY: Armenian,
ID: Indonesian,
IS: Icelandic,
IT: Italian,
JA: Japanese,
KA: Georgian,
KK: Kazakh,
KO: Korean,
LA: Latin,
LG: Ganda,
LT: Lithuanian,
LV: Latvian,
MI: Maori,
MK: Macedonian,
MN: Mongolian,
MR: Marathi,
MS: Malay,
NB: Bokmal,
NL: Dutch,
NN: Nynorsk,
PA: Punjabi,
PL: Polish,
PT: Portuguese,
RO: Romanian,
RU: Russian,
SK: Slovak,
SL: Slovene,
SN: Shona,
SO: Somali,
SQ: Albanian,
SR: Serbian,
ST: Sotho,
SV: Swedish,
SW: Swahili,
TA: Tamil,
TE: Telugu,
TH: Thai,
TL: Tagalog,
TN: Tswana,
TR: Turkish,
TS: Tsonga,
UK: Ukrainian,
UR: Urdu,
VI: Vietnamese,
XH: Xhosa,
YO: Yoruba,
ZH: Chinese,
ZU: Zulu,
}

var stringToIsoCode639_3 = map[string]IsoCode639_3 {
"AFR": AFR,
"ARA": ARA,
"AZE": AZE,
"BEL": BEL,
"BEN": BEN,
"BOS": BOS,
"BUL": BUL,
"CAT": CAT,
"CES": CES,
"CYM": CYM,
"DAN": DAN,
"DEU": DEU,
"ELL": ELL,
"ENG": ENG,
"EPO": EPO,
"EST": EST,
"EUS": EUS,
"FAS": FAS,
"FIN": FIN,
"FRA": FRA,
"GLE": GLE,
"GUJ": GUJ,
"HEB": HEB,
"HIN": HIN,
"HRV": HRV,
"HUN": HUN,
"HYE": HYE,
"IND": IND,
"ISL": ISL,
"ITA": ITA,
"JPN": JPN,
"KAT": KAT,
"KAZ": KAZ,
"KOR": KOR,
"LAT": LAT,
"LAV": LAV,
"LIT": LIT,
"LUG": LUG,
"MAR": MAR,
"MKD": MKD,
"MON": MON,
"MRI": MRI,
"MSA": MSA,
"NLD": NLD,
"NNO": NNO,
"NOB": NOB,
"PAN": PAN,
"POL": POL,
"POR": POR,
"RON": RON,
"RUS": RUS,
"SLK": SLK,
"SLV": SLV,
"SNA": SNA,
"SOM": SOM,
"SOT": SOT,
"SPA": SPA,
"SQI": SQI,
"SRP": SRP,
"SWA": SWA,
"SWE": SWE,
"TAM": TAM,
"TEL": TEL,
"TGL": TGL,
"THA": THA,
"TSN": TSN,
"TSP": TSO,
"TUR": TUR,
"UKR": UKR,
"URD": URD,
"VIE": VIE,
"XHO": XHO,
"YOR": YOR,
"ZHO": ZHO,
"ZUL": ZUL,
}

var isoCode639_3ToLanguage = map[IsoCode639_3]Language {
AFR: Afrikaans,
ARA: Arabic,
AZE: Azerbaijani,
BEL: Belarusian,
BEN: Bengali,
BOS: Bosnian,
BUL: Bulgarian,
CAT: Catalan,
CES: Czech,
CYM: Welsh,
DAN: Danish,
DEU: German,
ELL: Greek,
ENG: English,
EPO: Esperanto,
EST: Estonian,
EUS: Basque,
FAS: Persian,
FIN: Finnish,
FRA: French,
GLE: Irish,
GUJ: Gujarati,
HEB: Hebrew,
HIN: Hindi,
HRV: Croatian,
HUN: Hungarian,
HYE: Armenian,
IND: Indonesian,
ISL: Icelandic,
ITA: Italian,
JPN: Japanese,
KAT: Georgian,
KAZ: Kazakh,
KOR: Korean,
LAT: Latin,
LAV: Latvian,
LIT: Lithuanian,
LUG: Ganda,
MAR: Marathi,
MKD: Macedonian,
MON: Mongolian,
MRI: Maori,
MSA: Malay,
NLD: Dutch,
NNO: Nynorsk,
NOB: Bokmal,
PAN: Punjabi,
POL: Polish,
POR: Portuguese,
RON: Romanian,
RUS: Russian,
SLK: Slovak,
SLV: Slovene,
SNA: Shona,
SOM: Somali,
SOT: Sotho,
SPA: Spanish,
SQI: Albanian,
SRP: Serbian,
SWA: Swahili,
SWE: Swedish,
TAM: Tamil,
TEL: Telugu,
TGL: Tagalog,
THA: Thai,
TSN: Tswana,
TSO: Tsonga,
TUR: Turkish,
UKR: Ukrainian,
URD: Urdu,
VIE: Vietnamese,
XHO: Xhosa,
YOR: Yoruba,
ZHO: Chinese,
ZUL: Zulu,
}

// GetLanguageFromIsoCode639_1 returns the language for the given
// ISO 639-1 code - string variant.
func GetLanguageFromIsoCode639_1String(code string) Language {
if val, ok := stringToIsoCode639_1[code]; ok {
if val, ok := isoCode639_1ToLanguage[val]; ok {
return val
}
}
return -1
}


// GetLanguageFromIsoCode639_3 returns the language for the given
// ISO 639-3 code - string variant.
func GetLanguageFromIsoCode639_3String(code string) Language {
if val, ok := stringToIsoCode639_3[code]; ok {
if val, ok := isoCode639_3ToLanguage[val]; ok {
return val
}
}
return -1
}

// GetLanguageFromIsoCode639_1 returns the language for the given
// ISO 639-1 code.
func GetLanguageFromIsoCode639_1(isoCode IsoCode639_1) Language {
if val, ok := isoCode639_1ToLanguage[isoCode]; ok {
return val
}
return -1
}

// GetLanguageFromIsoCode639_3 returns the language for the given
// ISO 639-3 code.
func GetLanguageFromIsoCode639_3(isoCode IsoCode639_3) Language {
if val, ok := isoCode639_3ToLanguage[isoCode]; ok {
return val
}
return -1
}
Loading