-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gen: same alias/language name lookup as in linguis
Includes generated code, to keep commits atomic. Consits of: - code generator for alias produces new API - retrofiting all clients to a new API - generated code data/aliases.go Signed-off-by: Alexander Bezzubov <bzz@apache.org>
- Loading branch information
Showing
4 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
package data | ||
|
||
// LanguagesByAlias keeps alias for different languages and use the name of the languages as an alias too. | ||
import "strings" | ||
|
||
// LanguagesByAliasMap keeps alias for different languages and use the name of the languages as an alias too. | ||
// All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores. | ||
var LanguagesByAlias = map[string]string{ | ||
var LanguagesByAliasMap = map[string]string{ | ||
{{range $alias, $language := . -}} | ||
"{{ $alias }}": {{ printf "%q" $language -}}, | ||
"{{ $alias }}": {{ printf "%q" $language -}}, | ||
{{end -}} | ||
} | ||
|
||
// LanguagesByAlias 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 LanguagesByAlias(langOrAlias string) (lang string, ok bool) { | ||
k := ConvertToAliasKey(langOrAlias) | ||
lang, ok = LanguagesByAliasMap[k] | ||
return | ||
} | ||
|
||
|
||
// ConvertToAliasKey converts language name to a key in LanguagesByAliasMap. | ||
// 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 | ||
} |