bisu 1.8.0 → 1.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2db1130663e6afdca1e4d1b22d34c5863db2f120cee81c1c802d69999b1c094b
4
- data.tar.gz: 6f0cfd04fd34bb489055eaa0211aa74691f50f32c5fb13d8b7a1559c68a0f25a
3
+ metadata.gz: fd090e1e936ebc979392e5ba1cb44657bf0c716fdadbc1566f3aafa8252ff3dd
4
+ data.tar.gz: 89b8897c02e0ef9eba1945c125b43e4dff1fc38db73017d2eeca8b3ebb16674c
5
5
  SHA512:
6
- metadata.gz: b2d8325f651a93ca9bc2edb7108af31ebc5d1e3d5e954c8a8890a1a7985d2afababe15166ca4d909984a0be453d6f6ad8965eb44b4e1588bd970bc0e3d9669af
7
- data.tar.gz: 67699cebd837fc150ae54b433fb3386d79617211ff988b64bca73d681cd8daaeb6202c1e84280d1cfcf39a906c0930272c9f5f237f8d1eb187d856b0494570af
6
+ metadata.gz: 521148f8d23cb2bc308eab074f90c2b964cee468a3fa65594504153d834b4878fd4b1dc9fcc96c7a04064e909b534bc6cafec49b199164d3b5d8310f215f8e36
7
+ data.tar.gz: a011abe84e8c72ef2ad755f64595141f03acbd7367b70c321fb867f059f3891debd4878545acfaa8bb7f59b5ea1562aae3683430d7613d05244249af6ce67315
data/.rspec CHANGED
@@ -1,5 +1,4 @@
1
1
  --color
2
2
  --format documentation
3
3
  --profile
4
- --drb
5
4
  --require spec_helper
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.7.3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
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.10.2](https://github.com/hole19/bisu/releases/tag/v1.10.2)
6
+ Released on 2021/08/30
7
+
8
+ #### Fixed
9
+ - Fixes bug where we were assuming "key" would always be the translations-key column title
10
+
11
+ ## [1.10.1](https://github.com/hole19/bisu/releases/tag/v1.10.1)
12
+ Released on 2021/08/30
13
+
14
+ #### Fixed
15
+ - Crash caused by an unexpected redirect
16
+
17
+ ## [1.10.0](https://github.com/hole19/bisu/releases/tag/v1.10.0)
18
+ Released on 2021/08/30
19
+
20
+ #### Fixed
21
+ - Google Spreadsheet option stopped working due to a change in the API. This version fixes that.
22
+
23
+ Note: You'll need a new setup. View README.
24
+
25
+ ## [1.9.0](https://github.com/hole19/bisu/releases/tag/v1.9.0)
26
+ Released on 2021/05/21
27
+
28
+ #### Added
29
+ - Adds a new option to surpress missing params when that's intentional: add "//ignore-params" to the end of the translation key
30
+
5
31
  ## [1.8.0](https://github.com/hole19/bisu/releases/tag/v1.8.0)
6
32
  Released on 2020/04/30
7
33
 
data/Gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.5.0'
2
+ ruby '2.7.3'
3
3
 
4
4
  gem 'safe_yaml', '~> 1.0'
5
5
  gem 'colorize', '~> 0.7'
6
- gem 'xml-simple', '~> 1.1'
7
6
 
8
7
  group :test do
9
8
  gem 'rake'
data/Gemfile.lock CHANGED
@@ -1,37 +1,37 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.7.0)
4
+ addressable (2.8.0)
5
5
  public_suffix (>= 2.0.2, < 5.0)
6
6
  colorize (0.8.1)
7
- crack (0.4.3)
8
- safe_yaml (~> 1.0.0)
9
- diff-lcs (1.3)
7
+ crack (0.4.5)
8
+ rexml
9
+ diff-lcs (1.4.4)
10
10
  hashdiff (1.0.1)
