trip_advisor 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +52 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +118 -0
- data/LICENSE.txt +20 -0
- data/README.md +23 -0
- data/Rakefile +7 -0
- data/lib/trip_advisor/api.rb +45 -0
- data/lib/trip_advisor/build.rb +221 -0
- data/lib/trip_advisor/rake_tasks.rb +182 -0
- data/lib/trip_advisor/resource_manager.rb +101 -0
- data/lib/trip_advisor/strings_file.rb +112 -0
- data/lib/trip_advisor/translation.rb +63 -0
- data/lib/trip_advisor/translation_tool.rb +110 -0
- data/lib/trip_advisor/version.rb +3 -0
- data/lib/trip_advisor.rb +5 -0
- data/run_tests.sh +6 -0
- data/spec/api_spec.rb +34 -0
- data/spec/builder_spec.rb +262 -0
- data/spec/fixtures/AndroidStrings.txt +21 -0
- data/spec/fixtures/Strings.txt +47 -0
- data/spec/fixtures/project.git/.gitignore +1 -0
- data/spec/fixtures/project.git/BUILD.json +7 -0
- data/spec/fixtures/project.git/Code/Project.h +0 -0
- data/spec/fixtures/project.git/Code/Project.m +0 -0
- data/spec/fixtures/project.git/Gemfile +3 -0
- data/spec/fixtures/project.git/Gemfile.lock +38 -0
- data/spec/fixtures/project.git/HEAD +1 -0
- data/spec/fixtures/project.git/LICENSE +1 -0
- data/spec/fixtures/project.git/Podfile +6 -0
- data/spec/fixtures/project.git/Podfile.lock +14 -0
- data/spec/fixtures/project.git/Project.podspec +14 -0
- data/spec/fixtures/project.git/TestProject/Images.xcassets/AppIcon.appiconset/Contents.json +23 -0
- data/spec/fixtures/project.git/TestProject/Images.xcassets/LaunchImage.launchimage/Contents.json +23 -0
- data/spec/fixtures/project.git/TestProject/TATPAppDelegate.h +15 -0
- data/spec/fixtures/project.git/TestProject/TATPAppDelegate.m +49 -0
- data/spec/fixtures/project.git/TestProject/TestProject-Info.plist +38 -0
- data/spec/fixtures/project.git/TestProject/TestProject-Prefix.pch +16 -0
- data/spec/fixtures/project.git/TestProject/en.lproj/InfoPlist.strings +1 -0
- data/spec/fixtures/project.git/TestProject/main.m +18 -0
- data/spec/fixtures/project.git/TestProject.xcodeproj/project.pbxproj +1020 -0
- data/spec/fixtures/project.git/TestProject.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/spec/fixtures/project.git/TestProject.xcodeproj/project.xcworkspace/xcuserdata/blake.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/spec/fixtures/project.git/TestProject.xcodeproj/xcuserdata/blake.xcuserdatad/xcschemes/TestProject.xcscheme +96 -0
- data/spec/fixtures/project.git/TestProject.xcodeproj/xcuserdata/blake.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
- data/spec/fixtures/project.git/TestProject.xcworkspace/contents.xcworkspacedata +1 -0
- data/spec/fixtures/project.git/TestProjectTests/TestProjectTests-Info.plist +22 -0
- data/spec/fixtures/project.git/TestProjectTests/TestProjectTests.m +34 -0
- data/spec/fixtures/project.git/TestProjectTests/en.lproj/InfoPlist.strings +1 -0
- data/spec/fixtures/project.git/VERSION +1 -0
- data/spec/fixtures/project.git/config +7 -0
- data/spec/fixtures/project.git/description +1 -0
- data/spec/fixtures/project.git/index +0 -0
- data/spec/fixtures/project.git/info/exclude +6 -0
- data/spec/fixtures/project.git/logs/HEAD +1 -0
- data/spec/fixtures/project.git/logs/refs/heads/master +1 -0
- data/spec/fixtures/project.git/objects/00/a6b3f80ebbe4019f03461416061e8805e6eab1 +0 -0
- data/spec/fixtures/project.git/objects/03/c303d5552f29d366d11a13448c3c18e94c3bfa +0 -0
- data/spec/fixtures/project.git/objects/03/ff7c3a95a196ac8ad1d53db2bd4fb4c80507c1 +0 -0
- data/spec/fixtures/project.git/objects/0a/7123364a174ffda52d29a18cdd31fd325bbd6c +0 -0
- data/spec/fixtures/project.git/objects/0d/183cba8b0a5e477ea1d001130c222af19b8324 +0 -0
- data/spec/fixtures/project.git/objects/0e/6ba5232c3c2f8a7e435794e845b5dc9f339d8b +0 -0
- data/spec/fixtures/project.git/objects/25/5b4ee687ed1337cffb10e6d07bb89ee6e5d180 +0 -0
- data/spec/fixtures/project.git/objects/25/60a2b9ab9323ca61a0fdebd3b4af46dbe4c272 +0 -0
- data/spec/fixtures/project.git/objects/2b/f8bd93d56787a7548c7f8960a94f05c269b486 +0 -0
- data/spec/fixtures/project.git/objects/38/439105a884d2556443c7b5c645034e67fb7987 +0 -0
- data/spec/fixtures/project.git/objects/3e/efcb9dd5b38e2c1dc061052455dd97bcd51e6c +0 -0
- data/spec/fixtures/project.git/objects/53/8b3019ab68814604fbc8e017d09b690c22728c +0 -0
- data/spec/fixtures/project.git/objects/59/c178850684e21fafbebedeff15b2b522402af2 +0 -0
- data/spec/fixtures/project.git/objects/62/037867910d9aa803d7e02addc26574e270d3d8 +0 -0
- data/spec/fixtures/project.git/objects/66/05c1af131470a3b635d166f2591917b32f3b82 +0 -0
- data/spec/fixtures/project.git/objects/69/67e396037a52d8300eb9dc8a1e9f7155dd55bf +0 -0
- data/spec/fixtures/project.git/objects/6b/5ad4043aee9bc0936466760665f870d4f2f40f +0 -0
- data/spec/fixtures/project.git/objects/6c/fc746d4ecf2e3ac67bb0cf6c4013e1aff9b1f1 +0 -0
- data/spec/fixtures/project.git/objects/6f/3b0ab36651ca648408c176f81e4b2e202efa0b +0 -0
- data/spec/fixtures/project.git/objects/74/3435c9bee5c433fe166891e698fdc70d81a3de +0 -0
- data/spec/fixtures/project.git/objects/96/81bfb8ec019f74df384cfb66d68e94bd6d9005 +0 -0
- data/spec/fixtures/project.git/objects/99/fa9259e929fe3bee4791ff2a63070fc0358c0a +3 -0
- data/spec/fixtures/project.git/objects/a1/5f8980cfbf126a9a0b3ddf7fb1c3fbd6480934 +2 -0
- data/spec/fixtures/project.git/objects/a3/96706db4ec4cfca4d984d38b90dc8098bded40 +1 -0
- data/spec/fixtures/project.git/objects/b4/42134ccda2b0b1813288e7e04a401a4bef2b59 +0 -0
- data/spec/fixtures/project.git/objects/b9/2732c79e00cf2fad5ceceb61bbc7a9a9739d2c +0 -0
- data/spec/fixtures/project.git/objects/ba/01f5352549018dfdb95423b9e0974443ec0346 +1 -0
- data/spec/fixtures/project.git/objects/ba/8dd7d2162334426facd310f62ed923eb6f4cf5 +0 -0
- data/spec/fixtures/project.git/objects/bf/422763a0101a5971e15d53581acb825b4d38b8 +0 -0
- data/spec/fixtures/project.git/objects/c7/9ebd3ada1309bae694b8e6760592b1254e035c +2 -0
- data/spec/fixtures/project.git/objects/ca/7ced48ee61e517fc57576a33dc9d95f5d4f539 +2 -0
- data/spec/fixtures/project.git/objects/ce/eed5f059b6d374d08e0b1e732463842b3a5a91 +0 -0
- data/spec/fixtures/project.git/objects/d7/89fd591fee7d26c2f40c6614b5a91931377f88 +0 -0
- data/spec/fixtures/project.git/objects/d8/ec4dbb2804f53fd863cd0adb830c5bf4e85a1d +0 -0
- data/spec/fixtures/project.git/objects/dc/680e07f12748657d5a798495f08ce3ad884f0b +0 -0
- data/spec/fixtures/project.git/objects/de/de871ad5691708aca809557a823082a70dde69 +0 -0
- data/spec/fixtures/project.git/objects/e0/30730e56be52e4dc293c829f73e0c586073ad2 +0 -0
- data/spec/fixtures/project.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/spec/fixtures/project.git/objects/e6/f7f8a92eb3177d10a809b96f41905e9be4cc2b +0 -0
- data/spec/fixtures/project.git/objects/ed/7115c4ae4c1885ee75f6ffe946b559546efd28 +0 -0
- data/spec/fixtures/project.git/objects/f1/e01dd1256054d5717ef0c89008f0a22639e273 +2 -0
- data/spec/fixtures/project.git/objects/f9/3e9c03a56aba331bcd98cb2ef00ba0003de285 +0 -0
- data/spec/fixtures/project.git/refs/heads/master +1 -0
- data/spec/fixtures/search.json +14159 -0
- data/spec/fixtures/search_results_1-50.html +1076 -0
- data/spec/fixtures/search_results_101-110.html +476 -0
- data/spec/fixtures/search_results_51-100.html +1076 -0
- data/spec/fixtures/translation_details.html +728 -0
- data/spec/fixtures/translation_details.json +738 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/strings_file_spec.rb +225 -0
- data/spec/translation_spec.rb +21 -0
- data/spec/translation_tool_spec.rb +146 -0
- data/trip_advisor.gemspec +38 -0
- metadata +474 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'trip_advisor'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
module FixtureHelper
|
13
|
+
def root_path
|
14
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixture_path(fixture)
|
18
|
+
File.join(root_path, fixture)
|
19
|
+
end
|
20
|
+
|
21
|
+
def fixture_content(fixture)
|
22
|
+
File.read(fixture_path(fixture))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.include(FixtureHelper)
|
28
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'trip_advisor/translation'
|
3
|
+
require 'trip_advisor/strings_file'
|
4
|
+
|
5
|
+
describe TripAdvisor::StringsFile do
|
6
|
+
describe '.read' do
|
7
|
+
before(:each) do
|
8
|
+
tempfile = Tempfile.open('Strings.txt') { |f| f << fixture_content('Strings.txt') }
|
9
|
+
@strings_file = TripAdvisor::StringsFile.read(tempfile.path)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "loads all strings into Translations" do
|
13
|
+
@strings_file.translations.size.should == 16
|
14
|
+
end
|
15
|
+
|
16
|
+
it "reads all language tags defined in the strings file" do
|
17
|
+
@strings_file.language_tags.should == %w{en es}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.read' do
|
22
|
+
before(:each) do
|
23
|
+
tempfile = Tempfile.open('AndroidStrings.txt') { |f| f << fixture_content('AndroidStrings.txt') }
|
24
|
+
@strings_file = TripAdvisor::StringsFile.read(tempfile.path)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "loads all strings into Translations" do
|
28
|
+
@strings_file.translations.size.should == 6
|
29
|
+
end
|
30
|
+
|
31
|
+
it "reads all language tags defined in the strings file" do
|
32
|
+
@strings_file.language_tags.should == %w{en es}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#[]' do
|
37
|
+
before(:each) do
|
38
|
+
tempfile = Tempfile.open('Strings.txt') { |f| f << fixture_content('Strings.txt') }
|
39
|
+
@strings_file = TripAdvisor::StringsFile.read(tempfile.path)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "reads a string by key from the file" do
|
43
|
+
@strings_file['%1$d Passengers'].should_not be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns a Translation object" do
|
47
|
+
translation = @strings_file['%1$d Passengers']
|
48
|
+
translation.should be_kind_of(TripAdvisor::Translation)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns a Localization for each string" do
|
52
|
+
translation = @strings_file['%1$d Passengers']
|
53
|
+
translation.localizations.size.should == 1
|
54
|
+
end
|
55
|
+
|
56
|
+
it "allows indexed access to the localization" do
|
57
|
+
translation = @strings_file['%1$d Passengers']
|
58
|
+
translation.localizations[0].string.should == '%1$d Passengers'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "allows keyed access to the localizations by locale identifier" do
|
62
|
+
translation = @strings_file['%1$d Passengers']
|
63
|
+
translation.localizations['en'].string.should == '%1$d Passengers'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#[]' do
|
68
|
+
before(:each) do
|
69
|
+
tempfile = Tempfile.open('AndroidStrings.txt') { |f| f << fixture_content('AndroidStrings.txt') }
|
70
|
+
@strings_file = TripAdvisor::StringsFile.read(tempfile.path)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "reads a string by key from the file" do
|
74
|
+
@strings_file['flights_app_arrival'].should_not be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns a Translation object" do
|
78
|
+
translation = @strings_file['flights_app_arrival']
|
79
|
+
translation.should be_kind_of(TripAdvisor::Translation)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns a Localization for each string" do
|
83
|
+
translation = @strings_file['flights_app_arrival']
|
84
|
+
translation.localizations.size.should == 1
|
85
|
+
end
|
86
|
+
|
87
|
+
it "allows indexed access to the localization" do
|
88
|
+
translation = @strings_file['flights_app_arrival']
|
89
|
+
translation.localizations[0].string.should == 'Arrival'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "allows keyed access to the localizations by locale identifier" do
|
93
|
+
translation = @strings_file['flights_app_arrival']
|
94
|
+
translation.localizations['en'].string.should == 'Arrival'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#merge_translations' do
|
99
|
+
before(:each) do
|
100
|
+
tempfile = Tempfile.open('Strings.txt') { |f| f << fixture_content('Strings.txt') }
|
101
|
+
@strings_file = TripAdvisor::StringsFile.read(tempfile.path)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "adds a new translation" do
|
105
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: 'TAFlights_exampleKey', note: 'Note for translator')
|
106
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '1 Passenger', status: 'Active')
|
107
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'es_CO', language_name: 'Spanish', string: '1 pasajero', status: 'Active')
|
108
|
+
@strings_file.merge_translations([translation])
|
109
|
+
@strings_file.write
|
110
|
+
|
111
|
+
# Read the new key back out
|
112
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
113
|
+
new_strings_file['1 Passenger'].should_not be_nil
|
114
|
+
new_strings_file['1 Passenger'].localizations.size.should == 2
|
115
|
+
localizations = new_strings_file['1 Passenger'].localizations.inject({}) { |hash, l| hash[l.locale_identifier] = l.string; hash }
|
116
|
+
localizations.should == { 'en' => '1 Passenger', 'es_CO' => '1 pasajero' }
|
117
|
+
end
|
118
|
+
|
119
|
+
it "merges new localizations for an existing translation" do
|
120
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: '%1$d Passengers')
|
121
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '%1$d Passengers', status: 'Active')
|
122
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'es_CO', language_name: 'Spanish', string: '1 pasajero', status: 'Active')
|
123
|
+
@strings_file.merge_translations([translation])
|
124
|
+
@strings_file.write
|
125
|
+
|
126
|
+
# Read the new key back out
|
127
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
128
|
+
new_strings_file['%1$d Passengers'].should_not be_nil
|
129
|
+
new_strings_file['%1$d Passengers'].localizations.size.should == 2
|
130
|
+
localizations = new_strings_file['%1$d Passengers'].localizations.inject({}) { |hash, l| hash[l.locale_identifier] = l.string; hash }
|
131
|
+
localizations.should == { 'en' => '%1$d Passengers', 'es_CO' => '1 pasajero' }
|
132
|
+
end
|
133
|
+
|
134
|
+
it "updates the string for an existing localization" do
|
135
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: '%1$d Passengers')
|
136
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'es_CO', language_name: 'Spanish', string: '1 pasajero', status: 'Active')
|
137
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '%1$d Passengers', status: 'Active')
|
138
|
+
@strings_file.merge_translations([translation])
|
139
|
+
@strings_file.write
|
140
|
+
|
141
|
+
# Read the new key back out
|
142
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
143
|
+
new_strings_file['%1$d Passengers'].should_not be_nil
|
144
|
+
new_strings_file['%1$d Passengers'].localizations.size.should == 2
|
145
|
+
localizations = new_strings_file['%1$d Passengers'].localizations.inject({}) { |hash, l| hash[l.locale_identifier] = l.string; hash }
|
146
|
+
localizations.should == { 'en' => '%1$d Passengers', 'es_CO' => '1 pasajero' }
|
147
|
+
end
|
148
|
+
|
149
|
+
it "adds a note to an existing localization if there is not one" do
|
150
|
+
@strings_file["%1$d Passengers"].note.should be_nil
|
151
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: '%1$d Passengers', note: "Number of Passengers")
|
152
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '%1$d Passengers', status: 'Active')
|
153
|
+
@strings_file.merge_translations([translation])
|
154
|
+
@strings_file.write
|
155
|
+
|
156
|
+
# Read the new key back out
|
157
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
158
|
+
new_strings_file['%1$d Passengers'].note.should == 'Number of Passengers'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#merge_translations' do
|
163
|
+
before(:each) do
|
164
|
+
tempfile = Tempfile.open('AndroidStrings.txt') { |f| f << fixture_content('AndroidStrings.txt') }
|
165
|
+
@strings_file = TripAdvisor::StringsFile.read(tempfile.path)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "adds a new translation" do
|
169
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: 'flights_app_example_key', note: 'Note for translator')
|
170
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '1 Passenger', status: 'Active')
|
171
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'es_CO', language_name: 'Spanish', string: '1 pasajero', status: 'Active')
|
172
|
+
@strings_file.merge_translations_android([translation])
|
173
|
+
@strings_file.write
|
174
|
+
|
175
|
+
# Read the new key back out
|
176
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
177
|
+
new_strings_file['flights_app_example_key'].should_not be_nil
|
178
|
+
new_strings_file['flights_app_example_key'].localizations.size.should == 2
|
179
|
+
localizations = new_strings_file['flights_app_example_key'].localizations.inject({}) { |hash, l| hash[l.locale_identifier] = l.string; hash }
|
180
|
+
localizations.should == { 'en' => '1 Passenger', 'es_CO' => '1 pasajero' }
|
181
|
+
end
|
182
|
+
|
183
|
+
it "merges new localizations for an existing translation" do
|
184
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: 'flights_app_example_key')
|
185
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '%1$d Passengers', status: 'Active')
|
186
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'es_CO', language_name: 'Spanish', string: '1 pasajero', status: 'Active')
|
187
|
+
@strings_file.merge_translations_android([translation])
|
188
|
+
@strings_file.write
|
189
|
+
|
190
|
+
# Read the new key back out
|
191
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
192
|
+
new_strings_file['flights_app_example_key'].should_not be_nil
|
193
|
+
new_strings_file['flights_app_example_key'].localizations.size.should == 2
|
194
|
+
localizations = new_strings_file['flights_app_example_key'].localizations.inject({}) { |hash, l| hash[l.locale_identifier] = l.string; hash }
|
195
|
+
localizations.should == { 'en' => '%1$d Passengers', 'es_CO' => '1 pasajero' }
|
196
|
+
end
|
197
|
+
|
198
|
+
it "updates the string for an existing localization" do
|
199
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: 'flights_app_example_key')
|
200
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'es_CO', language_name: 'Spanish', string: '1 pasajero', status: 'Active')
|
201
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '%1$d Passengers', status: 'Active')
|
202
|
+
@strings_file.merge_translations_android([translation])
|
203
|
+
@strings_file.write
|
204
|
+
|
205
|
+
# Read the new key back out
|
206
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
207
|
+
new_strings_file['flights_app_example_key'].should_not be_nil
|
208
|
+
new_strings_file['flights_app_example_key'].localizations.size.should == 2
|
209
|
+
localizations = new_strings_file['flights_app_example_key'].localizations.inject({}) { |hash, l| hash[l.locale_identifier] = l.string; hash }
|
210
|
+
localizations.should == { 'en' => '%1$d Passengers', 'es_CO' => '1 pasajero' }
|
211
|
+
end
|
212
|
+
|
213
|
+
it "adds a note to an existing localization if there is not one" do
|
214
|
+
@strings_file['flights_app_number_of_passengers'].note.should be_nil
|
215
|
+
translation = TripAdvisor::Translation.new(id: 123456, key: 'flights_app_number_of_passengers', note: "Number of Passengers")
|
216
|
+
translation.localizations << TripAdvisor::Translation::Localization.new(locale_identifier: 'en', language_name: 'English', string: '%1$d Passengers', status: 'Active')
|
217
|
+
@strings_file.merge_translations_android([translation])
|
218
|
+
@strings_file.write
|
219
|
+
|
220
|
+
# Read the new key back out
|
221
|
+
new_strings_file = TripAdvisor::StringsFile.read(@strings_file.path)
|
222
|
+
new_strings_file['flights_app_number_of_passengers'].note.should == 'Number of Passengers'
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'trip_advisor/translation'
|
3
|
+
|
4
|
+
describe TripAdvisor::Translation do
|
5
|
+
it "strips leading and trailing whitespace from key attribute" do
|
6
|
+
translation = TripAdvisor::Translation.new(key: " the key ")
|
7
|
+
translation.key.should == 'the key'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe TripAdvisor::Translation::Localization do
|
12
|
+
it "strips leading and trailing whitespace from string attribute" do
|
13
|
+
translation = TripAdvisor::Translation::Localization.new(string: " the value ")
|
14
|
+
translation.string.should == 'the value'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "handles TripAdvisor locale substitutions" do
|
18
|
+
translation = TripAdvisor::Translation::Localization.new(locale_identifier: "no")
|
19
|
+
translation.locale_identifier.should == 'nb'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'trip_advisor/translation_tool'
|
3
|
+
|
4
|
+
describe TripAdvisor::TranslationTool do
|
5
|
+
before(:each) do
|
6
|
+
@translation_tool = TripAdvisor::TranslationTool.new(username: 'username', password: 'password')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#search' do
|
10
|
+
it 'returns a results page' do
|
11
|
+
fixture = fixture_content('search.json')
|
12
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
13
|
+
paginator = @translation_tool.search('TAFlights')
|
14
|
+
paginator.should be_kind_of(TripAdvisor::TranslationTool::ResultsPaginator)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'retrieves the total number of results' do
|
18
|
+
fixture = fixture_content('search.json')
|
19
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
20
|
+
paginator = @translation_tool.search('TAFlights')
|
21
|
+
paginator.total.should == 240
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the first page with an offset of zero" do
|
25
|
+
fixture = fixture_content('search.json')
|
26
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
27
|
+
paginator = @translation_tool.search('TAFlights')
|
28
|
+
paginator.offset.should == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'calculates the page total' do
|
32
|
+
fixture = fixture_content('search.json')
|
33
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
34
|
+
paginator = @translation_tool.search('TAFlights')
|
35
|
+
paginator.page_count.should == 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'builds the correct number of translations' do
|
39
|
+
fixture = fixture_content('search.json')
|
40
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
41
|
+
paginator = @translation_tool.search('TAFlights')
|
42
|
+
paginator.translations.size.should == 240
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'populates the translation ids correctly' do
|
46
|
+
fixture = fixture_content('search.json')
|
47
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
48
|
+
paginator = @translation_tool.search('TAFlights')
|
49
|
+
paginator.translations[0, 10].map { |t| t.id }.should == [293439, 314425, 303071, 290857, 292302, 290743, 290861, 290741, 290819, 292279]
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'populates the translation keys correctly' do
|
53
|
+
fixture = fixture_content('search.json')
|
54
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
55
|
+
paginator = @translation_tool.search('TAFlights')
|
56
|
+
paginator.translations[0, 10].map { |t| t.key }.should == ["TAFlights_adjustfilters_ffffef05", "TAFlights_Select_ffffdca8",
|
57
|
+
"TAFlights_SeePrice_19ac", "TAFlights_DeselectAllFiltersAccessibilityLabel_ffffef05", "TAFlights_Departingfrom:_ffffef05",
|
58
|
+
"TAFlights_ItineraryGroupPrice,Name,andItineraryCount_ffffef05", "TAFlights_FilterSelectionHeaderText_ffffef05",
|
59
|
+
"TAFlights_AccessibilityLabeldescribingMarketingAirline,FlightNumber,Departure/ArrivalCity(AirportCode),Aircraft,SeatClass,FlightDuration&Amenities_ffffef05",
|
60
|
+
"TAFlights_NearbyAirportsHeaderText_ffffef05", "TAFlights_Theflightsearchreturnedincompletesearchresults._ffffef05"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'populates the translation notes correctly' do
|
64
|
+
fixture = fixture_content('search.json')
|
65
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
66
|
+
paginator = @translation_tool.search('TAFlights')
|
67
|
+
paginator.translations[0, 10].map { |t| t.note }.should == ["Message asking the user to adjust the current set of overly restrictive filters so that the view will",
|
68
|
+
"Select Button Title", "'See Price' call to action for an individual flight itinerary", "Deselect All Filters Accessibility Label", "'Departing From {Airport Name}' Header Text",
|
69
|
+
"Itinerary Group Price, Name, and Itinerary Count", "Filter Selection Header Text",
|
70
|
+
"Accessibility Label describing Marketing Airline, Flight Number, Departure/Arrival City (Airport Code), Aircraft, Seat Class, Flight Duration & Amenities",
|
71
|
+
"Nearby Airports Header Text", "Invalid Flight Search Results Loaded Error Message"]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'raises an error if you try to load a negative offset' do
|
75
|
+
fixture = fixture_content('search.json')
|
76
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
77
|
+
paginator = @translation_tool.search('TAFlights')
|
78
|
+
expect { paginator.load(offset: -1) }.to raise_error(ArgumentError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'raises an error if you try to load an offset greater than the number of translations' do
|
82
|
+
fixture = fixture_content('search.json')
|
83
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
84
|
+
paginator = @translation_tool.search('TAFlights')
|
85
|
+
expect { paginator.load(offset: 400) }.to raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'raises an error if you try to load a page with a negative index' do
|
89
|
+
fixture = fixture_content('search.json')
|
90
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
91
|
+
paginator = @translation_tool.search('TAFlights')
|
92
|
+
expect { paginator.load(page: -1) }.to raise_error(ArgumentError)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raises an error if you try paginator to load a page beyond the page count' do
|
96
|
+
fixture = fixture_content('search.json')
|
97
|
+
stub_request(:post, "https://username:password@localization.tripadvisor.com/translations/search/keys").with(:body => "{\"lang\":\"en\",\"keyName\":\"TAFlights\"}").to_return(body: fixture, :status => 200)
|
98
|
+
paginator = @translation_tool.search('TAFlights')
|
99
|
+
expect { paginator.load(page: 6) }.to raise_error(ArgumentError)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#get_translation' do
|
104
|
+
it "sets the translation id" do
|
105
|
+
fixture = fixture_content('translation_details.json')
|
106
|
+
stub_request(:get, "https://username:password@localization.tripadvisor.com/translations/keys/id/290759/translations").to_return(body: fixture, status: 200)
|
107
|
+
translation = @translation_tool.get_translation(290759)
|
108
|
+
translation.id.should == 290759
|
109
|
+
end
|
110
|
+
|
111
|
+
it "loads the correct number of localizations" do
|
112
|
+
fixture = fixture_content('translation_details.json')
|
113
|
+
stub_request(:get, "https://username:password@localization.tripadvisor.com/translations/keys/id/290759/translations").to_return(body: fixture, status: 200)
|
114
|
+
translation = @translation_tool.get_translation(290759)
|
115
|
+
translation.localizations.size.should == 46
|
116
|
+
end
|
117
|
+
|
118
|
+
it "loads the status for all localizations" do
|
119
|
+
fixture = fixture_content('translation_details.json')
|
120
|
+
stub_request(:get, "https://username:password@localization.tripadvisor.com/translations/keys/id/290759/translations").to_return(body: fixture, status: 200)
|
121
|
+
translation = @translation_tool.get_translation(290759)
|
122
|
+
translation.localizations.map(&:status).uniq.should == [false]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "loads the locale_identifier for all localizations" do
|
126
|
+
fixture = fixture_content('translation_details.json')
|
127
|
+
stub_request(:get, "https://username:password@localization.tripadvisor.com/translations/keys/id/290759/translations").to_return(body: fixture, status: 200)
|
128
|
+
translation = @translation_tool.get_translation(290759)
|
129
|
+
translation.localizations.map(&:locale_identifier).size.should == 46
|
130
|
+
translation.localizations.map(&:locale_identifier).should == ["pl", "nb", "en_SG", "sk", "ru", "es_CL", "fi", "nl", "en-GB", "de_AT", "da", "sr", "en_CA", "zh", "en",
|
131
|
+
"fr", "th", "ar", "vi", "el", "de", "en_ZA", "id", "en_MY", "ja", "es_PE", "zh-Hant", "pt", "cs", "en_IE", "en_IN", "es_AR", "es", "ko", "es_MX", "en_AU", "sv", "en_NZ",
|
132
|
+
"iw", "tr", "es_CO", "en_PH", "es_VE", "hu", "it", "uk"]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "loads the language for all localizations" do
|
136
|
+
fixture = fixture_content('translation_details.json')
|
137
|
+
stub_request(:get, "https://username:password@localization.tripadvisor.com/translations/keys/id/290759/translations").to_return(body: fixture, status: 200)
|
138
|
+
translation = @translation_tool.get_translation(290759)
|
139
|
+
translation.localizations.map(&:language_name).should == ["Polish", "Norwegian", "English (Singapore)", "Slovak", "Russian", "Spanish (Chile)", "Finnish", "Dutch",
|
140
|
+
"English (UK)", "German (Austria)", "Danish", "Serbian", "English (Canada)", "Chinese (China)", "English", "French", "Thai", "Arabic", "Vietnamese", "Greek",
|
141
|
+
"German", "English (South Africa)", "Indonesian", "English (Malaysia)", "Japanese", "Spanish (Peru)", "Chinese (Taiwan)", "Portuguese", "Czech", "English (Ireland)",
|
142
|
+
"English (India)", "Spanish (Argentina)", "Spanish", "Korean", "Spanish (Mexico)", "English (Australia)", "Swedish", "English (New Zealand)", "Hebrew", "Turkish",
|
143
|
+
"Spanish (Colombia)", "English (Philippines)", "Spanish (Venezuela)", "Hungarian", "Italian", "Ukrainian"]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trip_advisor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "trip_advisor"
|
8
|
+
spec.version = TripAdvisor::VERSION
|
9
|
+
spec.authors = ["Blake Watters"]
|
10
|
+
spec.email = ["bwatters@tripadvisor.com"]
|
11
|
+
spec.description = %q{A Ruby interface for interacting with TripAdvisor development API's}
|
12
|
+
spec.summary = %q{This library provides interfaces to a number of TripAdvisor internal API's used for development purposes.}
|
13
|
+
spec.homepage = "http://engineering.tripadvisor.com"
|
14
|
+
spec.license = "Commercial"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'nokogiri', '~> 1.6.0'
|
22
|
+
spec.add_dependency 'rest-client', '~> 1.6.7'
|
23
|
+
spec.add_dependency 'addressable', '~> 2.3.5'
|
24
|
+
spec.add_dependency 'twine', '~> 0.4.0'
|
25
|
+
spec.add_dependency 'highline', '~> 1.6.19'
|
26
|
+
spec.add_dependency 'rugged', '~> 0.19.0'
|
27
|
+
spec.add_dependency 'oj', '~> 2.1.6'
|
28
|
+
spec.add_dependency 'cocoapods', '~> 0.34.2'
|
29
|
+
spec.add_dependency 'xcpretty', '~> 0.1.7'
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
32
|
+
spec.add_development_dependency "rake"
|
33
|
+
spec.add_development_dependency "rspec", "~> 2.14.0"
|
34
|
+
spec.add_development_dependency "simplecov", "~> 0.7.1"
|
35
|
+
spec.add_development_dependency "webmock", "~> 1.13.0"
|
36
|
+
spec.add_development_dependency "excon", "~> 0.26.0"
|
37
|
+
spec.add_development_dependency "tomdoc", "~> 0.2.5"
|
38
|
+
end
|