From 62f62892f5546aa00d41ec30149b780bf7099f91 Mon Sep 17 00:00:00 2001 From: Stefanos Valoumas Date: Thu, 13 Jun 2024 13:03:05 +0300 Subject: [PATCH 1/2] TX-15429: Fix hrefland in source alternate tag --- .../transifex-live-integration-hreflang.php | 23 +++++-- ...ransifex-live-integration-settings-page.js | 68 +++++++++---------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/includes/lib/transifex-live-integration-hreflang.php b/includes/lib/transifex-live-integration-hreflang.php index a959efb..ffdc1a7 100644 --- a/includes/lib/transifex-live-integration-hreflang.php +++ b/includes/lib/transifex-live-integration-hreflang.php @@ -96,6 +96,7 @@ private function generate_languages_hreflang( $raw_url, $languages, $language_map, $hreflang_map ) { Plugin_Debug::logTrace(); + $source = $this->settings['source_language']; $url_map = Transifex_Live_Integration_Common::generate_language_url_map( $raw_url, $this->tokenized_url, $language_map ); $ret = [ ]; foreach ($languages as $language) { @@ -106,10 +107,11 @@ private function generate_languages_hreflang( $raw_url, $languages, $protocol = Transifex_Live_Integration_Util::get_http_requested_protocol(); $href_link_parts[0] = $protocol; $arr['href'] = implode(':', $href_link_parts); - } else { - $arr['href'] = $url_map[$language]; + } else { + $arr['href'] = $url_map[$language]; } $arr['hreflang'] = $hreflang_map[$language]; + $arr['is_source'] = ($language === $source); array_push( $ret, $arr ); } return $ret; @@ -134,10 +136,23 @@ public function render_hreflang() { $unslashed_source_url = $site_url . $source_url_path; $source_url = rtrim( $unslashed_source_url, '/' ) . '/'; $hreflang_out = ''; + $hreflangs = $this->generate_languages_hreflang( $source_url_path, $this->languages, $this->language_map, $this->hreflang_map ); + $source_hreflang = ''; + + foreach ($hreflangs as $hreflang) { + if ($hreflang['is_source']) { + $source_hreflang = $hreflang['hreflang']; + break; + } + } + // If source_hreflang is not found, + // use the source language as default + if (empty($source_hreflang)) { + $source_hreflang = $source; + } $hreflang_out .= <<\n +\n SOURCE; - $hreflangs = $this->generate_languages_hreflang( $source_url_path, $this->languages, $this->language_map, $this->hreflang_map ); foreach ($hreflangs as $hreflang) { $href_attr = $hreflang['href']; $hreflang_attr = $hreflang['hreflang']; diff --git a/javascript/transifex-live-integration-settings-page.js b/javascript/transifex-live-integration-settings-page.js index 3b31913..8fbdb0b 100755 --- a/javascript/transifex-live-integration-settings-page.js +++ b/javascript/transifex-live-integration-settings-page.js @@ -71,56 +71,53 @@ function build_cdn_manifest_url(apikey) { return "https://cdn.transifex.com/" + apikey + "/latest/manifest.jsonp"; } - - - -function transifex_live_integration_convert(l) { - var r = {"type": "div", +function transifex_live_integration_convert(data) { + var result = {"type": "div", "id": "transifex-languages"}; - var t = l['translation']; - var k = l['source']; - var h = []; + var translation = data['translation']; + var source = data['source']; + var html = []; transifex_languages = []; language_lookup = []; language_map = []; hreflang_map = []; - var arr = {}; - var arrr = {}; - var arrrr = {}; - - h.push(transifex_live_integration_mapper(k)); - transifex_languages.push(k['code']); - arr['tx_name'] = k['tx_name']; - arr['code'] = k['code']; - language_lookup.push(arr); - arrr[k['code']] = k['code']; - arrrr[k['code']] = k['code'].toLowerCase().replace('_', '-'); + var language_data = {}; + var language = {}; + var hreflang = {}; + + html.push(transifex_live_integration_mapper(source)); + transifex_languages.push(source['code']); + language_data['tx_name'] = source['tx_name']; + language_data['code'] = source['code']; + language_lookup.push(language_data); + language[source['code']] = source['code']; + hreflang[source['code']] = source['code'].toLowerCase().replace('_', '-'); jQuery.each( - t, function (i, o) { - h.push(transifex_live_integration_mapper(o)); + translation, function (i, o) { + html.push(transifex_live_integration_mapper(o)); transifex_languages.push(o['code']); - var arr = {}; - arr['tx_name'] = o['tx_name']; - arr['code'] = o['code']; - language_lookup.push(arr); - arrr[o['code']] = o['code']; - arrrr[o['code']] = o['code'].toLowerCase().replace('_', '-'); + var language_data = {}; + language_data['tx_name'] = o['tx_name']; + language_data['code'] = o['code']; + language_lookup.push(language_data); + language[o['code']] = o['code']; + hreflang[o['code']] = o['code'].toLowerCase().replace('_', '-'); } ); - language_map.push(arrr); - hreflang_map.push(arrrr); + language_map.push(language); + hreflang_map.push(hreflang); var s = { - caption: 'Source:' + l['source']['tx_name'], + caption: 'Source:' + source['tx_name'], name: "transifex-integration-live-source-language", id: "transifex-integration-live-[source-language]", type: "text", - value: l['source']['code'] + value: source['code'] }; - source_language = l['source']['code']; - r['source'] = s; - r['html'] = h; - return r; + source_language = source['code']; + result['source'] = s; + result['html'] = html; + return result; } @@ -206,7 +203,6 @@ function addTransifexLanguages(obj) { } ); - } else { var tlslm = JSON.parse(jQuery('#transifex_live_settings_language_map').val()); var tlshm = JSON.parse(jQuery('#transifex_live_settings_hreflang_map').val()); From fe91e88dce1a824c855c1b421364552a1668c033 Mon Sep 17 00:00:00 2001 From: Stefanos Valoumas Date: Fri, 14 Jun 2024 12:24:01 +0300 Subject: [PATCH 2/2] Bump version 1.3.40 --- .github/workflows/main.yml | 2 +- readme.md | 3 +++ readme.txt | 5 ++++- transifex-live-integration.php | 6 +++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5f43ec..51beb2a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" env: - PLUGIN_VERSION: 1.3.39 + PLUGIN_VERSION: 1.3.40 WP_PROJECT_TYPE: plugin WP_VERSION: latest WP_MULTISITE: 0 diff --git a/readme.md b/readme.md index 50db46d..d4ecf30 100755 --- a/readme.md +++ b/readme.md @@ -69,6 +69,9 @@ Ex. $updated_content = apply_filters('tx_link', $original_content); * It is also recommended to use [widgets](https://codex.wordpress.org/Widgets_API) in your theme instead of custom code, since this allows you to make your integration more future proof against incompatibilities with 3rd party modules. == Changelog == += 1.3.40 = +Fix hrefland in source alternate tag + = 1.3.39 = Add subdirectory rewrite rules for archive pages of custom post types diff --git a/readme.txt b/readme.txt index 0d1add3..f0242c1 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: txmatthew, ThemeBoy, brooksx Tags: transifex, localize, localization, multilingual, international, SEO Requires at least: 3.5.2 Tested up to: 6.5.3 -Stable tag: 1.3.39 +Stable tag: 1.3.40 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -78,6 +78,9 @@ Ex. $updated_content = apply_filters('tx_link', $original_content); It is also recommended to use [widgets](https://codex.wordpress.org/Widgets_API) in your theme instead of custom code, since this allows you to make your integration more future proof against incompatibilities with 3rd party modules. == Changelog == += 1.3.40 = +Fix hrefland in source alternate tag + = 1.3.39 = Add subdirectory rewrite rules for archive pages of custom post types diff --git a/transifex-live-integration.php b/transifex-live-integration.php index 7cc9fa5..8ee6ef9 100755 --- a/transifex-live-integration.php +++ b/transifex-live-integration.php @@ -5,13 +5,13 @@ * * @link https://help.transifex.com/en/articles/6261241-wordpress * @package TransifexLiveIntegration - * @version 1.3.39 + * @version 1.3.40 * * @wordpress-plugin * Plugin Name: International SEO by Transifex * Plugin URI: https://help.transifex.com/en/articles/6261241-wordpress * Description: Translate your WordPress powered website using Transifex. - * Version: 1.3.39 + * Version: 1.3.40 * License: GNU General Public License * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Text Domain: transifex-live-integration @@ -75,7 +75,7 @@ } define( 'LANG_PARAM', 'lang' ); -$version = '1.3.39'; +$version = '1.3.40'; require_once( dirname( __FILE__ ) . '/transifex-live-integration-main.php' ); Transifex_Live_Integration::do_plugin( is_admin(), $version );