Add GetLanguageID function

The Linguist-defined language IDs are important to our use case because they are
used as database identifiers. This adds a new generator to extract the language
IDs into a map and uses that to implement GetLanguageID.

Because one language has the ID 0, there is no way to tell if a language name is
found or not. If desired, we could add this by returning (string, bool) from
GetLanguageID. But none of the other functions that take language names do this,
so I didn't want to introduce it here.
This commit is contained in:
Luke Francl
2021-04-13 11:49:21 -07:00
parent 7f5d84ad74
commit eb043e80a8
7 changed files with 676 additions and 0 deletions

View File

@ -490,6 +490,14 @@ func GetLanguageExtensions(language string) []string {
return data.ExtensionsByLanguage[language]
}
// GetLanguageID returns the ID for the language. IDs are assigned by GitHub.
//
// NOTE: The zero value (0) is a valid language ID, so this API has no way to
// distinguish an invalid language name and a match on the language with ID 0.
func GetLanguageID(language string) int {
return data.IDByLanguage[language]
}
// Type represent language's type. Either data, programming, markup, prose, or unknown.
type Type int