From f4ddddc6d39428ae2d9e2c4ddf65213d8578ed7b Mon Sep 17 00:00:00 2001 From: Matthew Jackowski Date: Thu, 26 May 2016 16:50:45 -0700 Subject: [PATCH] fix for subdomain language mappings --- .../transifex-live-integration-javascript.php | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/includes/lib/transifex-live-integration-javascript.php b/includes/lib/transifex-live-integration-javascript.php index 1d189e15..e508cc04 100644 --- a/includes/lib/transifex-live-integration-javascript.php +++ b/includes/lib/transifex-live-integration-javascript.php @@ -33,6 +33,7 @@ class Transifex_Live_Integration_Javascript { * @var array */ private $language_map; + private $url_options; /** * Public constructor, sets local settings @@ -40,11 +41,12 @@ class Transifex_Live_Integration_Javascript { */ public function __construct( $settings, $live_settings ) { Plugin_Debug::logTrace(); - $this->live_settings = $live_settings; // set defaults + $this->live_settings = $live_settings; // set defaults $this->live_settings['api_key'] = $settings['api_key']; // add api key $this->lang = false; $this->source_language = $settings['source_language']; $this->language_map = $settings['language_map']; + $this->url_options = $settings['url_options']; } /** @@ -98,18 +100,34 @@ function wp_head_hook() { Plugin_Debug::logTrace(); $lang = $this->lang; $live_settings = $this->live_settings; - if ( $lang ) { - $detectlang = <<url_options === 2 ) { + $language_map = ''; + foreach ($this->language_map as $key => $value) { + $language_map .= "case '$value': return '$key'; break; "; + } + $snippet .= <<function subdomain_detect_lang() {var a = window.location.host.split( '.' )[0]; switch(a) { $language_map case 'www': return true; break;} return a;} + +SUBDOMAIN; + $detectlang = "subdomain_detect_lang"; + } else { + if ( $lang ) { + $detectlang = << '%function%' ] ); $live_settings_json = json_encode( $live_settings ); $live_settings_string = str_replace( '"%function%"', $detectlang, $live_settings_json ); - } else { - $live_settings_string = json_encode( $live_settings ); } - $snippet = <<window.liveSettings=$live_settings_string; \n SNIPPET;