easy_translation 0.1.0 → 0.1.1

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: 86508e13e9f69fa80bfc523efd3622941569a95bbc4b6e6fd61cd17ae22adc96
4
- data.tar.gz: f6bf8380f782eae7160ce518ee291f237ef82c90c753dabeefebb7ebf4a0e211
3
+ metadata.gz: be2971e686cb5ffeeff5c5f308740455a11d330e7a0384a74a5bc0613ff54e61
4
+ data.tar.gz: 107d7fca7d077ed6a80f78a2ab65a5c737849756d22745fb7abf9231618dbb47
5
5
  SHA512:
6
- metadata.gz: ad61827e760a711410be81d639d86e88f00868b56d122caa9696d2184972ba5688134282695b0b7aa8e8598511e979cc704b7551ecc83000efcb82995632235e
7
- data.tar.gz: f6e77dd8ceb6e460659cc94654803260588254fcc884e4ebd410b44653bc5571a9e319afcf2c8ffa4ea7a495bf53be1c9ea0aecd9d27a98c4fddbf87dbeac7c0
6
+ metadata.gz: 7447df9b792101e1a6c938934dc6cfc7a883dd6c5da86e929c59d577a082f7bbfd3a2306541e77152f6761331684392c0e1bcb2fd965eb95cd9adae28d18a8da
7
+ data.tar.gz: 551aa22b1977559470453ea59f1f062edd90c94105fef29778a4487b6d46096a70164cdccac0c6e39c8f4de33d78541637228496c0307dac1fd84e806110e354
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # EasyTranslation
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/easy_translation`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ easy_translation uses the ChatGPT API for providing two features.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ 1. To translate a single sentence into selected languages.
6
+ 2. To translate the values of YML file into selected languages.
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,13 +23,25 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ After the installation, first require the class in your file
26
27
 
27
- ## Development
28
+ require 'chat_gpt_service'
28
29
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+ then initialize the ChatGPT service with your API key
30
31
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+ chat_gpt = ChatGptService.new('your_api_key')
33
+
34
+ and then call the translate method on the string.
35
+
36
+ chat_gpt.translate('your_string', [array_of_languages])
37
+
38
+ this will return the translated string into the required languages.
39
+
40
+ or if you want to translate your YML file
41
+
42
+ chat_gpt.translate(your_file_object, [array_of_languages])
43
+
44
+ this will download the translated yml file.
32
45
 
33
46
  ## Contributing
34
47
 
@@ -14,7 +14,8 @@ class ChatGptService
14
14
  }
15
15
  end
16
16
 
17
- def translate(message)
17
+ def translate(message, languages)
18
+ message = set_messsage_for_translation(message, languages)
18
19
  body = {
19
20
  model: options[:model],
20
21
  messages: [{ role: 'user', content: message }]
@@ -26,4 +27,16 @@ class ChatGptService
26
27
  "Chat gpt sent an invalid response #{e.message}"
27
28
  end
28
29
  end
30
+
31
+ private
32
+
33
+ def set_messsage_for_translation(message, languages)
34
+ message = if message.is_a? String
35
+ "Translate this #{message} into these languages #{languages}"
36
+ else
37
+ file_data = YAML.load(File.read(message.path))
38
+ "Translate only the values after the colon sign, in string into these languages #{languages} and return response in the standard .yml format #{file_data}"
39
+ end
40
+ message
41
+ end
29
42
  end
@@ -1,3 +1,3 @@
1
1
  module EasyTranslation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ayishm.aziz@xprolabs.com
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-27 00:00:00.000000000 Z
11
+ date: 2023-04-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: