tongues 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/tongues.iml +48 -0
- data/.idea/vcs.xml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/lib/README.md +62 -0
- data/lib/generators/tongues/config/initializer_generator.rb +12 -0
- data/lib/generators/tongues/config/templates/initializer.rb +4 -0
- data/lib/tongues/api_connexion.rb +56 -0
- data/lib/tongues/config/config.yml +83 -0
- data/lib/tongues/config/configuration.rb +38 -0
- data/lib/tongues/core_ext/detection.rb +41 -0
- data/lib/tongues/core_ext/string.rb +5 -0
- data/lib/tongues/core_ext/symbol.rb +5 -0
- data/lib/tongues/tongue.rb +9 -0
- data/lib/tongues/version.rb +3 -0
- data/lib/tongues.rb +3 -0
- data/tongues.gemspec +26 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c01d2406d8e62879e24487277e65b9bd6b8b918
|
4
|
+
data.tar.gz: 48c801670c101004cdb47e9f2b0068e672cc6753
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb7262124da61929cb21dfd0a8fb13d31e837ac4fda7d30467787a0b90989e375faf2be76e20c254443ef14c915decf9fb6a7d13597356830d229cad0d889fb7
|
7
|
+
data.tar.gz: 7f0c3622c85b64927b1a6c9f2dbaa7e43e7de059d5943ec46883d8bf8c1ad60c0a9cf1c2715e54e0863ef1f15f3fe563128967761342183f99a6c2ba2fd29707
|
data/.gitignore
ADDED
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/tongues.iml" filepath="$PROJECT_DIR$/.idea/tongues.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
9
|
+
|
data/.idea/tongues.iml
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager">
|
13
|
+
<content url="file://$MODULE_DIR$" />
|
14
|
+
<orderEntry type="inheritedJdk" />
|
15
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="actionmailer (v4.0.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="actionpack (v4.0.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="activemodel (v4.0.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="activerecord (v4.0.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="activerecord-deprecated_finders (v1.0.3, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v4.0.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="arel (v4.0.2, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="atomic (v1.1.15, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="builder (v3.1.4, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="erubis (v2.7.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="hike (v1.2.3, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.9, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v0.4.3, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="mail (v2.5.4, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types (v1.25.1, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v4.7.5, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.9.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="polyglot (v0.3.4, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="rack (v1.5.2, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-test (v0.6.2, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rails (v3.2.17, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="railties (v4.0.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="sprockets (v2.11.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="sprockets-rails (v2.0.1, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v0.18.1, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.2.0, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="tilt (v1.4.1, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="treetop (v1.4.15, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v0.3.38, RVM: ruby-2.0.0-p247 [global]) [gem]" level="application" />
|
46
|
+
</component>
|
47
|
+
</module>
|
48
|
+
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 alexzicat
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Tongues
|
2
|
+
|
3
|
+
Language detection gem using detectlanguage.com api.
|
4
|
+
Returns the language of a string or a symbol.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'tongues'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install tongues
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
The gem installed, you need to generate the initializer file:
|
23
|
+
|
24
|
+
rails generate tongues:initializer
|
25
|
+
|
26
|
+
Add your detectlanguage.com api key inside config/initializers/tongues.rb:
|
27
|
+
|
28
|
+
Tongues.configure do |config|
|
29
|
+
require 'tongues'
|
30
|
+
config.api_key = ''
|
31
|
+
end
|
32
|
+
|
33
|
+
You are now ready to use the gem
|
34
|
+
|
35
|
+
"how you get a String language".tongue # => "ENGLISH"
|
36
|
+
"how you get a String language code".tongue_code # => "en"
|
37
|
+
"how you get the confidence in a language detection".tongue_confidence # => 15.09
|
38
|
+
|
39
|
+
"is this english".en? # => true
|
40
|
+
"is this english".english? # => true
|
41
|
+
|
42
|
+
:"how you get a Symbol language".tongue # => "ENGLISH"
|
43
|
+
:"how you get a Symbol language code".tongue_code # => "en"
|
44
|
+
:"how you get the confidence in a language detection".tongue_confidence # => 15.09
|
45
|
+
|
46
|
+
:"is this english".en? # => true
|
47
|
+
:"is this english".english? # => true
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# wtf_lang [![TravisCI](https://secure.travis-ci.org/nashby/wtf_lang.png?branch=master)](http://travis-ci.org/nashby/wtf_lang)
|
2
|
+
|
3
|
+
Can't stop dreaming about an easy language detector? Just use wtf_lang!
|
4
|
+
|
5
|
+
### Install
|
6
|
+
|
7
|
+
gem install wtf_lang
|
8
|
+
|
9
|
+
### Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'wtf_lang'
|
13
|
+
|
14
|
+
WtfLang::API.key = "your_api_key" # you can get it here http://detectlanguage.com/
|
15
|
+
|
16
|
+
"ruby is so awesome!".lang # => "en"
|
17
|
+
"ruby is so awesome!".full_lang # => "ENGLISH"
|
18
|
+
|
19
|
+
# numeric value between 0-1.0 that represents
|
20
|
+
# the confidence level in the language code for the given text.
|
21
|
+
"ruby is so awesome!".lang_confidence # => ["en", 0.15502742]
|
22
|
+
|
23
|
+
"ruby is so awesome!".en? # => true
|
24
|
+
"ruby is so awesome!".english? # => true
|
25
|
+
```
|
26
|
+
|
27
|
+
If you want to cache results to make less requests to google API, use variables
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
text = "ruby is so awesome!"
|
31
|
+
text.lang #=> "en"
|
32
|
+
text.full_lang #=> "english"
|
33
|
+
```
|
34
|
+
|
35
|
+
It works with symbols too!
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
:"ruby is so awesome!".lang # => "en"
|
39
|
+
```
|
40
|
+
|
41
|
+
### Contributing to wtf_lang
|
42
|
+
|
43
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
44
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
45
|
+
* Fork the project
|
46
|
+
* Start a feature/bugfix branch
|
47
|
+
* Commit and push until you are happy with your contribution
|
48
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
49
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
50
|
+
|
51
|
+
### Authors
|
52
|
+
|
53
|
+
#### [Contributors](http://github.com/nashby/wtf_lang/contributors)
|
54
|
+
- [Bernard Potocki](https://github.com/imanel)
|
55
|
+
|
56
|
+
[Vasiliy Ermolovich](http://github.com/nashby/)<br/>
|
57
|
+
|
58
|
+
### Copyright
|
59
|
+
|
60
|
+
Copyright (c) 2012 nashby. See LICENSE.txt for
|
61
|
+
further details.
|
62
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Tongues
|
4
|
+
class InitializerGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
desc 'This generator creates an initializer for the api key.'
|
8
|
+
def add_initializer
|
9
|
+
template 'initializer.rb', 'config/initializers/tongues.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
require 'tongues/tongue'
|
5
|
+
|
6
|
+
module Tongues
|
7
|
+
class ApiConnexion
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
## Detects the language for the text in params
|
12
|
+
def detect(text)
|
13
|
+
response = call_api(text)
|
14
|
+
|
15
|
+
if detection = parse_response(response)
|
16
|
+
lang_symbol = detection['language']
|
17
|
+
language = Tongues::Configuration.languages[lang_symbol]
|
18
|
+
confidence = detection['confidence']
|
19
|
+
Tongue.new(lang_symbol, language, confidence)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
## Returns the api key
|
24
|
+
def key
|
25
|
+
@key
|
26
|
+
end
|
27
|
+
|
28
|
+
## Modifies the api key
|
29
|
+
def key=(key)
|
30
|
+
@key = key
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
## Generates the URL to call
|
37
|
+
def self.url(text)
|
38
|
+
"#{Tongues::Configuration.api_url}?key=#{Tongues::Configuration.api_key}&q=#{parse_request(text)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
## Calls the API
|
42
|
+
def self.call_api(text)
|
43
|
+
Net::HTTP.get(URI.parse(url(text)))
|
44
|
+
end
|
45
|
+
|
46
|
+
## Parses the request text
|
47
|
+
def self.parse_request(text)
|
48
|
+
CGI.escape(text)
|
49
|
+
end
|
50
|
+
|
51
|
+
## Parses the response
|
52
|
+
def self.parse_response(response)
|
53
|
+
JSON.parse(response)['data']['detections'].first
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
correspondences:
|
2
|
+
af: AFRIKAANS
|
3
|
+
ar: ARABIC
|
4
|
+
az: AZERBAIJANI
|
5
|
+
be: BELARUSIAN
|
6
|
+
bg: BULGARIAN
|
7
|
+
bh: BIHARI
|
8
|
+
bn: BENGALI
|
9
|
+
ca: CATALAN
|
10
|
+
ceb: CEBUANO
|
11
|
+
chr: CHEROKEE
|
12
|
+
cs: CZECH
|
13
|
+
cy: WELSH
|
14
|
+
da: DANISH
|
15
|
+
de: GERMAN
|
16
|
+
dv: DHIVEHI
|
17
|
+
el: GREEK
|
18
|
+
en: ENGLISH
|
19
|
+
es: SPANISH
|
20
|
+
et: ESTONIAN
|
21
|
+
eu: BASQUE
|
22
|
+
fa: PERSIAN
|
23
|
+
fi: FINNISH
|
24
|
+
fil: TAGALOG
|
25
|
+
fr: FRENCH
|
26
|
+
ga: IRISH
|
27
|
+
gd: SCOTS_GAELIC
|
28
|
+
gl: GALICIAN
|
29
|
+
gu: GUJARATI
|
30
|
+
he: HEBREW
|
31
|
+
hi: HINDI
|
32
|
+
hmn: HMONG
|
33
|
+
hr: CROATIAN
|
34
|
+
ht: HAITIAN_CREOLE
|
35
|
+
hu: HUNGARIAN
|
36
|
+
hy: ARMENIAN
|
37
|
+
id: INDONESIAN
|
38
|
+
is: ICELANDIC
|
39
|
+
it: ITALIAN
|
40
|
+
iu: INUKTITUT
|
41
|
+
ja: JAPANESE
|
42
|
+
jw: JAVANESE
|
43
|
+
ka: GEORGIAN
|
44
|
+
km: KHMER
|
45
|
+
kn: KANNADA
|
46
|
+
ko: KOREAN
|
47
|
+
lg: GANDA
|
48
|
+
lif: LIMBU
|
49
|
+
lo: LAOTHIAN
|
50
|
+
lt: LITHUANIAN
|
51
|
+
lv: LATVIAN
|
52
|
+
mk: MACEDONIAN
|
53
|
+
ml: MALAYALAM
|
54
|
+
mr: MARATHI
|
55
|
+
ms: MALAY
|
56
|
+
mt: MALTESE
|
57
|
+
nb: NORWEGIAN
|
58
|
+
ne: NEPALI
|
59
|
+
nl: DUTCH
|
60
|
+
or: ORIYA
|
61
|
+
pa: PUNJABI
|
62
|
+
pl: POLISH
|
63
|
+
pt: PORTUGUESE
|
64
|
+
ro: ROMANIAN
|
65
|
+
ru: RUSSIAN
|
66
|
+
rw: KINYARWANDA
|
67
|
+
si: SINHALESE
|
68
|
+
sk: SLOVAK
|
69
|
+
sl: SLOVENIAN
|
70
|
+
sq: ALBANIAN
|
71
|
+
sr: SERBIAN
|
72
|
+
sv: SWEDISH
|
73
|
+
sw: SWAHILI
|
74
|
+
syr: SYRIAC
|
75
|
+
ta: TAMIL
|
76
|
+
te: TELUGU
|
77
|
+
th: THAI
|
78
|
+
tr: TURKISH
|
79
|
+
uk: UKRAINIAN
|
80
|
+
ur: URDU
|
81
|
+
vi: VIETNAMESE
|
82
|
+
yi: YIDDISH
|
83
|
+
zh: CHINESE
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Tongues
|
5
|
+
|
6
|
+
## Provides a convenient way to edit configuration
|
7
|
+
def self.configure(&block)
|
8
|
+
if block_given?
|
9
|
+
block.call(Configuration.instance)
|
10
|
+
else
|
11
|
+
Configuration.instance
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
include Singleton
|
17
|
+
|
18
|
+
## Returns the api url
|
19
|
+
def self.api_url
|
20
|
+
'http://ws.detectlanguage.com/0.2/detect'
|
21
|
+
end
|
22
|
+
|
23
|
+
## Returns the api key
|
24
|
+
def self.api_key
|
25
|
+
@@api_key
|
26
|
+
end
|
27
|
+
|
28
|
+
## Modifies the api_key
|
29
|
+
def self.api_key=(key)
|
30
|
+
@@api_key = key
|
31
|
+
end
|
32
|
+
|
33
|
+
## Returns a hash of supported languages
|
34
|
+
def self.languages
|
35
|
+
YAML::load(File.open('lib/tongues/config/config.yml'))['correspondences']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Tongues
|
2
|
+
module Detection
|
3
|
+
require 'tongues/api_connexion'
|
4
|
+
require 'tongues/config/configuration'
|
5
|
+
|
6
|
+
## Returns the full language name
|
7
|
+
def tongue
|
8
|
+
detect_tongue && detect_tongue.language
|
9
|
+
end
|
10
|
+
|
11
|
+
## Returns the language code
|
12
|
+
def tongue_code
|
13
|
+
detect_tongue && detect_tongue.lang_symbol
|
14
|
+
end
|
15
|
+
|
16
|
+
## Returns the confidence in language
|
17
|
+
def tongue_confidence
|
18
|
+
detect_tongue && detect_tongue.confidence
|
19
|
+
end
|
20
|
+
|
21
|
+
## Comparison to languages
|
22
|
+
Tongues::Configuration.languages.each do |lang_symbol, language|
|
23
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
24
|
+
def #{lang_symbol}?
|
25
|
+
language && language == "#{lang_symbol}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def #{language}?
|
29
|
+
full_language && full_language == "#{language}"
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
## Calls the api and returns the language
|
37
|
+
def detect_tongue
|
38
|
+
@tongue ||= Tongues::ApiConnexion.detect self.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/tongues.rb
ADDED
data/tongues.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tongues/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tongues'
|
8
|
+
spec.version = Tongues::VERSION
|
9
|
+
spec.authors = ['Alexandre Zicat']
|
10
|
+
spec.email = ['dev.alexzicat@gmail.com']
|
11
|
+
spec.description = %q{Small language detection gem using detectlanguage.com api. Heavily inspired by the wtf_lang gem}
|
12
|
+
spec.summary = %q{Small language detection gem}
|
13
|
+
spec.homepage = 'https://github.com/alexzicat'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake', '~> 0'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'rails', '~> 3.2', '>= 3.2.3'
|
25
|
+
spec.add_runtime_dependency 'json', '~> 0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tongues
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandre Zicat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.2.3
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.2'
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.2.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: json
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Small language detection gem using detectlanguage.com api. Heavily inspired
|
76
|
+
by the wtf_lang gem
|
77
|
+
email:
|
78
|
+
- dev.alexzicat@gmail.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- .gitignore
|
84
|
+
- .idea/encodings.xml
|
85
|
+
- .idea/misc.xml
|
86
|
+
- .idea/modules.xml
|
87
|
+
- .idea/scopes/scope_settings.xml
|
88
|
+
- .idea/tongues.iml
|
89
|
+
- .idea/vcs.xml
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/README.md
|
95
|
+
- lib/generators/tongues/config/initializer_generator.rb
|
96
|
+
- lib/generators/tongues/config/templates/initializer.rb
|
97
|
+
- lib/tongues.rb
|
98
|
+
- lib/tongues/api_connexion.rb
|
99
|
+
- lib/tongues/config/config.yml
|
100
|
+
- lib/tongues/config/configuration.rb
|
101
|
+
- lib/tongues/core_ext/detection.rb
|
102
|
+
- lib/tongues/core_ext/string.rb
|
103
|
+
- lib/tongues/core_ext/symbol.rb
|
104
|
+
- lib/tongues/tongue.rb
|
105
|
+
- lib/tongues/version.rb
|
106
|
+
- tongues.gemspec
|
107
|
+
homepage: https://github.com/alexzicat
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Small language detection gem
|
131
|
+
test_files: []
|
132
|
+
has_rdoc:
|