39 lines
781 B
Go
39 lines
781 B
Go
package iso639
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
)
|
|
|
|
// GetLanguageNameForISO639Code tries get the language name for an ISO 639-1, ISO 639-2/B or ISO 639-2/T code
|
|
func GetLanguageNameForISO639Code(s string) (string, error) {
|
|
languageName, err := GetLanguageNameForISO639_1Code(s)
|
|
if err == nil {
|
|
return languageName, nil
|
|
}
|
|
|
|
languageName, err = GetLanguageNameForISO639_2BCode(s)
|
|
if err == nil {
|
|
return languageName, nil
|
|
}
|
|
|
|
languageName, err = GetLanguageNameForISO639_2TCode(s)
|
|
if err == nil {
|
|
return languageName, nil
|
|
}
|
|
|
|
return "", fmt.Errorf("no language name found for ISO 639 code: %s", s)
|
|
}
|
|
|
|
func getAllKeysOfMap(m map[string]string) []string {
|
|
keys := make([]string, 0, len(m))
|
|
|
|
for key := range m {
|
|
keys = append(keys, key)
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
return keys
|
|
}
|