Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for language picker urls in case of subdirectory #284

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/lib/transifex-live-integration-hreflang.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function render_hreflang() {
return false;
}
global $wp;
$disable_canonical_urls = $this->settings['canonical_urls'];
$disable_canonical_urls = isset($this->settings['canonical_urls']) ? $this->settings['canonical_urls'] : false;
$lang = get_query_var( 'lang' );
$url_path = add_query_arg( array(), $wp->request );
$source_url_path = (substr( $url_path, 0, strlen( $lang ) ) === $lang) ? substr( $url_path, strlen( $lang ), strlen( $url_path ) ) : $url_path;
Expand Down
11 changes: 10 additions & 1 deletion includes/lib/transifex-live-integration-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ function render() {
$lang = get_query_var( 'lang' );
$home_url = home_url( $wp->request );
$url_path = add_query_arg( array(), $wp->request );
$source_url_path = (substr($url_path, 0, strlen($lang) + 1) === $lang . '/') ? substr($url_path, strlen($lang) + 1) : $url_path;

// If url contains the language prefix, make sure we don't remove it from url
// in this case return the url_path with e.g engagement => /engagement
// Otherwise remove the part from url string until the language prefix
// e.g el/sample_page =>sample_page
if (strpos($url_path, $lang ) !== false && $url_path !== $lang && strpos($url_path, $lang .'/' ) === false) {
$source_url_path = '/' . $url_path;
} else {
$source_url_path = (substr($url_path, 0, strlen($lang)) === $lang) ? substr($url_path, strlen($lang)) : $url_path;
}
$url_map = Transifex_Live_Integration_Common::generate_language_url_map( $source_url_path, $this->tokenized_url, $this->language_map );
$site_url_slash_maybe = (new Transifex_Live_Integration_WP_Services())->get_site_url($this->is_subdirectory_install);
$site_url = rtrim( $site_url_slash_maybe, '/' ) . '/';
Expand Down
3 changes: 3 additions & 0 deletions transifex-live-integration-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ static function do_plugin( $is_admin, $version ) {

$settings = Transifex_Live_Integration_Defaults::settings();
}
if (!isset($settings['is_subdirectory_install'])) {
$settings['is_subdirectory_install'] = 0;
}
$live_settings = Transifex_Live_Integration_Defaults::transifex_settings();
$debug_mode = ($settings['debug']) ? true : false;

Expand Down
Loading