From f54317b3bd2ad079fca8be3aff6ec7fdd1e76fb7 Mon Sep 17 00:00:00 2001 From: Sharipov Ruslan Date: Mon, 24 Oct 2016 11:04:29 +0600 Subject: [PATCH 1/4] RU: add translations for late/early fees --- .../converters/check_in_out_fees.rb | 53 ++++++++++++++----- .../mappers/roomorama_property.rb | 14 +++-- .../converters/check_in_out_fees.rb | 31 ++++++++--- .../mappers/roomorama_property_spec.rb | 33 ++++++++++-- 4 files changed, 105 insertions(+), 26 deletions(-) diff --git a/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb b/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb index 106fa37cf..5b933011b 100644 --- a/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb +++ b/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb @@ -4,8 +4,19 @@ module Converters # # This class converts property's check-in and check-out fee rules to text. class CheckInOutFees - LATE_ARRIVAL_FEES_TITLE = "* Late arrival fees:" - EARLY_DEPARTURE_FEES_TITLE = "* Early departure fees:" + SUPPORTED_LOCALES = %i(en zh de es) + LATE_ARRIVAL_FEES_TITLE = { + en: "* Late arrival fees:", + zh: "* 晚到费用:", + de: "* Gebühren für späte Ankunft:", + es: "* Penalización por retraso en la llegada:" + } + EARLY_DEPARTURE_FEES_TITLE = { + en: "* Early departure fees:", + zh: "* 提早离店费用:", + de: "* Gebühren für frühe Abreise:", + es: "* La comisión a aplicar por salida anticipada:" + } # Initialize +RentalsUnited::Converters::CheckInOutFees+ # @@ -19,7 +30,17 @@ def initialize(ru_property, currency) @currency = currency end - # Output format: + # Output hash format: + # + # { + # en: "en tranlation", + # de: "de tranlation", + # zh: "zh tranlation", + # es: "es tranlation" + # } + # + # Translation for every lang is presented as string in the next format: + # # * Late arrival fees:\n # - 20:00 - 00:00 : $10\n # - 00:00 - 05:00 : $20\n @@ -28,36 +49,44 @@ def initialize(ru_property, currency) # - 13:00 - 15:00 : $10\n # - 11:00 - 13:00 : $20\n # - .. - def as_text + # + # If there is no any fees, method returns `nil` + def build_tranlations return nil if empty_fees? - [ - formatted_late_arrival_fees, - formatted_early_departure_fees - ].compact.join("\n") + hash = {} + SUPPORTED_LOCALES.each { |locale| hash[locale] = localize_fees(locale) } + hash end private attr_reader :late_arrival_fees, :early_departure_fees, :currency + def localize_fees(lang) + [ + formatted_late_arrival_fees(lang), + formatted_early_departure_fees(lang) + ].compact.join("\n") + end + def empty_fees? (late_arrival_fees + early_departure_fees).empty? end - def formatted_late_arrival_fees + def formatted_late_arrival_fees(lang) return nil unless late_arrival_fees.any? [ - LATE_ARRIVAL_FEES_TITLE, + LATE_ARRIVAL_FEES_TITLE[lang], formatted_rules(late_arrival_fees) ].join("\n") end - def formatted_early_departure_fees + def formatted_early_departure_fees(lang) return nil unless early_departure_fees.any? [ - EARLY_DEPARTURE_FEES_TITLE, + EARLY_DEPARTURE_FEES_TITLE[lang], formatted_rules(early_departure_fees) ].join("\n") end diff --git a/lib/concierge/suppliers/rentals_united/mappers/roomorama_property.rb b/lib/concierge/suppliers/rentals_united/mappers/roomorama_property.rb index 2b5121043..45231326c 100644 --- a/lib/concierge/suppliers/rentals_united/mappers/roomorama_property.rb +++ b/lib/concierge/suppliers/rentals_united/mappers/roomorama_property.rb @@ -64,7 +64,6 @@ def build_roomorama_property property.number_of_single_beds = ru_property.number_of_single_beds property.number_of_double_beds = ru_property.number_of_double_beds property.number_of_sofa_beds = ru_property.number_of_sofa_beds - property.description_append = description_append property.country_code = country_code(location) property.currency = location.currency property.city = location.city @@ -91,6 +90,7 @@ def build_roomorama_property set_security_deposit!(property) set_rates!(property) set_cleaning!(property) + set_description_append!(property) Result.new(property) end @@ -149,8 +149,16 @@ def country_code(location) Converters::CountryCode.code_by_name(location.country) end - def description_append - Converters::CheckInOutFees.new(ru_property, location.currency).as_text + def set_description_append!(property) + converter = Converters::CheckInOutFees.new(ru_property, location.currency) + tranlations = converter.build_tranlations + + if tranlations + property.description_append = tranlations.fetch(:en) + property.zh.description_append = tranlations.fetch(:zh) + property.de.description_append = tranlations.fetch(:de) + property.es.description_append = tranlations.fetch(:es) + end end def supported_property_type? diff --git a/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb b/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb index 69b8536d9..de6b7ddc4 100644 --- a/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb +++ b/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb @@ -53,9 +53,14 @@ module RentalsUnited let(:currency) { "EUR" } let(:subject) { described_class.new(ru_property, currency) } - it "converts fee rules to text" do - expect(subject.as_text).to eq( - "* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR" + it "converts fee rules to hash" do + expect(subject.build_tranlations).to eq( + { + en: "* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR", + zh: "* 晚到费用:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* 提早离店费用:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR", + de: "* Gebühren für späte Ankunft:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* Gebühren für frühe Abreise:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR", + es: "* Penalización por retraso en la llegada:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* La comisión a aplicar por salida anticipada:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR" + } ) end @@ -63,8 +68,13 @@ module RentalsUnited let(:early_departure_fees) { [] } it "converts fee rules to text when there is no late fees" do - expect(subject.as_text).to eq( - "* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR" + expect(subject.build_tranlations).to eq( + { + en: "* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR", + zh: "* 晚到费用:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR", + de: "* Gebühren für späte Ankunft:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR", + es: "* Penalización por retraso en la llegada:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR" + } ) end end @@ -73,8 +83,13 @@ module RentalsUnited let(:late_arrival_fees) { [] } it "converts fee rules to text when there is no late fees" do - expect(subject.as_text).to eq( - "* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR" + expect(subject.build_tranlations).to eq( + { + en: "* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR", + zh: "* 提早离店费用:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR", + de: "* Gebühren für frühe Abreise:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR", + es: "* La comisión a aplicar por salida anticipada:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR" + } ) end end @@ -84,7 +99,7 @@ module RentalsUnited let(:early_departure_fees) { [] } it "returns nil" do - expect(subject.as_text).to be_nil + expect(subject.build_tranlations).to eq(nil) end end end diff --git a/spec/lib/concierge/suppliers/rentals_united/mappers/roomorama_property_spec.rb b/spec/lib/concierge/suppliers/rentals_united/mappers/roomorama_property_spec.rb index 916ff202b..b6574641c 100644 --- a/spec/lib/concierge/suppliers/rentals_united/mappers/roomorama_property_spec.rb +++ b/spec/lib/concierge/suppliers/rentals_united/mappers/roomorama_property_spec.rb @@ -401,12 +401,39 @@ end context "when mapping late/early fees" do + let(:translations) { + { + en: "test 1", + de: "test 2", + zh: "test 3", + es: "test 4" + } + } + it "sets fees to the description_append field" do expect_any_instance_of(RentalsUnited::Converters::CheckInOutFees) - .to(receive(:as_text)) - .and_return("Check in rules") + .to(receive(:build_tranlations)) + .and_return(translations) + + expect(property.description_append).to eq("test 1") + expect(property.de.description_append).to eq("test 2") + expect(property.zh.description_append).to eq("test 3") + expect(property.es.description_append).to eq("test 4") + end - expect(property.description_append).to eq("Check in rules") + context "when tranlations are empty" do + let(:translations) { nil } + + it "sets fees to the description_append field" do + expect_any_instance_of(RentalsUnited::Converters::CheckInOutFees) + .to(receive(:build_tranlations)) + .and_return(translations) + + expect(property.description_append).to be_nil + expect(property.de.description_append).to be_nil + expect(property.zh.description_append).to be_nil + expect(property.es.description_append).to be_nil + end end end end From 6231e315c92e24ea336dbbbd62d96ed26f1f500c Mon Sep 17 00:00:00 2001 From: Sharipov Ruslan Date: Mon, 24 Oct 2016 11:07:27 +0600 Subject: [PATCH 2/4] code style --- .../suppliers/rentals_united/converters/check_in_out_fees.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb b/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb index de6b7ddc4..34b641c9d 100644 --- a/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb +++ b/spec/lib/concierge/suppliers/rentals_united/converters/check_in_out_fees.rb @@ -99,7 +99,7 @@ module RentalsUnited let(:early_departure_fees) { [] } it "returns nil" do - expect(subject.build_tranlations).to eq(nil) + expect(subject.build_tranlations).to be_nil end end end From 51e39b7621968df3f7e5274fa3a328c9c73bc78e Mon Sep 17 00:00:00 2001 From: Sharipov Ruslan Date: Mon, 24 Oct 2016 11:10:10 +0600 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2198ab847..11edeabac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file summarises the most important changes that went live on each release of Concierge. Please check the Wiki entry on the release process to understand how this file is formatted and how the process works. +## Unreleased +### Added +- Rentals United: add translations for zh de es languages for late/early fees + ## [0.12.12] - 2016-10-21 ### Added - Rentals United: add late check-in / early check-out fees to description_append From c913840e2d760a9da7975b11b38f827e19219931 Mon Sep 17 00:00:00 2001 From: Keang Date: Mon, 24 Oct 2016 14:17:29 +0800 Subject: [PATCH 4/4] Bump version 0.12.13 --- CHANGELOG.md | 4 ++-- lib/concierge/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11edeabac..431575245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ This file summarises the most important changes that went live on each release of Concierge. Please check the Wiki entry on the release process to understand how this file is formatted and how the process works. -## Unreleased +## [0.12.13] - 2016-10-24 ### Added -- Rentals United: add translations for zh de es languages for late/early fees +- Rentals United: add translations for zh de es languages for late/early fees ## [0.12.12] - 2016-10-21 ### Added diff --git a/lib/concierge/version.rb b/lib/concierge/version.rb index bc5195263..fc170ba70 100644 --- a/lib/concierge/version.rb +++ b/lib/concierge/version.rb @@ -1,3 +1,3 @@ module Concierge - VERSION = "0.12.12" + VERSION = "0.12.13" end