GitLab Dependency | Language Savant

GitLab Linguist build status

We use this library to detect blob languages, ignore binary files, suppress generated files in diffs and generate language breakdown graphs.


Language detection

Linguist defines the list of all languages known to GitHub in a yaml file. In order for a file to be highlighted, a language and lexer must be defined there.

Most languages are detected by their file extension. This is the fastest and most common situation.

For disambiguating between files with common extensions, we use a Bayesian classifier. For an example, this helps us tell the difference between .h files which could be either C, C++, or Obj-C.

In the actual GitHub app we deal with Grit::Blob objects. For testing, there is a simple FileBlob API."lib/linguist.rb") #=> "Ruby""bin/linguist") #=> "Ruby"

See lib/linguist/language.rb and lib/linguist/languages.yml.


The Language Graph you see on every repository is built by aggregating the languages of all repo’s blobs. The top language in the graph determines the project’s primary language. Collectively, these stats make up the Top Languages page.

The repository stats API can be used on a directory:

project = Linguist::Repository.from_directory(".")  #=> "Ruby"
project.languages      #=> { "Ruby" => 0.98, "Shell" => 0.02 }

These stats are also printed out by the binary. Try running linguist on itself:

$ bundle exec linguist lib/
100%  Ruby

Ignore vendored files

Checking other code into your git repo is a common practice. But this often inflates your project’s language stats and may even cause your project to be labeled as another language. We are able to identify some of these files and directories and exclude them."vendor/plugins/foo.rb").vendored? # => true

See Linguist::BlobHelper#vendored? and lib/linguist/vendor.yml.

Generated file detection

Not all plain text files are true source files. Generated files like minified js and compiled CoffeeScript can be detected and excluded from language stats. As an extra bonus, these files are suppressed in diffs."underscore.min.js").generated? # => true

See Linguist::Generated#generated?.

Installation is usually running the latest version of the github-linguist gem that is released on

But for development you are going to want to checkout out the source. To get it, clone the repo and run Bundler to install its dependencies.

git clone
cd linguist/
bundle install

To run the tests:

bundle exec rake test

Related Repositories



Language Savant. If your repository's language is being reported incorrectly, send us a pull request! ...



Elixir Internationalization library ...



Language Savant, Python clone of github/linguist. ...



An application to manage translations in Django models ...



Localization support for the Laravel framework ...

Top Contributors

josh tnm stevepiercy mislav vmg gjtorikian charliesome tmm1 randx piki paulcbetts jaxzin lparenteau rdeltour Uberi Caged Ziaw bfontaine matkoniecz dveeden secondplanet jowido kevinsawicki rtomayko scottjg stuarthalloway tclem upsuper leafo tucnak