11
- public_suffix (4.0.3)
12
- rake (13.0.1)
13
- rspec (3.9.0)
14
- rspec-core (~> 3.9.0)
15
- rspec-expectations (~> 3.9.0)
16
- rspec-mocks (~> 3.9.0)
17
- rspec-core (3.9.1)
18
- rspec-support (~> 3.9.1)
19
- rspec-expectations (3.9.0)
11
+ public_suffix (4.0.6)
12
+ rake (13.0.3)
13
+ rexml (3.2.5)
14
+ rspec (3.10.0)
15
+ rspec-core (~> 3.10.0)
16
+ rspec-expectations (~> 3.10.0)
17
+ rspec-mocks (~> 3.10.0)
18
+ rspec-core (3.10.1)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-expectations (3.10.1)
20
21
  diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.9.0)
22
+ rspec-support (~> 3.10.0)
22
23
  rspec-its (1.3.0)
23
24
  rspec-core (>= 3.0.0)
24
25
  rspec-expectations (>= 3.0.0)
25
- rspec-mocks (3.9.1)
26
+ rspec-mocks (3.10.2)
26
27
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.9.0)
28
- rspec-support (3.9.2)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-support (3.10.2)
29
30
  safe_yaml (1.0.5)
30
31
  webmock (1.24.6)
31
32
  addressable (>= 2.3.6)
32
33
  crack (>= 0.3.2)
33
34
  hashdiff
34
- xml-simple (1.1.5)
35
35
 
36
36
  PLATFORMS
37
37
  ruby
@@ -43,10 +43,9 @@ DEPENDENCIES
43
43
  rspec-its
44
44
  safe_yaml (~> 1.0)
45
45
  webmock (~> 1.20)
46
- xml-simple (~> 1.1)
47
46
 
48
47
  RUBY VERSION
49
- ruby 2.5.0p0
48
+ ruby 2.7.3p183
50
49
 
51
50
  BUNDLED WITH
52
- 1.17.2
51
+ 2.2.26
data/README.md CHANGED
@@ -24,7 +24,7 @@ Usage
24
24
  1. Run: `bisu`
25
25
  1. That's it!*
26
26
 
27
- *given that someone already configured Bisu
27
+ \*_given that someone already configured Bisu_
28
28
 
29
29
  Setup your configuration file
30
30
  -----
@@ -66,13 +66,14 @@ Setup your configuration file
66
66
 
67
67
  1. First ["Publish to the web"](https://www.google.com/search?q=google+sheets+publish+to+web) your Google Sheet
68
68
  1. Share only the sheet that contains the translations
69
+ 1. Make sure you CSV format
69
70
  1. First column should contain the translation keys
70
71
  1. First row should contain the locale for each language
71
72
 
72
73
  ```
73
74
  dictionary:
74
75
  type: google_sheet
75
- sheet_id: <GOOGLE-DRIVE-SHEET-ID>
76
+ url: <GOOGLE-DRIVE-SHEET-CSV-URL>
76
77
  keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
77
78
  ```
78
79
 
data/bisu.gemspec CHANGED
@@ -18,7 +18,4 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_runtime_dependency 'safe_yaml', '~> 1.0'
20
20
  s.add_runtime_dependency 'colorize', '~> 0.7'
21
- s.add_runtime_dependency 'xml-simple', '~> 1.1'
22
-
23
- s.add_development_dependency 'webmock', '~> 1.20'
24
21
  end
@@ -3,7 +3,7 @@ type: iOS
3
3
 
4
4
  dictionary:
5
5
  type: google_sheet
6
- sheet_id: <GOOGLE-DRIVE-SHEET-ID>
6
+ url: <GOOGLE-DRIVE-SHEET-CSV-URL>
7
7
  keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
8
8
 
9
9
  translate:
data/lib/bisu/config.rb CHANGED
@@ -61,9 +61,9 @@ module Bisu
61
61
  type: Hash,
62
62
  elements: {
63
63
  type: { type: String },
64
- sheet_id: { type: String },
65
- keys_column: { type: String }
66
- }
64
+ url: { type: String },
65
+ keys_column: { type: String },
66
+ },
67
67
  }
68
68
 
69
69
  ONE_SKY_STRUCT = {
@@ -72,15 +72,15 @@ module Bisu
72
72
  api_key: { type: String },
73
73
  api_secret: { type: String },
74
74
  project_id: { type: Integer },
75
- file_name: { type: String }
76
- }
75
+ file_name: { type: String },
76
+ },
77
77
  }
78
78
 
