diff --git a/CHANGELOG.md b/CHANGELOG.md index 2198ab847..431575245 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. +## [0.12.13] - 2016-10-24 +### 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 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/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 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..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 @@ -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 be_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