pll_translate_string() returns only default language’s string translation
-
Hi there.
First of all thanks for this free multilingual solution. I’ve been using it for years now with no issues. But.. today I got one that I can’t debug myself or search for solution online.
Long story short – I have WordPress 5.6 with Polylang 2.9.1 set with two languages – Latvian and English. In order to internationalize URL’s I’ve set some custom rewrite rules that worked fine for both languages before.
I’m initializing registry of custom translatable strings within
functions.php
file like so:<?php /** * Register rewrite strings for Polylang string translation */ add_action('init', function() { global $theme_rewrites; // Definitions $t10e_strings = array( // ... 'period' => array( 'slug' => 'period', 'tag' => 'theme_period', 'order' => 4, 'values'=> array( '1-day' => __('1 diena', 'theme'), '1-week' => __('1 nedēļa', 'theme'), '1-month' => __('1 menesis', 'theme'), '6-months' => __('6 mēneši', 'theme'), '1-year' => __('1 gads', 'theme'), ) ) ); // Register strings foreach($theme_rewrites as $theme_rewrite_key => $theme_rewrite) { pll_register_string($theme_rewrite['slug'] . '_slug', $theme_rewrite['slug'], 'Theme URLs'); // Register Period values if($theme_rewrite_key == 'period'){ foreach($theme_rewrite['values'] as $theme_period_key => $theme_period) { pll_register_string($theme_rewrite_key . '_key_' . preg_replace('/(-|\s)/u', '_', $theme_period_key), $theme_period_key, 'Theme URLs'); } } } });
And then on querying
theme_period
in my custom page templatepage-events.php
I’m calling for the translatable string like so:
$theme_period_key = pll_translate_string(get_query_var('theme_period'), "en");
I’ve double checked that translatable strings are shown and properly set for both languages in
Dashboard
>Languages
>String translations
and also double checked that both languages are set and are callable. So at this point I’m not sure what’s the problem here. I’ve tried flushing rewrite rules and debugging it, but I still get Latvian (default) string instead of English one.I would appreciate any help possible to resolve this issue.
- The topic ‘pll_translate_string() returns only default language’s string translation’ is closed to new replies.