2017-06-08 10:28:36 +00:00
|
|
|
package data
|
2017-05-04 13:03:54 +00:00
|
|
|
|
2019-02-14 11:47:45 +00:00
|
|
|
import "strings"
|
|
|
|
|
|
|
|
// LanguageByAliasMap keeps alias for different languages and use the name of the languages as an alias too.
|
2017-05-29 08:05:16 +00:00
|
|
|
// All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
2019-02-14 11:47:45 +00:00
|
|
|
var LanguageByAliasMap = map[string]string{
|
2017-05-04 13:03:54 +00:00
|
|
|
{{range $alias, $language := . -}}
|
2019-02-14 11:47:45 +00:00
|
|
|
"{{ $alias }}": {{ printf "%q" $language -}},
|
2017-05-04 13:03:54 +00:00
|
|
|
{{end -}}
|
|
|
|
}
|
2019-02-14 11:47:45 +00:00
|
|
|
|
|
|
|
// LanguageByAlias looks up the language name by it's alias or name.
|
|
|
|
// It mirrors the logic of github linguist and is needed e.g for heuristcs.yml
|
|
|
|
// that mixes names and aliases in a language field (see XPM example).
|
|
|
|
func LanguageByAlias(langOrAlias string) (lang string, ok bool) {
|
|
|
|
k := convertToAliasKey(langOrAlias)
|
|
|
|
lang, ok = LanguageByAliasMap[k]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// convertToAliasKey converts language name to a key in LanguageByAliasMap.
|
|
|
|
// Following
|
|
|
|
// - internal.code-generator.generator.convertToAliasKey()
|
|
|
|
// - GetLanguageByAlias()
|
|
|
|
// conventions.
|
|
|
|
// It is here to avoid dependency on "generate" and "enry" packages.
|
|
|
|
func convertToAliasKey(langName string) string {
|
|
|
|
ak := strings.SplitN(langName, `,`, 2)[0]
|
|
|
|
ak = strings.Replace(ak, ` `, `_`, -1)
|
|
|
|
ak = strings.ToLower(ak)
|
|
|
|
return ak
|
|
|
|
}
|