gopkg.in/src-d/enry.v1@v1.7.3/internal/code-generator/assets/alias.go.tmpl (about)

     1  package data
     2  
     3  import "strings"
     4  
     5  // LanguageByAliasMap keeps alias for different languages and use the name of the languages as an alias too.
     6  // All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
     7  var LanguageByAliasMap = map[string]string{
     8  	{{range $alias, $language := . -}}
     9  		"{{ $alias }}":	{{ printf "%q" $language -}},
    10  	{{end -}}
    11  }
    12  
    13  // LanguageByAlias looks up the language name by it's alias or name.
    14  // It mirrors the logic of github linguist and is needed e.g for heuristcs.yml
    15  // that mixes names and aliases in a language field (see XPM example).
    16  func LanguageByAlias(langOrAlias string) (lang string, ok bool) {
    17  	k := convertToAliasKey(langOrAlias)
    18  	lang, ok = LanguageByAliasMap[k]
    19  	return
    20  }
    21  
    22  
    23  // convertToAliasKey converts language name to a key in LanguageByAliasMap.
    24  // Following
    25  //  - internal.code-generator.generator.convertToAliasKey()
    26  //  - GetLanguageByAlias()
    27  // conventions.
    28  // It is here to avoid dependency on "generate" and "enry" packages.
    29  func convertToAliasKey(langName string) string {
    30  	ak := strings.SplitN(langName, `,`, 2)[0]
    31  	ak = strings.Replace(ak, ` `, `_`, -1)
    32  	ak = strings.ToLower(ak)
    33  	return ak
    34  }