easy_translation 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -6
- data/lib/chat_gpt_service.rb +14 -1
- data/lib/easy_translation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be2971e686cb5ffeeff5c5f308740455a11d330e7a0384a74a5bc0613ff54e61
|
4
|
+
data.tar.gz: 107d7fca7d077ed6a80f78a2ab65a5c737849756d22745fb7abf9231618dbb47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7447df9b792101e1a6c938934dc6cfc7a883dd6c5da86e929c59d577a082f7bbfd3a2306541e77152f6761331684392c0e1bcb2fd965eb95cd9adae28d18a8da
|
7
|
+
data.tar.gz: 551aa22b1977559470453ea59f1f062edd90c94105fef29778a4487b6d46096a70164cdccac0c6e39c8f4de33d78541637228496c0307dac1fd84e806110e354
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# EasyTranslation
|
2
2
|
|
3
|
-
|
3
|
+
easy_translation uses the ChatGPT API for providing two features.
|
4
4
|
|
5
|
-
|
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
|
-
|
26
|
+
After the installation, first require the class in your file
|
26
27
|
|
27
|
-
|
28
|
+
require 'chat_gpt_service'
|
28
29
|
|
29
|
-
|
30
|
+
then initialize the ChatGPT service with your API key
|
30
31
|
|
31
|
-
|
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
|
|
data/lib/chat_gpt_service.rb
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|