M
M
mercmarcus2021-08-31 11:19:46
WordPress
mercmarcus, 2021-08-31 11:19:46

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)


Still there is a folder "Converter" there .php files.

Okay, a folder in the file base.

Where to put the code or change under wordpress?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vox_termin, 2021-08-31
@vox_termin

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 question

Ask a Question

731 491 924 answers to any question