Answer the question
In order to leave comments, you need to log in
How to integrate language switcher code?
I have a WordPress site and I want to put a language switch (case, transliterator). Found the code, but how to integrate it?
public function translateToLatin($plain)
{
$textInterpreter = new TextInterpreter();
$textInterpreter->setTokenizer(new LatinTokenizer());
$textInterpreter->addBehavior(new LatinBehaviour([
'салом' => 'salom',
'тожмаҳал' => 'tojmahal',
'қалам' => 'qalam',
'Патир' => 'Patir'
]));
$matches = array();
preg_match('/<a([^"\'>]+)href=["\']?([^"\'>]+)["\']?/', $plain, $matches);
if (sizeof($matches) > 0) {
$url = $matches[2];
str_replace($url, urlencode($url), $plain);
}
try {
$translated = $textInterpreter->process($plain)->getText();
return $translated;
} catch (\Exception $e) {
return $plain;
}
}
$this->translateToLatin($this->title)
Answer the question
In order to leave comments, you need to log in
What values does this code change? Find the relevant wordpress variables and do the substitution.
Or use ready-made solutions, multilingual plugins for wordpress:
Qtranslate X, free
https://ru.wordpress.org/plugins/qtranslate-x/
WPML, paid
https://wpml.org/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question