Skip to content

Commit

Permalink
Fixes bug where we were assuming "key" would always be the translatio…
Browse files Browse the repository at this point in the history
…ns-key column title
  • Loading branch information
joaoffcosta committed Aug 30, 2021
1 parent 486b877 commit 08a2d18
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Setup your configuration file
dictionary:
type: google_sheet
url: <GOOGLE-DRIVE-SHEET-CSV-URL>
keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
```

##### OneSky integration:
Expand Down
1 change: 1 addition & 0 deletions generic.translatable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type: iOS
dictionary:
type: google_sheet
url: <GOOGLE-DRIVE-SHEET-CSV-URL>
keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>

translate:
- in: path/to/1st/file.translatable
Expand Down
2 changes: 1 addition & 1 deletion lib/bisu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def i18n_for(config:, options:)
source =
case config[:type]
when "google_sheet"
Bisu::Source::GoogleSheet.new(config[:url])
Bisu::Source::GoogleSheet.new(config[:url], config[:keys_column])
when "one_sky"
Bisu::Source::OneSky.new(config[:api_key], config[:api_secret], config[:project_id], config[:file_name])
when "url"
Expand Down
1 change: 1 addition & 0 deletions lib/bisu/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def localize_files
elements: {
type: { type: String },
url: { type: String },
keys_column: { type: String },
},
}

Expand Down
5 changes: 3 additions & 2 deletions lib/bisu/source/google_sheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
module Bisu
module Source
class GoogleSheet
def initialize(url)
def initialize(url, keys_column)
@url = url
@keys_column = keys_column
end

def to_i18
Expand All @@ -20,7 +21,7 @@ def to_i18

csv.each do |row|
languages.each do |lang|
hash[lang][row["key"]] = row[lang] unless row[lang].nil?
hash[lang][row[@keys_column]] = row[lang] unless row[lang].nil?
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/sample.translatable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type: iOS
dictionary:
type: google_sheet
url: sheet-public-url
keys_column: "key name"

translate:
- in: hole19/Localizable.strings.translatable
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/sample_google_response.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
key,en,ja,fr,de,ko
key name,en,ja,fr,de,ko
kConnectFacebook,Connect with Facebook,フェイスブックへ接続,Connexion par Facebook,Mit Facebook verbinden,페이스북으로 접속
kNoNoNoMr,"No, no, no. Mr %{name} not here",,,,
kTwitterServer,,,,,트위터 서버연결 실패. \n잠시 후 재시도.
3 changes: 2 additions & 1 deletion spec/lib/bisu/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
dictionary: {
type: "google_sheet",
url: "https://abc1234567890",
keys_column: "key name",
},
translate: [
{ in: "path/to/file/to/1.ext.translatable",
Expand Down Expand Up @@ -36,7 +37,7 @@
describe "#dictionary" do
subject(:dictionary) { config.dictionary }

it { should eq({ type: "google_sheet", url: "https://abc1234567890" }) }
it { should eq({ type: "google_sheet", url: "https://abc1234567890", keys_column: "key name" }) }

context "when given a OneSky type dictionary" do
before do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/bisu/source/google_sheet_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe Bisu::Source::GoogleSheet do
subject(:to_i18) { Bisu::Source::GoogleSheet.new(url).to_i18 }
subject(:to_i18) { Bisu::Source::GoogleSheet.new(url, "key name").to_i18 }

let(:url) { "https://docs.google.com/spreadsheets/d/e/2PACX-1vTm6yu_zfbxKizC-PvUE1HVFCsplmiyz0s0qLSIGeokA7KtS3BgtqaA79CsfYfPsXH6xzUaP8HDTcj8/pub?gid=0&single=true&output=csv" }
let(:response) { File.read("spec/fixtures/sample_google_response.csv") }
Expand Down

0 comments on commit 08a2d18

Please sign in to comment.