google-translate-free 0.0.1 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61878476dbea93fa674c06ec15e5447c79d59534aac01e45767467dde0964186
4
- data.tar.gz: 3d46fe34808ad0391f7ddd3d43357fdaacb023270ab3e72e4e32f2a46a6c361b
3
+ metadata.gz: 4cc72fe0c76488b83866129f10701348e32119ea42b3dfd42ec535682e1afbd9
4
+ data.tar.gz: 75f4ff9e1e54ad9dbae00937d05d622b9ea080484c23fdc2acf9aaa2e83c5675
5
5
  SHA512:
6
- metadata.gz: 4b1d3d8c3af406f0b003dc47b9c723363051a149487608b1340b0ffffdcfd9aa7b2e024b96d0389c54b77a7ba079fb49a7da088b3a071f41e36223fd3414b4b7
7
- data.tar.gz: c6576a7a50fa7d15f1a9e02b2a404584b638ff547aab17aafdc387e43b682df4324d9a85afc6c49986ad1d8ad3a67307e7050748e975ed72257698ba117fc4da
6
+ metadata.gz: 041a4b9dae5ec62be5d6de6d1d667058f59a1aff9045024cbe0d09246245c806a6b7ba27cc41976eb675064550e1b484f7015f942763b06c02bcc65e1f9dad8b
7
+ data.tar.gz: 65f41fd1f0b04f752cfd0c4986953f1ed679624ba697e264865e79990ede898c99c6db7476ed9ee0eda6a8863db1b1c2d5c7ef20ba699579e53df911f206101e
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Changelog
data/README.md CHANGED
@@ -1 +1,97 @@
1
- # google-translate-free
1
+ # Google Translate Free
2
+
3
+ This repository is a robust translation service designed to help you with a variety of language-based features including direct translations, alternate translations, definitions, examples, transliterations, spelling suggestions, language detection, and highly relevant keyword suggestions.
4
+
5
+ Let's read the [documents](https://api.datpmt.com) before using it.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'google-translate-free', '~> 1.0'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install google-translate-free
22
+
23
+ ## Usage
24
+ To translate
25
+ ```ruby
26
+ Translate.translate('summer', :vi, :en)
27
+ # => "mùa hè"
28
+ ```
29
+ Without third params, Google Translate will auto-detect your source language.
30
+ ```ruby
31
+ Translate.translate('summer', :vi)
32
+ # => "mùa hè"
33
+ ```
34
+ For definitions
35
+ ```ruby
36
+ Translate.definitions('summer')
37
+ # =>
38
+ #[
39
+ # {
40
+ # :noun=>[
41
+ # ["The warmest season of the year, in the northern hemisphere from june to august and in the southern hemisphere from december to february.", "<b>summer</b> vacation.", nil],
42
+ # ["A horizontal bearing beam, especially one supporting joists or rafters.", nil, nil]
43
+ # ]
44
+ # },
45
+ # {
46
+ # :verb=>[
47
+ # ["Spend the summer in a particular place.", nil, nil]
48
+ # ]
49
+ # }
50
+ #]
51
+ ```
52
+ For examples
53
+ ```ruby
54
+ Translate.examples('summer')
55
+ # =>
56
+ #[
57
+ # "The plant flowers in late <b>summer</b>.",
58
+ # "The golden <b>summer</b> of her life.",
59
+ # "A long hot <b>summer</b>.",
60
+ # "<b>summer</b> vacation."
61
+ #]
62
+ ```
63
+ For transliteration
64
+ ```ruby
65
+ Translate.transliteration('summer')
66
+ # => "ˈsəmər"
67
+ ```
68
+ For spelling suggestions
69
+ ```ruby
70
+ Translate.suggest('summmer')
71
+ # => "summer"
72
+ ```
73
+ For language detection
74
+ ```ruby
75
+ Translate.detection('summer')
76
+ # => ["en", 0.93254006]
77
+ ```
78
+ For keyword suggestions
79
+ ```ruby
80
+ Translate.see_more('summers')
81
+ # => "summer"
82
+ ```
83
+
84
+ ## Contributors
85
+
86
+ - [datpmt](https://github.com/datpmt)
87
+
88
+ I welcome contributions to this project.
89
+
90
+ 1. Fork it.
91
+ 2. Create your feature branch (`git checkout -b your-feature`).
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
93
+ 4. Push to the branch (`git push origin your-feature`).
94
+ 5. Create a new pull request.
95
+
96
+ ## License
97
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -22,6 +22,7 @@ module Translate
22
22
  end
23
23
 
24
24
  def self.definitions(keyword)
25
+ validate_keyword(keyword)
25
26
  # [ preposition: [desc ex sysnonyms] ]
26
27
  uri = URI(url(:md, keyword, :auto))
27
28
  result = net_get(uri)[12]
@@ -32,7 +33,7 @@ module Translate
32
33
  {
33
34
  "#{pre}": preposition[1].map do |arr|
34
35
  code = arr.last
35
- [arr[0].capitalize, examples(keyword, code)&.first, synonyms(pre, keyword, code)]
36
+ [arr[0], examples(keyword, code)&.first, synonyms(pre, keyword, code)]
36
37
  end
37
38
  }
38
39
  end
@@ -53,6 +54,7 @@ module Translate
53
54
  end
54
55
 
55
56
  def self.examples(keyword, code = nil)
57
+ validate_keyword(keyword)
56
58
  uri = URI(url(:ex, keyword, :auto))
57
59
  result = net_get(uri)[13]
58
60
  return unless result
@@ -63,13 +65,13 @@ module Translate
63
65
  result[0].map { |ex| ex[0] if ex.last == code }.compact
64
66
  end
65
67
  last_rs.map do |ex|
66
- "#{ex.capitalize}."
68
+ "#{ex}."
67
69
  end
68
70
  end
69
71
 
70
- def self.transliteration(string)
71
- encode = encode_url(string)
72
- uri = URI(url(:rm, encode, :auto))
72
+ def self.transliteration(keyword)
73
+ validate_keyword(keyword)
74
+ uri = URI(url(:rm, keyword, :auto))
73
75
  net_get(uri)&.dig(0, 0, 3)
74
76
  end
75
77
 
@@ -81,8 +83,8 @@ module Translate
81
83
 
82
84
  def self.see_more(keyword)
83
85
  # ex [kids -> kid, tables -> table]
84
- encode = encode_url(keyword)
85
- uri = URI(url(:rw, encode, :auto))
86
+ validate_keyword(keyword)
87
+ uri = URI(url(:rw, keyword, :auto))
86
88
  net_get(uri)&.dig(14, 0, 0) || keyword
87
89
  end
88
90
 
@@ -115,4 +117,8 @@ module Translate
115
117
  def self.validate_language_code(from_lang, to_lang)
116
118
  TranslateLib::Validation.validate_language_code(from_lang, to_lang)
117
119
  end
120
+
121
+ def self.validate_keyword(keyword)
122
+ TranslateLib::Validation.validate_keyword(keyword)
123
+ end
118
124
  end
@@ -20,11 +20,19 @@ module TranslateLib
20
20
  raise_error!('Translate strings shorter than or equal to 5000 characters.') if string.length > 5000
21
21
  end
22
22
 
23
+ def self.validate_keyword(keyword)
24
+ raise_error!('keyword does not have a valid value.') unless single_word?(keyword)
25
+ end
26
+
23
27
  def self.validate_language_code(from_lang, to_lang)
24
28
  raise_error!('from_lang does not have a valid value.') unless ALLOW_LANGUAGE_CODE.include?(from_lang.to_s.downcase)
25
29
  raise_error!('to_lang does not have a valid value.') unless ALLOW_LANGUAGE_CODE.include?(to_lang.to_s.downcase)
26
30
  end
27
31
 
32
+ def self.single_word?(str)
33
+ !!(str =~ /^\p{L}+$/)
34
+ end
35
+
28
36
  def self.raise_error!(message)
29
37
  TranslateLib::Exception.raise_error!(message)
30
38
  end
metadata CHANGED
@@ -1,25 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-translate-free
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - datpmt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-05-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Google Translate Free
13
+ description: Translation service designed to help you with a variety of language-based
14
+ features including direct translations, alternate translations, definitions, examples,
15
+ transliterations, spelling suggestions, language detection, and highly relevant
16
+ keyword suggestions.
14
17
  email: datpmt.2k@gmail.com
15
18
  executables: []
16
19
  extensions: []
17
20
  extra_rdoc_files: []
18
21
  files:
19
- - CHANGELOG.MD
22
+ - CHANGELOG.md
20
23
  - LICENSE
21
24
  - README.md
22
- - lib/translate.rb
25
+ - lib/google-translate-free.rb
23
26
  - lib/translate_lib/exception.rb
24
27
  - lib/translate_lib/validation.rb
25
28
  homepage: https://rubygems.org/gems/google-translate-free
@@ -46,5 +49,5 @@ requirements: []
46
49
  rubygems_version: 3.2.3
47
50
  signing_key:
48
51
  specification_version: 4
49
- summary: Google Translate Free
52
+ summary: Supports APIs related to Google Translate and more!
50
53
  test_files: []
data/CHANGELOG.MD DELETED
File without changes