-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #473 from roomorama/release/0.12.11
Release/0.12.11
- Loading branch information
Showing
97 changed files
with
617 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Workers::Comparison | ||
|
||
# +Workers::Comparison::Translations+ | ||
# | ||
# This class performs a comparison between two hash of translations. | ||
# | ||
# Usage: | ||
# original = old_roomorama_property.translations | ||
# new = new_roomorama_property.translations | ||
# | ||
# diff = Roomorama::Diff.new(old_roomorama_property.identifier) | ||
# | ||
# Workers::Comparison::Translations.(original, new).apply_to(diff) | ||
# | ||
class Translations | ||
|
||
attr_reader :original, :new | ||
|
||
def initialize(original, new) | ||
@original = original || {} | ||
@new = new || {} | ||
end | ||
|
||
def apply_to(diff) | ||
Roomorama::Translated::TRANSLATED_LOCALES.each do |locale| | ||
new_t = new[locale] || {} | ||
old_t = original[locale] || {} | ||
next if new_t.empty? && old_t.empty? | ||
translation = diff.public_send(locale) | ||
|
||
added = new_t.keys - old_t.keys | ||
added.each do |attr| | ||
translation[attr] = new_t[attr] | ||
end | ||
|
||
removed = old_t.keys - new_t.keys | ||
removed.each do |attr| | ||
translation.erase(attr) | ||
end | ||
|
||
common = old_t.keys & new_t.keys | ||
common.each do |attr| | ||
translation[attr] = new_t[attr] if new_t[attr] != old_t[attr] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# This module adds some translated fields to the class that includes it. | ||
# The default locale (:en) should be accessed directly on the base class. | ||
# | ||
# Usage | ||
# | ||
# class Property | ||
# attr_accessor :title, :description, :terms_and_conditions | ||
# include Roomorama::Translated | ||
# end | ||
# | ||
# p = Property.new | ||
# p.title = "Default title in english" | ||
# p.es.title = "Translated title in spanish" | ||
# | ||
module Roomorama::Translated | ||
TRANSLATED_LOCALES = %i(es de zh zh_tw) | ||
|
||
class Translation | ||
TRANSLATED_FIELDS = [:title, | ||
:description, | ||
:terms_and_conditions, | ||
:check_in_instructions, | ||
:description_append] | ||
|
||
attr_accessor *TRANSLATED_FIELDS | ||
|
||
def initialize | ||
@erased = [] | ||
end | ||
|
||
def erase(key) | ||
@erased << key | ||
end | ||
|
||
def []=(attr, value) | ||
attr = attr.to_sym | ||
if TRANSLATED_FIELDS.include?(attr) | ||
setter = [attr, "="].join | ||
public_send(setter, value) | ||
end | ||
end | ||
|
||
def to_h | ||
{ | ||
title: title, | ||
description: description, | ||
terms_and_conditions: terms_and_conditions, | ||
check_in_instructions: check_in_instructions, | ||
description_append: description_append, | ||
}.tap do |hash| | ||
hash.delete_if { |k, v| v.nil? && !@erased.include?(k) } | ||
end | ||
end | ||
end | ||
|
||
def self.included(base) | ||
|
||
def es; @es ||= Translation.new() end | ||
def de; @de ||= Translation.new() end | ||
def zh; @zh ||= Translation.new() end | ||
def zh_tw; @zh_tw ||= Translation.new() end | ||
|
||
def translations | ||
hash = {} | ||
TRANSLATED_LOCALES.collect do |locale| | ||
locale_hash = self.send(locale).to_h | ||
hash[locale] = locale_hash unless locale_hash.empty? | ||
end | ||
|
||
hash.empty? ? nil : hash | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.