-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
51 lines (42 loc) · 1.86 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "yaml"
require "immosquare-translate"
namespace :immosquare_translate do
desc "Translate tasks"
namespace :sample do
##=============================================================##
## Load config keys from config_dev.yml
##=============================================================##
def load_config
path = "#{File.dirname(__FILE__)}/config_dev.yml"
abort("Error: config_dev.yml not found") if !File.exist?(path)
##=============================================================##
## Load config keys from config_dev.yml
##=============================================================##
dev_config = YAML.load_file(path)
abort("Error config_dev.yml is empty") if dev_config.nil?
ImmosquareTranslate.config do |config|
config.openai_api_key = dev_config["openai_api_key"]
end
end
##=============================================================##
## Translate the sample YAML file
## rake immosquare_translate:sample:translate_yml
##=============================================================##
desc "Translate the sample file"
task :translate_yml do
load_config
input_path = "#{File.dirname(__FILE__)}/spec/input/sample.en.yml"
ImmosquareTranslate::YmlTranslator.translate(input_path, "fr")
end
##=============================================================##
## Transalate text from English to French + fix spelling
## rake immosquare_translate:sample:translate
##=============================================================##
desc "Translate texts"
task :translate do
load_config
datas = ImmosquareTranslate::Translator.translate(["Bonjour mes ami", "O revoir", "je vais au supermarché", "je vais acheter des chaussettes"], "fr", ["en", "es", "fr", "it", "fr-ca"])
puts datas.inspect
end
end
end