wovnrb 3.8.0 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.en.md +44 -15
- data/README.ja.md +51 -20
- data/README.md +1 -1
- data/lib/wovnrb/api_translator.rb +5 -0
- data/lib/wovnrb/custom_domain/custom_domain_lang.rb +31 -0
- data/lib/wovnrb/custom_domain/custom_domain_lang_url_handler.rb +27 -0
- data/lib/wovnrb/custom_domain/custom_domain_langs.rb +40 -0
- data/lib/wovnrb/headers.rb +62 -51
- data/lib/wovnrb/lang.rb +1 -1
- data/lib/wovnrb/services/html_converter.rb +17 -3
- data/lib/wovnrb/services/html_replace_marker.rb +4 -0
- data/lib/wovnrb/store.rb +10 -1
- data/lib/wovnrb/url_language_switcher.rb +44 -4
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +7 -2
- data/test/lib/custom_domain/custom_domain_lang_test.rb +85 -0
- data/test/lib/custom_domain/custom_domain_lang_url_handler_test.rb +75 -0
- data/test/lib/custom_domain/custom_domain_langs_test.rb +82 -0
- data/test/lib/headers_test.rb +209 -48
- data/test/lib/services/html_converter_test.rb +70 -0
- data/test/lib/url_language_switcher_test.rb +148 -0
- data/test/lib/wovnrb_test.rb +1 -0
- metadata +9 -3
@@ -771,6 +771,85 @@ module Wovnrb
|
|
771
771
|
assert_equal('/th/', url_lang_switcher.add_lang_code(href_trailing_slash, 'th', headers))
|
772
772
|
end
|
773
773
|
|
774
|
+
def test_add_lang_code_with_custom_domain_langs
|
775
|
+
custom_domain_langs = {
|
776
|
+
'en' => { 'url' => 'my-site.com' },
|
777
|
+
'en-US' => { 'url' => 'en-us.my-site.com' },
|
778
|
+
'ja' => { 'url' => 'my-site.com/ja' },
|
779
|
+
'zh-CHS' => { 'url' => 'my-site.com/zh/chs' },
|
780
|
+
'zh-Hant-HK' => { 'url' => 'zh-hant-hk.com/zh' }
|
781
|
+
}
|
782
|
+
test_cases = [
|
783
|
+
# no_lang_url, lang_code, expected_url
|
784
|
+
# absolute URL
|
785
|
+
['https://my-site.com', 'en', 'https://my-site.com'],
|
786
|
+
['https://my-site.com', 'ja', 'https://my-site.com/ja'],
|
787
|
+
['https://my-site.com/index.php', 'ja', 'https://my-site.com/ja/index.php'],
|
788
|
+
['https://my-site.com/a/b/', 'ja', 'https://my-site.com/ja/a/b/'],
|
789
|
+
['https://my-site.com/a/b/index.php', 'ja', 'https://my-site.com/ja/a/b/index.php'],
|
790
|
+
['https://my-site.com/index.php', 'en-US', 'https://en-us.my-site.com/index.php'],
|
791
|
+
['https://my-site.com/index.php', 'zh-CHS', 'https://my-site.com/zh/chs/index.php'],
|
792
|
+
['https://my-site.com/index.php', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php'],
|
793
|
+
['https://my-site.com/index.php?a=1&b=2', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php?a=1&b=2'],
|
794
|
+
['https://my-site.com/index.php#hash', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php#hash'],
|
795
|
+
['https://my-site.com/index.php?a=1&b=2#hash', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php?a=1&b=2#hash'],
|
796
|
+
|
797
|
+
# absolute path
|
798
|
+
['/', 'en', 'http://my-site.com/'],
|
799
|
+
['/', 'ja', 'http://my-site.com/ja/'],
|
800
|
+
['/index.php', 'ja', 'http://my-site.com/ja/index.php'],
|
801
|
+
['/a/b/', 'ja', 'http://my-site.com/ja/a/b/'],
|
802
|
+
['/a/b/index.php', 'ja', 'http://my-site.com/ja/a/b/index.php'],
|
803
|
+
['/index.php', 'en-US', 'http://en-us.my-site.com/index.php'],
|
804
|
+
['/index.php', 'zh-CHS', 'http://my-site.com/zh/chs/index.php'],
|
805
|
+
['/index.php', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php'],
|
806
|
+
['/index.php?a=1&b=2', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php?a=1&b=2'],
|
807
|
+
['/index.php#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php#hash'],
|
808
|
+
['/index.php?a=1&b=2#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php?a=1&b=2#hash'],
|
809
|
+
|
810
|
+
# relative path
|
811
|
+
['index.php', 'ja', 'http://my-site.com/ja/req_uri/index.php'],
|
812
|
+
['a/b/', 'ja', 'http://my-site.com/ja/req_uri/a/b/'],
|
813
|
+
['a/b/index.php', 'ja', 'http://my-site.com/ja/req_uri/a/b/index.php'],
|
814
|
+
['index.php', 'en-US', 'http://en-us.my-site.com/req_uri/index.php'],
|
815
|
+
['index.php', 'zh-CHS', 'http://my-site.com/zh/chs/req_uri/index.php'],
|
816
|
+
['index.php', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php'],
|
817
|
+
['index.php?a=1&b=2', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php?a=1&b=2'],
|
818
|
+
['index.php#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php#hash'],
|
819
|
+
['index.php?a=1&b=2#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php?a=1&b=2#hash'],
|
820
|
+
['?a=1&b=2', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/?a=1&b=2'],
|
821
|
+
|
822
|
+
# anchor links should not be changed
|
823
|
+
['#hash', 'zh-Hant-HK', '#hash']
|
824
|
+
]
|
825
|
+
|
826
|
+
settings = {
|
827
|
+
'project_token' => 'T0k3N',
|
828
|
+
'default_lang' => 'en',
|
829
|
+
'supported_langs' => ['en'],
|
830
|
+
'url_pattern' => 'custom_domain',
|
831
|
+
'custom_domain_langs' => custom_domain_langs
|
832
|
+
}
|
833
|
+
additional_env = {
|
834
|
+
'HTTP_HOST' => 'my-site.com',
|
835
|
+
'REQUEST_URI' => '/req_uri/'
|
836
|
+
}
|
837
|
+
|
838
|
+
test_cases.each do |test_case|
|
839
|
+
target_uri, lang, expected_uri = test_case
|
840
|
+
store = Wovnrb::Store.instance
|
841
|
+
store.update_settings(settings)
|
842
|
+
url_lang_switcher = UrlLanguageSwitcher.new(store)
|
843
|
+
headers = Wovnrb::Headers.new(
|
844
|
+
Wovnrb.get_env(additional_env),
|
845
|
+
store.settings,
|
846
|
+
url_lang_switcher
|
847
|
+
)
|
848
|
+
|
849
|
+
assert_equal(expected_uri, url_lang_switcher.add_lang_code(target_uri, lang, headers))
|
850
|
+
end
|
851
|
+
end
|
852
|
+
|
774
853
|
def test_remove_lang_query_with_lang_param_name
|
775
854
|
settings = Wovnrb.get_settings('url_pattern' => 'query', 'lang_param_name' => 'lang')
|
776
855
|
store = Wovnrb.get_store(settings)
|
@@ -920,6 +999,75 @@ module Wovnrb
|
|
920
999
|
assert_equal('https://wovn.io/', uri_with_scheme)
|
921
1000
|
end
|
922
1001
|
|
1002
|
+
def test_remove_lang_custom_domain
|
1003
|
+
custom_domain_langs = {
|
1004
|
+
'en' => { 'url' => 'my-site.com' },
|
1005
|
+
'en-US' => { 'url' => 'en-us.my-site.com' },
|
1006
|
+
'ja' => { 'url' => 'my-site.com/ja' },
|
1007
|
+
'zh-CHS' => { 'url' => 'my-site.com/zh/chs' },
|
1008
|
+
'zh-Hant-HK' => { 'url' => 'zh-hant-hk.com/zh' }
|
1009
|
+
}
|
1010
|
+
test_cases = [
|
1011
|
+
# target_uri, lang, expected_uri, env
|
1012
|
+
# absolute URL
|
1013
|
+
['https://my-site.com', 'en', 'https://my-site.com', {}],
|
1014
|
+
['https://my-site.com/ja', 'ja', 'https://my-site.com', { 'REQUEST_URI' => '/ja' }],
|
1015
|
+
['https://my-site.com/ja/index.php', 'ja', 'https://my-site.com/index.php', { 'REQUEST_URI' => '/ja/index.php' }],
|
1016
|
+
['https://my-site.com/ja/a/b/', 'ja', 'https://my-site.com/a/b/', { 'REQUEST_URI' => '/ja/a/b/' }],
|
1017
|
+
['https://my-site.com/ja/a/b/index.php', 'ja', 'https://my-site.com/a/b/index.php', { 'REQUEST_URI' => '/ja/a/b/index.php' }],
|
1018
|
+
['https://en-us.my-site.com/index.php', 'en-US', 'https://my-site.com/index.php', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/index.php' }],
|
1019
|
+
['https://my-site.com/zh/chs/index.php', 'zh-CHS', 'https://my-site.com/index.php', { 'REQUEST_URI' => '/zh/chs/index.php' }],
|
1020
|
+
['https://zh-hant-hk.com/zh/index.php', 'zh-Hant-HK', 'https://my-site.com/index.php', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1021
|
+
['https://zh-hant-hk.com/zh/index.php?a=1&b=2', 'zh-Hant-HK', 'https://my-site.com/index.php?a=1&b=2', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1022
|
+
['https://zh-hant-hk.com/zh/index.php#hash', 'zh-Hant-HK', 'https://my-site.com/index.php#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1023
|
+
['https://zh-hant-hk.com/zh/index.php?a=1&b=2#hash', 'zh-Hant-HK', 'https://my-site.com/index.php?a=1&b=2#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1024
|
+
|
1025
|
+
# absolute path
|
1026
|
+
['/', 'en', '/', {}],
|
1027
|
+
['/ja/', 'ja', '/', { 'REQUEST_URI' => '/ja' }],
|
1028
|
+
['/ja/index.php', 'ja', '/index.php', { 'REQUEST_URI' => '/ja/index.php' }],
|
1029
|
+
['/ja/a/b/', 'ja', '/a/b/', { 'REQUEST_URI' => '/ja/a/b/' }],
|
1030
|
+
['/ja/a/b/index.php', 'ja', '/a/b/index.php', { 'REQUEST_URI' => '/ja/a/b/index.php' }],
|
1031
|
+
['/index.php', 'en-US', '/index.php', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/index.php' }],
|
1032
|
+
['/zh/chs/index.php', 'zh-CHS', '/index.php', { 'REQUEST_URI' => '/zh/chs/index.php' }],
|
1033
|
+
['/zh/index.php', 'zh-Hant-HK', '/index.php', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1034
|
+
['/zh/index.php?a=1&b=2', 'zh-Hant-HK', '/index.php?a=1&b=2', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1035
|
+
['/zh/index.php#hash', 'zh-Hant-HK', '/index.php#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1036
|
+
['/zh/index.php?a=1&b=2#hash', 'zh-Hant-HK', '/index.php?a=1&b=2#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
|
1037
|
+
|
1038
|
+
# other patterns should not be changed
|
1039
|
+
['?a=1&b=2', 'en-US', '?a=1&b=2', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/' }],
|
1040
|
+
['#hash', 'en-US', '#hash', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/' }]
|
1041
|
+
]
|
1042
|
+
|
1043
|
+
settings = {
|
1044
|
+
'project_token' => 'T0k3N',
|
1045
|
+
'default_lang' => 'en',
|
1046
|
+
'supported_langs' => %w[en en-US ja zh-CHS zh-Hant-HK],
|
1047
|
+
'url_pattern' => 'custom_domain',
|
1048
|
+
'custom_domain_langs' => custom_domain_langs
|
1049
|
+
}
|
1050
|
+
base_env = {
|
1051
|
+
'HTTP_HOST' => 'my-site.com',
|
1052
|
+
'REQUEST_URI' => '/req_uri/'
|
1053
|
+
}
|
1054
|
+
|
1055
|
+
test_cases.each do |test_case|
|
1056
|
+
target_uri, lang, expected_uri, env = test_case
|
1057
|
+
additional_env = base_env.merge(env)
|
1058
|
+
store = Wovnrb::Store.instance
|
1059
|
+
store.update_settings(settings)
|
1060
|
+
url_lang_switcher = UrlLanguageSwitcher.new(store)
|
1061
|
+
headers = Wovnrb::Headers.new(
|
1062
|
+
Wovnrb.get_env(additional_env),
|
1063
|
+
store.settings,
|
1064
|
+
url_lang_switcher
|
1065
|
+
)
|
1066
|
+
|
1067
|
+
assert_equal(expected_uri, url_lang_switcher.remove_lang_from_uri_component(target_uri, lang, headers))
|
1068
|
+
end
|
1069
|
+
end
|
1070
|
+
|
923
1071
|
def store_headers_factory(setting_opts = {}, url = 'http://my-site.com')
|
924
1072
|
settings = default_store_settings.merge(setting_opts)
|
925
1073
|
store = Wovnrb::Store.instance
|
data/test/lib/wovnrb_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wovnrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wovn Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -223,6 +223,9 @@ files:
|
|
223
223
|
- docker/scripts/jenkins/taskdef.json.bak
|
224
224
|
- lib/wovnrb.rb
|
225
225
|
- lib/wovnrb/api_translator.rb
|
226
|
+
- lib/wovnrb/custom_domain/custom_domain_lang.rb
|
227
|
+
- lib/wovnrb/custom_domain/custom_domain_lang_url_handler.rb
|
228
|
+
- lib/wovnrb/custom_domain/custom_domain_langs.rb
|
226
229
|
- lib/wovnrb/headers.rb
|
227
230
|
- lib/wovnrb/helpers/nokogumbo_helper.rb
|
228
231
|
- lib/wovnrb/lang.rb
|
@@ -239,6 +242,9 @@ files:
|
|
239
242
|
- test/fixtures/html/test.html
|
240
243
|
- test/fixtures/html/test_translated.html
|
241
244
|
- test/lib/api_translator_test.rb
|
245
|
+
- test/lib/custom_domain/custom_domain_lang_test.rb
|
246
|
+
- test/lib/custom_domain/custom_domain_lang_url_handler_test.rb
|
247
|
+
- test/lib/custom_domain/custom_domain_langs_test.rb
|
242
248
|
- test/lib/headers_test.rb
|
243
249
|
- test/lib/lang_test.rb
|
244
250
|
- test/lib/services/glob_test.rb
|
@@ -271,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
277
|
- !ruby/object:Gem::Version
|
272
278
|
version: '0'
|
273
279
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
280
|
+
rubygems_version: 3.4.8
|
275
281
|
signing_key:
|
276
282
|
specification_version: 4
|
277
283
|
summary: Gem for WOVN.io
|