bisu 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +7 -0
- data/generic.translatable.yml +17 -22
- data/lib/bisu.rb +3 -0
- data/lib/bisu/config.rb +9 -1
- data/lib/bisu/localizer.rb +6 -2
- data/lib/bisu/source/google_sheet.rb +3 -3
- data/lib/bisu/source/one_sky.rb +1 -1
- data/lib/bisu/source/url.rb +40 -0
- data/lib/bisu/version.rb +1 -1
- data/spec/fixtures/sample_json_response.json +19 -0
- data/spec/fixtures/{sample_one_sky_response.txt → sample_one_sky_response.json} +0 -0
- data/spec/fixtures/{sample_one_sky_response_with_bug.txt → sample_one_sky_response_with_bug.json} +0 -0
- data/spec/lib/bisu/config_spec.rb +11 -0
- data/spec/lib/bisu/{google_sheet_spec.rb → source/google_sheet_spec.rb} +0 -0
- data/spec/lib/bisu/{one_sky_spec.rb → source/one_sky_spec.rb} +2 -2
- data/spec/lib/bisu/source/url_spec.rb +33 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed28be32f24a03d0e812b3ad88980911bd4d13a
|
4
|
+
data.tar.gz: 13f1165c2bf416965c75e24553f5f2672a91f1ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e4ebf64ac0b36be4fa1f058347a7029a676986289a216120bc22f680c9bbcdca545660017f2da39a2a6a05f822c3cf110820ce579d8c20f149fb16257e3adc3
|
7
|
+
data.tar.gz: fb3ce272578ae914ca44b785a456dec185c87435a0abba11c1debb328e2dec1909bdf2d2648b40dda9b0030d63283b28120d16ac22db95f3b2347c84e3da181f
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
`Bisu` adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [1.7.0](https://github.com/hole19/bisu/releases/tag/v1.7.0)
|
6
|
+
Released on 2019/02/18
|
7
|
+
|
8
|
+
#### Added
|
9
|
+
- Adds support for a dictionary source from generic URL
|
10
|
+
|
11
|
+
## [1.6.0](https://github.com/hole19/bisu/releases/tag/v1.6.0)
|
12
|
+
Released on 2019/02/18
|
13
|
+
|
14
|
+
#### Added
|
15
|
+
- Merges changes from [Onfido's fork](https://github.com/onfido/bisu)
|
16
|
+
- Removes the restriction for keys to start with k
|
17
|
+
- Adds a strict mode to fail if there's any warning
|
18
|
+
|
5
19
|
## [1.5.0](https://github.com/hole19/bisu/releases/tag/v1.5.0)
|
6
20
|
Released on 2019/01/19
|
7
21
|
|
data/README.md
CHANGED
data/generic.translatable.yml
CHANGED
@@ -1,27 +1,22 @@
|
|
1
1
|
# supported types are iOS/Android/RoR
|
2
2
|
type: iOS
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
dictionary:
|
5
|
+
type: google_sheet
|
6
|
+
sheet_id: <GOOGLE-DRIVE-SHEET-ID>
|
7
|
+
keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
|
6
8
|
|
7
|
-
|
8
|
-
- path/to/file
|
9
|
-
|
10
|
-
|
9
|
+
translate:
|
10
|
+
- in: path/to/1st/file.translatable
|
11
|
+
out: path/to/%{locale}/strings.xml
|
12
|
+
out_en: path/to/default/strings.xml
|
13
|
+
- in: path/to/2nd/file.translatable
|
14
|
+
out: path/to/2nd-%{locale}/strings.xml
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
out_path: path/to/final-%{locale}/%{out_name}
|
20
|
-
out:
|
21
|
-
- locale: en
|
22
|
-
kb_language: english
|
23
|
-
path: path/to/default/%{out_name}
|
24
|
-
- locale: pt
|
25
|
-
kb_language: portuguese
|
26
|
-
- locale: pt-PT
|
27
|
-
kb_language: portuguese
|
16
|
+
languages:
|
17
|
+
- locale: en
|
18
|
+
language: en
|
19
|
+
- locale: en-US
|
20
|
+
language: en
|
21
|
+
- locale: pt
|
22
|
+
language: pt
|
data/lib/bisu.rb
CHANGED
@@ -7,6 +7,7 @@ require 'bisu/object_extension'
|
|
7
7
|
require 'bisu/config'
|
8
8
|
require 'bisu/source/google_sheet'
|
9
9
|
require 'bisu/source/one_sky'
|
10
|
+
require 'bisu/source/url'
|
10
11
|
require 'bisu/dictionary'
|
11
12
|
require 'bisu/localizer'
|
12
13
|
require 'bisu/version'
|
@@ -59,6 +60,8 @@ module Bisu
|
|
59
60
|
Bisu::Source::GoogleSheet.new(config[:sheet_id], config[:keys_column])
|
60
61
|
when "one_sky"
|
61
62
|
Bisu::Source::OneSky.new(config[:api_key], config[:api_secret], config[:project_id], config[:file_name])
|
63
|
+
when "url"
|
64
|
+
Bisu::Source::Url.new(config[:url])
|
62
65
|
end
|
63
66
|
|
64
67
|
source = source.to_i18
|
data/lib/bisu/config.rb
CHANGED
@@ -75,9 +75,17 @@ module Bisu
|
|
75
75
|
}
|
76
76
|
}
|
77
77
|
|
78
|
+
URL_STRUCT = {
|
79
|
+
type: Hash,
|
80
|
+
elements: {
|
81
|
+
url: { type: String }
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
78
85
|
DICTIONARY_STRUCT = {
|
79
86
|
"google_sheet" => GOOGLE_SHEET_STRUCT,
|
80
|
-
"one_sky" => ONE_SKY_STRUCT
|
87
|
+
"one_sky" => ONE_SKY_STRUCT,
|
88
|
+
"url" => URL_STRUCT
|
81
89
|
}
|
82
90
|
end
|
83
91
|
end
|
data/lib/bisu/localizer.rb
CHANGED
@@ -26,11 +26,15 @@ module Bisu
|
|
26
26
|
Logger.error("Parameter #{param} not found in translation for #{l[:key]} in #{language}")
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
|
+
unless t.gsub!(l[:match], process(localized))
|
31
|
+
Logger.warn("Could not find translation for #{l[:match]} in #{language}")
|
32
|
+
end
|
33
|
+
else
|
34
|
+
Logger.warn("Could not find translation for #{l[:match]} in #{language}")
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
|
-
t.scan(/\$([^\$\{]+)(?:\{(.+)\})?\$/) { |match| Logger.warn("Could not find translation for #{match[0]} in #{language}") }
|
34
38
|
unless @type.eql?(:ror)
|
35
39
|
t.scan(/%{[^}]+}/) { |match| Logger.error("Could not find translation param for #{match} in #{language}") }
|
36
40
|
end
|
@@ -19,7 +19,7 @@ module Bisu
|
|
19
19
|
kb = {}
|
20
20
|
raw["entry"].each do |entry|
|
21
21
|
unless (key = entry[@key_column]) && key = key.first
|
22
|
-
raise "Cannot find key column '#{@key_column}'"
|
22
|
+
raise "Bisu::Source::GoogleSheet: Cannot find key column '#{@key_column}'"
|
23
23
|
end
|
24
24
|
|
25
25
|
entry.select { |c| !non_language_columns.include?(c) }.each do |lang, texts|
|
@@ -44,13 +44,13 @@ module Bisu
|
|
44
44
|
data = http.get(uri.path, headers)
|
45
45
|
|
46
46
|
unless data.code.to_i == 200
|
47
|
-
raise "Cannot access sheet at #{uri} - HTTP #{data.code}"
|
47
|
+
raise "Bisu::Source::GoogleSheet: Cannot access sheet at #{uri} - HTTP #{data.code}"
|
48
48
|
end
|
49
49
|
|
50
50
|
begin
|
51
51
|
XmlSimple.xml_in(data.body, 'KeyAttr' => 'name')
|
52
52
|
rescue
|
53
|
-
raise "Cannot parse. Expected XML at #{uri}"
|
53
|
+
raise "Bisu::Source::GoogleSheet: Cannot parse. Expected XML at #{uri}"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
data/lib/bisu/source/one_sky.rb
CHANGED
@@ -47,7 +47,7 @@ module Bisu
|
|
47
47
|
request = Net::HTTP::Get.new(uri.request_uri)
|
48
48
|
response = http.request(request)
|
49
49
|
|
50
|
-
raise "OneSky: Http Error #{JSON.parse(response.body)}" if response.code.to_i >= 400
|
50
|
+
raise "Bisu::Source::OneSky: Http Error #{JSON.parse(response.body)}" if response.code.to_i >= 400
|
51
51
|
|
52
52
|
response.body
|
53
53
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Bisu
|
5
|
+
module Source
|
6
|
+
class Url
|
7
|
+
def initialize(url)
|
8
|
+
@url = url
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_i18
|
12
|
+
Logger.info("Downloading dictionary from #{@url}...")
|
13
|
+
|
14
|
+
file = get(@url)
|
15
|
+
hash = JSON.parse(file)
|
16
|
+
|
17
|
+
Logger.info("Found #{hash.count} languages.")
|
18
|
+
|
19
|
+
hash
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get(url)
|
25
|
+
uri = URI(url)
|
26
|
+
|
27
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
http.use_ssl = true
|
29
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
+
|
31
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
32
|
+
response = http.request(request)
|
33
|
+
|
34
|
+
raise "Bisu::Source::Url: Http Error #{response.body}" if response.code.to_i >= 400
|
35
|
+
|
36
|
+
response.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/bisu/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"en": {
|
3
|
+
"kConnectFacebook": "Connect with Facebook",
|
4
|
+
"kNoNoNoMr": "No, no, no. Mr %{name} not here"
|
5
|
+
},
|
6
|
+
"ja": {
|
7
|
+
"kConnectFacebook": "\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u3078\u63a5\u7d9a"
|
8
|
+
},
|
9
|
+
"fr": {
|
10
|
+
"kConnectFacebook": "Connexion par Facebook"
|
11
|
+
},
|
12
|
+
"de": {
|
13
|
+
"kConnectFacebook": "Mit Facebook verbinden"
|
14
|
+
},
|
15
|
+
"ko": {
|
16
|
+
"kConnectFacebook": "\ud398\uc774\uc2a4\ubd81\uc73c\ub85c \uc811\uc18d",
|
17
|
+
"kTwitterServer": "트위터 서버연결 실패. \\n잠시 후 재시도."
|
18
|
+
}
|
19
|
+
}
|
File without changes
|
data/spec/fixtures/{sample_one_sky_response_with_bug.txt → sample_one_sky_response_with_bug.json}
RENAMED
File without changes
|
@@ -53,6 +53,17 @@ describe Bisu::Config do
|
|
53
53
|
it { should eq({ type: "one_sky", api_key: "as387oavh48", api_secret: "bp0s5avo8a59", project_id: 328742, file_name: "file.json" }) }
|
54
54
|
end
|
55
55
|
|
56
|
+
context "when given a Url type dictionary" do
|
57
|
+
before do
|
58
|
+
hash[:dictionary] = {
|
59
|
+
type: "url",
|
60
|
+
url: "a_url"
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it { should eq({ type: "url", url: "a_url" }) }
|
65
|
+
end
|
66
|
+
|
56
67
|
context "when given an unknown type dictionary" do
|
57
68
|
before { hash[:dictionary] = { type: "i_dunno" } }
|
58
69
|
it { expect { config }.to raise_error /unknown dictionary type 'i_dunno'/i }
|
File without changes
|
@@ -6,7 +6,7 @@ describe Bisu::Source::OneSky do
|
|
6
6
|
let(:project_id) { 98765 }
|
7
7
|
let(:file_name) { "file456.json" }
|
8
8
|
|
9
|
-
let(:os_response) { File.read("spec/fixtures/sample_one_sky_response.
|
9
|
+
let(:os_response) { File.read("spec/fixtures/sample_one_sky_response.json") }
|
10
10
|
|
11
11
|
def stub_multilingual(status:, response:)
|
12
12
|
stub_request(:get, "https://platform.api.onesky.io/1/projects/#{project_id}/translations/multilingual").
|
@@ -37,7 +37,7 @@ describe Bisu::Source::OneSky do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when OneSky returns the newline bug" do
|
40
|
-
let(:os_response) { File.read("spec/fixtures/sample_one_sky_response_with_bug.
|
40
|
+
let(:os_response) { File.read("spec/fixtures/sample_one_sky_response_with_bug.json") }
|
41
41
|
|
42
42
|
it { expect { to_i18 }.not_to raise_error }
|
43
43
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
describe Bisu::Source::Url do
|
2
|
+
subject(:to_i18) { Bisu::Source::Url.new(url).to_i18 }
|
3
|
+
|
4
|
+
let(:url) { "https://in17n-08c12b370aeb6c66.herokuapp.com/documents/1/json?api_key=0320cd5d-1a51-4785-a832-a5bed8e62ed6" }
|
5
|
+
let(:os_response) { File.read("spec/fixtures/sample_json_response.json") }
|
6
|
+
|
7
|
+
def stub_url(status:, response:)
|
8
|
+
stub_request(:get, url).
|
9
|
+
to_return(:status => status, :body => response, :headers => {})
|
10
|
+
end
|
11
|
+
|
12
|
+
before { stub_url(status: 200, response: os_response) }
|
13
|
+
|
14
|
+
it { expect { to_i18 }.not_to raise_error }
|
15
|
+
|
16
|
+
it "returns an hash in i18 format" do
|
17
|
+
expect(to_i18).to eq({
|
18
|
+
"en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
|
19
|
+
"ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
|
20
|
+
"fr" => { "kConnectFacebook" => "Connexion par Facebook" },
|
21
|
+
"de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
|
22
|
+
"ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when get request to that URL raises an error" do
|
27
|
+
before { stub_url(status: 400, response: { error: "ups... not allowed!" }.to_json) }
|
28
|
+
|
29
|
+
it "raises that same error" do
|
30
|
+
expect { to_i18 }.to raise_error /not allowed/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bisu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joaoffcosta
|
@@ -92,19 +92,22 @@ files:
|
|
92
92
|
- lib/bisu/object_extension.rb
|
93
93
|
- lib/bisu/source/google_sheet.rb
|
94
94
|
- lib/bisu/source/one_sky.rb
|
95
|
+
- lib/bisu/source/url.rb
|
95
96
|
- lib/bisu/version.rb
|
96
97
|
- spec/fixtures/sample.translatable.yml
|
98
|
+
- spec/fixtures/sample_json_response.json
|
97
99
|
- spec/fixtures/sample_kb_public_info.html
|
98
100
|
- spec/fixtures/sample_kb_public_sheet.html
|
99
|
-
- spec/fixtures/sample_one_sky_response.
|
100
|
-
- spec/fixtures/sample_one_sky_response_with_bug.
|
101
|
+
- spec/fixtures/sample_one_sky_response.json
|
102
|
+
- spec/fixtures/sample_one_sky_response_with_bug.json
|
101
103
|
- spec/lib/bisu/config_spec.rb
|
102
104
|
- spec/lib/bisu/dictionary_spec.rb
|
103
|
-
- spec/lib/bisu/google_sheet_spec.rb
|
104
105
|
- spec/lib/bisu/localizer_spec.rb
|
105
106
|
- spec/lib/bisu/logger_spec.rb
|
106
107
|
- spec/lib/bisu/object_extension_spec.rb
|
107
|
-
- spec/lib/bisu/
|
108
|
+
- spec/lib/bisu/source/google_sheet_spec.rb
|
109
|
+
- spec/lib/bisu/source/one_sky_spec.rb
|
110
|
+
- spec/lib/bisu/source/url_spec.rb
|
108
111
|
- spec/lib/bisu_spec.rb
|
109
112
|
- spec/spec_helper.rb
|
110
113
|
homepage: https://github.com/hole19/bisu
|