79
79
  URL_STRUCT = {
80
80
  type: Hash,
81
81
  elements: {
82
- url: { type: String }
83
- }
82
+ url: { type: String },
83
+ },
84
84
  }
85
85
 
86
86
  DICTIONARY_STRUCT = {
@@ -32,15 +32,15 @@ module Bisu
32
32
  unless t.gsub!(l[:match], localized)
33
33
  Logger.warn("Could not find translation for #{l[:match]} in #{language}")
34
34
  end
35
+
36
+ unless @type.eql?(:ror) || l[:ignore_param_warn] == true
37
+ localized.scan(/%{[^}]+}/) { |match| Logger.error("Could not find translation param for #{match} in #{language}") }
38
+ end
35
39
  else
36
40
  Logger.warn("Could not find translation for #{l[:match]} in #{language}")
37
41
  end
38
42
  end
39
43
 
40
- unless @type.eql?(:ror)
41
- t.scan(/%{[^}]+}/) { |match| Logger.error("Could not find translation param for #{match} in #{language}") }
42
- end
43
-
44
44
  t
45
45
  end
46
46
 
@@ -57,7 +57,7 @@ module Bisu
57
57
  private
58
58
 
59
59
  def to_localize(text)
60
- all_matches = text.to_enum(:scan, /\$([^\$\{]+)(?:\{(.+)\})?\$/).map { Regexp.last_match }
60
+ all_matches = text.to_enum(:scan, /\$([^\$\{\/]+)(?:\{(.+)\})?(\/\/ignore-params)?\$/).map { Regexp.last_match }
61
61
  all_matches.map do |match|
62
62
  params = if match[2]
63
63
  params = match[2].split(",").map(&:strip).map do |param|
@@ -67,9 +67,12 @@ module Bisu
67
67
  Hash[params]
68
68
  end
69
69
 
70
- { match: match[0],
70
+ {
71
+ match: match[0],
71
72
  key: match[1],
72
- params: params || {} }
73
+ params: params || {},
74
+ ignore_param_warn: text.include?("//ignore-params")
75
+ }
73
76
  end
74
77
  end
75
78
 
@@ -1,64 +1,65 @@
1
1
  require "net/https"
2
- require "xmlsimple"
2
+ require "csv"
3
3
 
4
4
  module Bisu
5
5
  module Source
6
6
  class GoogleSheet
7
- def initialize(sheet_id, keys_column)
8
- @sheet_id = sheet_id
9
- @key_column = keys_column
7
+ def initialize(url, keys_column)
8
+ @url = url
9
+ @keys_column = keys_column
10
10
  end
11
11
 
12
12
  def to_i18
13
- raw = raw_data(@sheet_id)
13
+ Logger.info("Downloading Google Sheet from #{@url}...")
14
14
 
15
- Logger.info("Downloading dictionary from Google Sheet...")
15
+ csv = get_csv(@url)
16
16
 
17
- non_language_columns = ["id", "updated", "category", "title", "content", "link", @key_column]
17
+ hash = {}
18
18
 
19
- kb = {}
20
- raw["entry"].each do |entry|
21
- unless (key = entry[@key_column]) && key = key.first
22
- raise "Bisu::Source::GoogleSheet: Cannot find key column '#{@key_column}'"
23
- end
19
+ languages = csv.headers[1..]
20
+ languages.each { |lang| hash[lang] = {} }
24
21
 
25
- entry.select { |c| !non_language_columns.include?(c) }.each do |lang, texts|
26
- kb[lang] ||= {}
27
- kb[lang][key] = texts.first unless texts.first == {}
22
+ csv.each do |row|
23
+ languages.each do |lang|
24
+ hash[lang][row[@keys_column]] = row[lang] unless row[lang].nil?
28
25
  end
29
26
  end
30
27
 
31
28
  Logger.info("Google Sheet parsed successfully!")
32
- Logger.info("Found #{kb.count} languages.")
29
+ Logger.info("Found #{languages.count} languages.")
33
30
 
34
- kb
31
+ hash
35
32
  end
36
33
 
37
34
  private
38
35
 
39
- def xml_data(uri, headers=nil)
40
- uri = URI.parse(uri)
36
+ def get_csv(url)
37
+ data = get(url)
38
+
39
+ begin
40
+ CSV.parse(data, headers: true)
41
+ rescue StandardError => e
42
+ raise "Bisu::Source::GoogleSheet: Cannot parse. Expected CSV at #{url}: #{e}"
43
+ end
44
+ end
45
+
46
+ def get(url, max_redirects = 1)
47
+ raise "Bisu::Source::GoogleSheet: Too may redirects" if max_redirects == -1
48
+
49
+ uri = URI(url)
50
+
41
51
  http = Net::HTTP.new(uri.host, uri.port)
42
52
  http.use_ssl = true
43
53
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
- data = http.get(uri.path, headers)
45
54
 
46
- unless data.code.to_i == 200
47
- raise "Bisu::Source::GoogleSheet: Cannot access sheet at #{uri} - HTTP #{data.code}"
48
- end
55
+ request = Net::HTTP::Get.new(uri.request_uri)
56
+ response = http.request(request)
49
57
 
50
- begin
51
- XmlSimple.xml_in(data.body, 'KeyAttr' => 'name')
52
- rescue
53
- raise "Bisu::Source::GoogleSheet: Cannot parse. Expected XML at #{uri}"
54
- end
55
- end
58
+ return get(response['location'], max_redirects - 1) if response.is_a? Net::HTTPRedirection
59
+
60
+ raise "Bisu::Source::GoogleSheet: Http Error #{response.body}" if response.code.to_i >= 400
56
61
 
57
- def raw_data(sheet_id)
58
- Logger.info("Downloading Google Sheet...")
59
- sheet = xml_data("https://spreadsheets.google.com/feeds/worksheets/#{sheet_id}/public/full")
60
- url = sheet["entry"][0]["link"][0]["href"]
61
- xml_data(url)
62
+ response.body
62
63
  end
63
64
  end
64
65
  end
data/lib/bisu/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bisu
2
- VERSION = '1.8.0'
3
- VERSION_UPDATED_AT = '2020-04-30'
2
+ VERSION = '1.10.2'
3
+ VERSION_UPDATED_AT = '2021-08-30'
4
4
  end
data/lib/bisu.rb CHANGED
@@ -59,7 +59,7 @@ module Bisu
59
59
  source =
60
60
  case config[:type]
61
61
  when "google_sheet"
62
- Bisu::Source::GoogleSheet.new(config[:sheet_id], config[:keys_column])
62
+ Bisu::Source::GoogleSheet.new(config[:url], config[:keys_column])
63
63
  when "one_sky"
64
64
  Bisu::Source::OneSky.new(config[:api_key], config[:api_secret], config[:project_id], config[:file_name])
65
65
  when "url"
@@ -70,7 +70,7 @@ module Bisu
70
70
 
71
71
  save_to_path = options[:dictionary_save_path]
72
72
  if save_to_path && file = open_file(save_to_path, "w", false)
73
- file.write(source.to_json)
73
+ file.write(deep_force_encoding(source).to_json)
74
74
  file.flush
75
75
  file.close
76
76
  end
@@ -149,4 +149,15 @@ module Bisu
149
149
 
150
150
  true
151
151
  end
152
+
153
+ def deep_force_encoding(hash)
154
+ hash.each do |_, value|
155
+ case value
156
+ when String
157
+ value.force_encoding(Encoding::UTF_8)
158
+ when Hash
159
+ deep_force_encoding(value)
160
+ end
161
+ end
162
+ end
152
163
  end
@@ -2,8 +2,8 @@ type: iOS
2
2
 
3
3
  dictionary:
4
4
  type: google_sheet
5
- sheet_id: sheet-id
6
- keys_column: keys-column
5
+ url: sheet-public-url
6
+ keys_column: "key name"
7
7
 
8
8
  translate:
9
9
  - in: hole19/Localizable.strings.translatable
@@ -0,0 +1,4 @@
1
+ key name,en,ja,fr,de,ko
2
+ kConnectFacebook,Connect with Facebook,フェイスブックへ接続,Connexion par Facebook,Mit Facebook verbinden,페이스북으로 접속
3
+ kNoNoNoMr,"No, no, no. Mr %{name} not here",,,,
4
+ kTwitterServer,,,,,트위터 서버연결 실패. \n잠시 후 재시도.
@@ -4,24 +4,24 @@ describe Bisu::Config do
4
4
  let(:hash) { {
5
5
  type: "BisuOS",
6
6
  dictionary: {
7
- type: "google_sheet",
8
- sheet_id: "abc1234567890",
9
- keys_column: "key_name"
7
+ type: "google_sheet",
8
+ url: "https://abc1234567890",
9
+ keys_column: "key name",
10
10
  },
11
11
  translate: [
12
- { in: "path/to/file/to/1.ext.translatable",
13
- out: "path/to/final-%{locale}/1.ext",
12
+ { in: "path/to/file/to/1.ext.translatable",
13
+ out: "path/to/final-%{locale}/1.ext",
14
14
  out_en_us: "path/to/default/1.ext"
15
15
  },
16
- { in: "path/to/file/to/2.ext.translatable",
17
- out: "path/to/final-%{locale}/2.ext",
16
+ { in: "path/to/file/to/2.ext.translatable",
17
+ out: "path/to/final-%{locale}/2.ext",
18
18
  out_en_us: "path/to/default/2.ext"
19
19
  },
20
20
  ],
21
21
  languages: [
22
- { locale: "en-US", language: "english" },
23
- { locale: "pt", language: "portuguese" },
24
- { locale: "pt-PT", language: "portuguese" },
22
+ { locale: "en-US", language: "english" },
23
+ { locale: "pt", language: "portuguese" },
24
+ { locale: "pt-PT", language: "portuguese" },
25
25
  { locale: "pt-Batatas", language: "portuguese-bt", fallback_language: "portuguese" }
26
26
  ]
27
27
  } }
@@ -37,16 +37,16 @@ describe Bisu::Config do
37
37
  describe "#dictionary" do
38
38
  subject(:dictionary) { config.dictionary }
39
39
 
40
- it { should eq({ type: "google_sheet", sheet_id: "abc1234567890", keys_column: "key_name" }) }
40
+ it { should eq({ type: "google_sheet", url: "https://abc1234567890", keys_column: "key name" }) }
41
41
 
42
42
  context "when given a OneSky type dictionary" do
43
43
  before do
44
44
  hash[:dictionary] = {
45
- type: "one_sky",
46
- api_key: "as387oavh48",
45
+ type: "one_sky",
46
+ api_key: "as387oavh48",
47
47
  api_secret: "bp0s5avo8a59",
48
48
  project_id: 328742,
49
- file_name: "file.json"
49
+ file_name: "file.json"
50
50
  }
51
51
  end
52
52
 
@@ -57,7 +57,7 @@ describe Bisu::Config do
57
57
  before do
58
58
  hash[:dictionary] = {
59
59
  type: "url",
60
- url: "a_url"
60
+ url: "a_url"
61
61
  }
62
62
  end
63
63
 
@@ -1,4 +1,9 @@
1
1
  describe Bisu::Localizer do
2
+ def translates(text, fallbacks: [], to:, lang: nil)
3
+ translation = localizer.localize(text, lang || language, locale, fallbacks)
4
+ expect(translation).to eq to
5
+ end
6
+
2
7
  let(:language) { "Portuguese" }
3
8
  let(:locale) { "pt-PT" }
4
9
 
@@ -33,11 +38,6 @@ describe Bisu::Localizer do
33
38
  shared_examples_for "a localizer" do
34
39
  it { expect { localizer }.not_to raise_error }
35
40
 
36
- def translates(text, fallbacks: [], to:, lang: nil)
37
- translation = localizer.localize(text, lang || language, locale, fallbacks)
38
- expect(translation).to eq to
39
- end
40
-
41
41
  it { translates("a line with no key", to: "a line with no key") }
42
42
 
43
43
  it { translates("this special key: $specialKComment1$", to: "this special key: This file was automatically generated based on a translation template.") }
@@ -87,7 +87,7 @@ describe Bisu::Localizer do
87
87
  .and not_change { Bisu::Logger.summary[:error] }
88
88
  end
89
89
 
90
- it "throws an error when missing key parameters (expect on ruby on rails)" do
90
+ it "throws a error when missing key parameters (expect on ruby on rails)" do
91
91
  if type == :ror
92
92
  expect {
93
93
  localizer.localize("$k1ParameterKey$", language, locale)
@@ -114,6 +114,17 @@ describe Bisu::Localizer do
114
114
  }.to not_change { Bisu::Logger.summary[:warn] }
115
115
  .and change { Bisu::Logger.summary[:error] }.by(1)
116
116
  end
117
+
118
+ # non localizable text with params
119
+
120
+ it "does not try to translate params outside $$" do
121
+ translates("%{some_text}", to: "%{some_text}")
122
+
123
+ expect {
124
+ localizer.localize("%{some_text}", language, locale)
125
+ }.to not_change { Bisu::Logger.summary[:warn] }
126
+ .and not_change { Bisu::Logger.summary[:error] }
127
+ end
117
128
  end
118
129
 
119
130
  let(:type_dependent_defaults) { {
@@ -134,6 +145,33 @@ describe Bisu::Localizer do
134
145
  ) }
135
146
 
136
147
  it_behaves_like "a localizer"
148
+
149
+ context "when a parameter replacemnt was not defined" do
150
+ let(:line) { "1 parameter: $k1ParameterKey$" }
151
+ let(:expected) { "1 parameter: Não sabes nada %{name}" }
152
+
153
+ it { translates(line, to: expected) }
154
+
155
+ it "returns an error" do
156
+ expect {
157
+ localizer.localize(line, language, locale)
158
+ }.to not_change { Bisu::Logger.summary[:warn] }
159
+ .and change { Bisu::Logger.summary[:error] }.by(1)
160
+ end
161
+
162
+ context "when passing //ignore-params" do
163
+ let(:line) { "1 parameter: $k1ParameterKey//ignore-params$" }
164
+
165
+ it { translates(line, to: expected) }
166
+
167
+ it "does not return an error" do
168
+ expect {
169
+ localizer.localize(line, language, locale)
170
+ }.to not_change { Bisu::Logger.summary[:warn] }
171
+ .and not_change { Bisu::Logger.summary[:error] }
172
+ end
173
+ end
174
+ end
137
175
  end
138
176
 
139
177
  describe "of type Android" do
@@ -1,68 +1,43 @@
1
1
  describe Bisu::Source::GoogleSheet do
2
- subject(:to_i18) { Bisu::Source::GoogleSheet.new(sheet_id, key_column).to_i18 }
2
+ subject(:to_i18) { Bisu::Source::GoogleSheet.new(url, "key name").to_i18 }
3
3
 
4
- let(:sheet_id) { "abc1234567890" }
5
- let(:url_info) { "https://spreadsheets.google.com/feeds/worksheets/#{sheet_id}/public/full" }
6
- let(:url_sheet) { "https://spreadsheets.google.com/feeds/list/#{sheet_id}/od6/public/full" }
4
+ let(:url) { "https://docs.google.com/spreadsheets/d/e/2PACX-1vTm6yu_zfbxKizC-PvUE1HVFCsplmiyz0s0qLSIGeokA7KtS3BgtqaA79CsfYfPsXH6xzUaP8HDTcj8/pub?gid=0&single=true&output=csv" }
5
+ let(:response) { File.read("spec/fixtures/sample_google_response.csv") }
7
6
 
8
- let(:key_column) { "key_column" }
9
-
10
- context "when given a valid sheet" do
11
- let(:file_info) { File.read("spec/fixtures/sample_kb_public_info.html") }
12
- let(:file_sheet) { File.read("spec/fixtures/sample_kb_public_sheet.html") }
13
-
14
- before do
15
- stub_request(:get, url_info).to_return(:status => 200, :body => file_info, :headers => {})
16
- stub_request(:get, url_sheet).to_return(:status => 200, :body => file_sheet, :headers => {})
17
- end
18
-
19
- it do
20
- expect { to_i18 }.not_to raise_error
21
- end
22
-
23
- it "returns an hash in i18 format" do
24
- expect(to_i18).to eq({
25
- "english" => { "kConnectFacebook" => "Connect with Facebook", "kConnectEmail" => "Connect with Email" },
26
- "german" => { "kConnectFacebook" => "Mit Facebook verbinden", "kConnectEmail" => "Mit E-Mail verbinden" },
27
- "portuguese" => { "kConnectFacebook" => "Registar com Facebook", "kConnectEmail" => "Registar com Email" },
28
- "spanish" => { "kConnectFacebook" => "Conéctate con Facebook", "kConnectEmail" => "Conéctate con Email" },
29
- "french" => { "kConnectFacebook" => "Connecter Facebook" },
30
- "dutch" => { "kConnectFacebook" => "Facebook Verbinden", "kConnectEmail" => "Email Verbinden" },
31
- "korean" => { "kConnectFacebook" => "페이스북으로 접속", "kConnectEmail" => "이메일로 접속" },
32
- "japanese" => { "kConnectFacebook" => "フェイスブックへ接続", "kConnectEmail" => "電子メールアカウントに接続" }
33
- })
34
- end
7
+ def stub_url(status:, response:)
8
+ stub_request(:get, url).
9
+ to_return(:status => status, :body => response, :headers => {})
10
+ end
35
11
 
36
- context "but the key column is not present in the first sheet" do
37
- let(:key_column) { "expecting_another_key_column" }
12
+ before { stub_url(status: 200, response: response) }
38
13
 
39
- it do
40
- expect { to_i18 }.to raise_error /Cannot find key column/
41
- end
42
- end
14
+ it do
15
+ expect { to_i18 }.not_to raise_error
43
16
  end
44
17
 
45
- context "when given an inexistent sheet" do
46
- before { stub_request(:get, url_info).to_return(:status => 400, :body => "Not Found", :headers => {}) }
47
-
48
- it do
49
- expect { to_i18 }.to raise_error /Cannot access sheet/
50
- end
18
+ it "returns an hash in i18 format" do
19
+ expect(to_i18).to eq({
20
+ "en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
21
+ "ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
22
+ "fr" => { "kConnectFacebook" => "Connexion par Facebook" },
23
+ "de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
24
+ "ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
25
+ })
51
26
  end
52
27
 
53
- context "when given a private sheet" do
54
- before { stub_request(:get, url_info).to_return(:status => 302, :body => "<HTML></HTML>", :headers => {}) }
28
+ context "when given an inexistent sheet" do
29
+ before { stub_url(status: 400, response: "Not Found") }
55
30
 
56
31
  it do
57
- expect { to_i18 }.to raise_error /Cannot access sheet/
32
+ expect { to_i18 }.to raise_error /Http Error/
58
33
  end
59
34
  end
60
35
 
61
- context "when url content is not XML" do
62
- before { stub_request(:get, url_info).to_return(:status => 200, :body => "This is not XML; { this: \"is json\" }", :headers => {}) }
36
+ context "when url content is not CSV" do
37
+ before { stub_url(status: 200, response: "{\"asdsa\": \"This is a json\"}") }
63
38
 
64
39
  it do
65
- expect { to_i18 }.to raise_error /Cannot parse. Expected XML/
40
+ expect { to_i18 }.to raise_error /Cannot parse. Expected CSV/
66
41
  end
67
42
  end
68
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bisu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - joaoffcosta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
@@ -38,34 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.7'
41
- - !ruby/object:Gem::Dependency
42
- name: xml-simple
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
- - !ruby/object:Gem::Dependency
56
- name: webmock
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.20'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.20'
69
41
  description: Bisu manages your app iOS and Android localization files for you. No
70
42
  more copy+paste induced errors!
71
43
  email: joaostacosta@gmail.com
@@ -97,9 +69,8 @@ files:
97
69
  - lib/bisu/source/url.rb
98
70
  - lib/bisu/version.rb
99
71
  - spec/fixtures/sample.translatable.yml
72
+ - spec/fixtures/sample_google_response.csv
100
73
  - spec/fixtures/sample_json_response.json
101
- - spec/fixtures/sample_kb_public_info.html
102
- - spec/fixtures/sample_kb_public_sheet.html
103
74
  - spec/fixtures/sample_one_sky_response.json
104
75
  - spec/fixtures/sample_one_sky_response_with_bug.json
105
76
  - spec/lib/bisu/config_spec.rb
@@ -131,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
102
  - !ruby/object:Gem::Version
132
103
  version: '0'
133
104
  requirements: []
134
- rubygems_version: 3.1.2
105
+ rubygems_version: 3.1.6
135
106
  signing_key:
136
107
  specification_version: 4
137
108
  summary: A localization automation service
@@ -1 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gs='http://schemas.google.com/spreadsheets/2006'><id>https://spreadsheets.google.com/feeds/worksheets/abc1234567890/public/full</id><updated>2015-02-09T18:59:53.874Z</updated><category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#worksheet'/><title type='text'>H19: Translation Knowledge Base</title><link rel='alternate' type='application/atom+xml' href='https://docs.google.com/spreadsheets/d/abc1234567890/pubhtml'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/abc1234567890/public/full'/><link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/abc1234567890/public/full'/><link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/abc1234567890/public/full'/><author><name>anthony.douglas</name><email>anthony.douglas@hole19golf.com</email></author><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><entry><id>https://spreadsheets.google.com/feeds/worksheets/abc1234567890/public/full/od6</id><updated>2015-02-09T18:59:53.874Z</updated><category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#worksheet'/><title type='text'>Translations</title><content type='text'>Translations</content><link rel='http://schemas.google.com/spreadsheets/2006#listfeed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full'/><link rel='http://schemas.google.com/spreadsheets/2006#cellsfeed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/abc1234567890/od6/public/full'/><link rel='http://schemas.google.com/visualization/2008#visualizationApi' type='application/atom+xml' href='https://docs.google.com/spreadsheets/d/abc1234567890/gviz/tq?gid=0&amp;pub=1'/><link rel='http://schemas.google.com/spreadsheets/2006#exportcsv' type='text/csv' href='https://docs.google.com/spreadsheets/d/abc1234567890/export?gid=0&amp;format=csv'/><link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/abc1234567890/public/full/od6'/><gs:colCount>25</gs:colCount><gs:rowCount>665</gs:rowCount></entry></feed>
@@ -1 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'><id>https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full</id><updated>2015-02-09T18:59:53.874Z</updated><category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/><title type='text'>Translations</title><link rel='alternate' type='application/atom+xml' href='https://docs.google.com/spreadsheets/d/abc1234567890/pubhtml'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full'/><link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full'/><link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full'/><author><name>anthony.douglas</name><email>anthony.douglas@hole19golf.com</email></author><openSearch:totalResults>664</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><entry><id>https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full/cokwr</id><updated>2015-02-09T18:59:53.874Z</updated><category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/><title type='text'>kConnectFacebook</title><content type='text'>english: Connect with Facebook, german: Mit Facebook verbinden, portuguese: Registar com Facebook, spanish: Conéctate con Facebook, french: Connecter Facebook, dutch: Facebook Verbinden, korean: 페이스북으로 접속, japanese: フェイスブックへ接続, key_column_2: kConnectFacebook</content><link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full/cokwr'/><gsx:key_column>kConnectFacebook</gsx:key_column><gsx:english>Connect with Facebook</gsx:english><gsx:german>Mit Facebook verbinden</gsx:german><gsx:portuguese>Registar com Facebook</gsx:portuguese><gsx:spanish>Conéctate con Facebook</gsx:spanish><gsx:french>Connecter Facebook</gsx:french><gsx:dutch>Facebook Verbinden</gsx:dutch><gsx:korean>페이스북으로 접속</gsx:korean><gsx:japanese>フェイスブックへ接続</gsx:japanese></entry><entry><id>https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full/cpzh4</id><updated>2015-02-09T18:59:53.874Z</updated><category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/><title type='text'>kConnectEmail</title><content type='text'>english: Connect with Email, german: Mit E-Mail verbinden, portuguese: Registar com Email, spanish: Conéctate con Email, dutch: Email Verbinden, korean: 이메일로 접속, japanese: 電子メールアカウントに接続, key_column_2: kConnectEmail</content><link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/abc1234567890/od6/public/full/cpzh4'/><gsx:key_column>kConnectEmail</gsx:key_column><gsx:english>Connect with Email</gsx:english><gsx:german>Mit E-Mail verbinden</gsx:german><gsx:portuguese>Registar com Email</gsx:portuguese><gsx:spanish>Conéctate con Email</gsx:spanish><gsx:french></gsx:french><gsx:dutch>Email Verbinden</gsx:dutch><gsx:korean>이메일로 접속</gsx:korean><gsx:japanese>電子メールアカウントに接続</gsx:japanese></entry></feed>