CINXE.COM

<!-- ~ Copyright Crown Equipment Corporation. All rights reserved. --> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js ie ie6 lte9 lte8 lte7"> <![endif]--> <!--[if IE 7]> <html class="no-js ie ie7 lte9 lte8 lte7"> <![endif]--> <!--[if IE 8]> <html class="no-js ie ie8 lte9 lte8"> <![endif]--> <!--[if IE 9]> <html class="no-js ie ie9 lte9 lt-ie10"> <![endif]--> <!--[if gt IE 9]> <html class="no-js"> <![endif]--> <!--[if !IE]><!--> <html class="no-js"> <!--<![endif]--> <body> <script src="/etc.clientlibs/global-web/clientlibs/clientlib-jquery.lc-b102a6e9ffe2a374e617c7172467cd52-lc.min.js"></script> <div/><!-- ~ Copyright Crown Equipment Corporation. All rights reserved. --> <div> <p id="envIs" hidden>prod,publish</p> </div> <script> //Get the browser preferred language setting let browserLang = (navigator.languages && navigator.languages[0] || navigator.language).toLowerCase(); let genericRedirect = "genericRedirect"; function redirect(redirectType) { //Making this redirection only for Publish instance if($('#envIs').text().indexOf('publish') >= 0) { let componentPath = '\/content\/redirect\/jcr:content' jQuery.ajax({ url: componentPath + ".ipstackapiservlet" + ".json", type: 'GET', dataType: 'text' }).done(function(accessKey) { // get the API result via jQuery.ajax if(accessKey) { $.ajax({ url: 'https://api.ipstack.com/check?access_key=' + accessKey, dataType: 'jsonp', success: function(response) { if(!response.error && response.country_code) { let countryCode = resolveCountryCodeByMapping(response.country_code.toLowerCase()); resolvePageURL(browserLang, countryCode, redirectType); } else { checkPageExists(browserLang, redirectType, response.error); } }, error: function() { checkPageExists(browserLang, redirectType); } }); } else { window.location = window.location.origin + '/global-selector-page.html'; } }); } } function resolveCountryCodeByMapping(countryCode) { // Mapping the countryCode to crown's regional site code let countryCodeMappings = { 'gb': 'uk', 'za': 'eu', 'fi': 'eu', 'in': 'eu', 'ie': 'eu', 'il': 'eu', 'sa': 'eu', 'bh': 'eu', 'eg': 'eu', 'is': 'eu', 'kw': 'eu', 'pk': 'eu', 'qa': 'eu', 'rs': 'eu', 'lk': 'eu', 'ae': 'eu', 'kp': 'kr', 'mx': 'la', 'co': 'la', 'pe': 'la', 've': 'la', 'gt': 'la', 'ec': 'la', 'bo': 'la', 'do': 'la', 'hn': 'la', 'py': 'la', 'sv': 'la', 'ni': 'la', 'cr': 'la', 'pa': 'la', 'pr': 'la', 'ky': 'la', 'jm': 'la', 'bb': 'la', 'tt': 'la', 'ee': 'ru', 'lv': 'ru', 'lt': 'ru', 'tw': 'hk' }; if(countryCodeMappings.hasOwnProperty(countryCode)) { return countryCodeMappings[countryCode]; } else { return countryCode; } } function getCountryCode(countryCode, languageCode) { let switzerlandMappings = { 'de': 'eu' }; let belgiumMappings = { 'de': 'eu', 'nl': 'be', 'fr': 'be' }; let austriaMappings = { 'de': 'eu' }; let netherlandsMappings = { 'en': 'eu' }; if(countryCode === 'ch' && switzerlandMappings.hasOwnProperty(languageCode)) { countryCode = switzerlandMappings[languageCode]; } else if(countryCode === 'be' && belgiumMappings.hasOwnProperty(languageCode)) { countryCode = belgiumMappings[languageCode]; } else if(countryCode === 'at' && austriaMappings.hasOwnProperty(languageCode)) { countryCode = austriaMappings[languageCode]; } else if(netherlandsMappings.hasOwnProperty(languageCode)) { countryCode = netherlandsMappings[languageCode]; } return countryCode; } function handle404Redirects(urlLang) { $.ajax({ url: urlLang, async: false, context: document.body, success: function(data) { $( this ).append(data); }, error: function() { window.location = window.location.origin + '/global-selector-page.html'; } }); } function resolvePageURL(browserLang, countryCode, redirectType) { let languageCode = browserLang.substring(0, 2); if(countryCode === 'ch' || countryCode === 'be' || countryCode === 'nl' || countryCode === 'at') { countryCode = getCountryCode(countryCode, languageCode); } if(redirectType === genericRedirect) { let urlLang = window.location.origin + '/' + languageCode + '-' + countryCode + '.html'; $.ajax({ type: 'HEAD', url: urlLang, async: false, success: function() { window.location = urlLang; }, error: function() { window.location = window.location.origin + '/global-selector-page.html'; } }); } else { let urlLang = window.location.origin + '/' + languageCode + '-' + countryCode + '/404.html'; handle404Redirects(urlLang); } } //Try to resolve Url Language by mapping-up with our language codes then resolve global selector page function resolvePageUrlByMapping(languageCode, redirectType) { var currentLanguageCode = languageCode; var languageCodeMappings = { 'en-gb': 'en-uk', 'zh': 'zh-cn', 'ko': 'ko-kr', 'ko-kp': 'ko-kr', 'th': 'th-th', 'it': 'it-it', 'nl': 'nl-nl', 'de': 'de-de', 'es': 'es-es', 'ru': 'ru-ru' } if(languageCodeMappings.hasOwnProperty(currentLanguageCode)) { return checkPageExists(languageCodeMappings[currentLanguageCode], redirectType); } //Resolving global selector page window.location = window.location.origin + '/global-selector-page.html' } function checkPageExists(languageCode, redirectType, ipStackErrorResponse) { if(redirectType === genericRedirect) { let urlLang = window.location.origin + '/' + languageCode + '.html'; $.ajax({ type: 'HEAD', url: urlLang, success: function() { window.location = urlLang; }, error: function() { resolvePageUrlByMapping(languageCode, redirectType); } }); } else { let urlLang = window.location.origin + '/' + languageCode + '/404.html'; handle404Redirects(urlLang); } let errorJson = { "isAPIErrorResponse": false, "ipStackErrorCode": "", "ipStackErrorInfo": "", "languageCode": languageCode } if(ipStackErrorResponse) { errorJson.isAPIErrorResponse = true; errorJson.ipStackErrorCode = ipStackErrorResponse.code; errorJson.ipStackErrorInfo = ipStackErrorResponse.info; } // Calling Servlet to log an error let componentPath = '\/content\/redirect\/jcr:content' $.ajax({ url: componentPath + ".ipstackapifailureservlet", type: 'POST', data: errorJson }); } </script> <script> jQuery(document).ready(function() { redirect(); }); </script> </body>