easy_translate 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,7 @@ module EasyTranslate
44
44
  params = base_params(text, options)
45
45
  params.add :format, (options[:html] ? 'html' : 'text')
46
46
  # for each to language, put all of the q's
47
+ to_lang = [to_lang] if to_lang.is_a?(String)
47
48
  to_lang.each do |tol|
48
49
  escaped_lang_pair = URI.escape "#{from_lang}|#{tol}"
49
50
  # because ruby let's us call .each on a string with newlines
@@ -137,13 +138,18 @@ module EasyTranslate
137
138
  response = http.get("#{path}?#{params.to_s}")
138
139
  response.body if response
139
140
  end
140
-
141
+
142
+ def index_func
143
+ return @index_func if @index_func
144
+ Array.instance_methods.include?(:key) ? :key : :index
145
+ end
146
+
141
147
  # a function used to get the lang code of any input.
142
148
  # can take -- :english, 'english', :en, 'en'
143
149
  def self.get_language(lang)
144
150
  return unless lang
145
151
  lang = lang.to_s
146
- lang = EasyTranslate::LANGUAGES.include?(lang) ? lang : EasyTranslate::LANGUAGES.index(lang)
152
+ lang = EasyTranslate::LANGUAGES.include?(lang) ? lang : EasyTranslate::LANGUAGES.send(index_func, lang)
147
153
  raise ArgumentError.new('please supply a valid language') unless lang
148
154
  lang
149
155
  end
@@ -1,5 +1,5 @@
1
1
  module EasyTranslate
2
2
 
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
 
5
5
  end
@@ -8,27 +8,28 @@ module EasyTranslate
8
8
 
9
9
  require 'easy_translate/param_builder'
10
10
  require 'easy_translate/translator'
11
-
11
+
12
12
  API_URL = 'ajax.googleapis.com'
13
13
  API_TRANSLATE_PATH = '/ajax/services/language/translate'
14
14
  API_DETECT_PATH = '/ajax/services/language/detect'
15
15
  API_VERSION = '1.0'
16
16
 
17
17
  LANGUAGES = { 'af' => 'afrikaans', 'sq' => 'albanian', 'ar' => 'arabic',
18
- 'hy' => 'armenian', 'az' => 'azerbaijani', 'eu' => 'basque', 'be' => 'belarusian',
19
- 'bg' => 'bulgarian', 'ca' => 'catalan', 'zh-CN' => 'chinese_simplified',
20
- 'zh-TW' => 'chinese_traditional', 'hr' => 'croatian', 'cs' => 'czech',
21
- 'da' => 'danish', 'nl' => 'dutch', 'en' => 'english', 'et' => 'estonian',
22
- 'tl' => 'filipino', 'fi' => 'finnish', 'fr' => 'french', 'gl' => 'galician',
23
- 'ka' => 'georgian', 'de' => 'german', 'el' => 'greek', 'ht' => 'haitian_creole',
24
- 'iw' => 'hebrew', 'hi' => 'hindi', 'hu' => 'hungarian', 'is' => 'icelandic',
25
- 'id' => 'indonesian', 'ga' => 'irish', 'it' => 'italian', 'ja' => 'japanese',
26
- 'ko' => 'korean', 'lv' => 'latvian', 'lt' => 'lithuanian', 'mk' => 'macedonian',
18
+ #'hy' => 'armenian', 'eu' => 'basque', 'az' => 'azerbaijani',
19
+ 'be' => 'belarusian', 'bg' => 'bulgarian', 'ca' => 'catalan',
20
+ 'zh-CN' => 'chinese_simplified', 'zh-TW' => 'chinese_traditional',
21
+ 'hr' => 'croatian', 'cs' => 'czech', 'da' => 'danish', 'nl' => 'dutch',
22
+ 'en' => 'english', 'et' => 'estonian', 'tl' => 'filipino', 'fi' => 'finnish',
23
+ 'fr' => 'french', 'gl' => 'galician', 'de' => 'german', # 'ka' => 'georgian',
24
+ 'el' => 'greek', 'ht' => 'haitian_creole', 'iw' => 'hebrew', 'hi' => 'hindi',
25
+ 'hu' => 'hungarian', 'is' => 'icelandic', 'id' => 'indonesian',
26
+ 'ga' => 'irish', 'it' => 'italian', 'ja' => 'japanese', 'ko' => 'korean',
27
+ 'lv' => 'latvian', 'lt' => 'lithuanian', 'mk' => 'macedonian',
27
28
  'ms' => 'malay', 'mt' => 'maltese', 'no' => 'norwegian', 'fa' => 'persian',
28
29
  'pl' => 'polish', 'pt' => 'portuguese', 'ro' => 'romanian', 'ru' => 'russian',
29
30
  'sr' => 'serbian', 'sk' => 'slovak', 'sl' => 'slovenian', 'es' => 'spanish',
30
31
  'sw' => 'swahili', 'sv' => 'swedish', 'th' => 'thai', 'tr' => 'turkish',
31
- 'uk' => 'ukrainian', 'ur' => 'urdu', 'vi' => 'vietnamese', 'cy' => 'welsh',
32
+ 'uk' => 'ukrainian', 'vi' => 'vietnamese', 'cy' => 'welsh', # 'ur' => 'urdu',
32
33
  'yi' => 'yiddish' }
33
-
34
+
34
35
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Crepezzi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-18 00:00:00 -04:00
17
+ date: 2010-06-24 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency