0.01
No commit activity in last 3 years
No release in over 3 years
Language detection
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

LanguageSniffer

Find out what language a given file is.
This is a stripped down version of linguist

  • pure language detection, nothing else ...
  • no dependencies
  • no Github business logic

Language detection

Most languages are detected by their file extension. This is the fastest and most common situation. For script files, which are usually extensionless, we do "deep content inspection"™ and check the shebang of the file. Checking the file's contents may also be used for disambiguating languages. C, C++ and Obj-C all use .h files. Looking for common keywords, we are usually able to guess the correct language.

LanguageSniffer.detect("lib/language_sniffer.rb").language.name #=> "Ruby"

LanguageSniffer.detect("bin/language_sniffer").language.name #=> "Ruby"

You can also just pass :content and :path, no need to have a local file.

LanguageSniffer.detect("xxx/language_sniffer", :content => File.read('bin/language_sniffer)).language.name #=> "Ruby"

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

Installation

To get it, clone the repo and run Bundler to install its dependencies.

git clone https://github.com/grosser/language_sniffer.git
cd language_sniffer/
bundle install

To run the tests:

bundle exec rake test

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b detect-foo-language)
  3. Make your changes
  4. Run the tests (bundle install then bundle exec rake)
  5. Commit your changes (git commit -am "Added detection for the new Foo language")
  6. Push to the branch (git push origin detect-foo-language)
  7. Create a Pull Request from your branch.
  8. Promote it. Get others to drop in and +1 it.

Author

Original work by Github,
stripping and simplification by Michael Grosser