There was a discussion on slack recently talking about a replacement for the now deprecated Google Translate Widget - you can no longer add that to new sites.
One suggestion is:
- go to https://translate.google.com/
- paste in your URL to your site in the left hand side
- on the right select the language you want to translate to, and then click on the link displayed in the right hand box
That will create a link to a translated version of the URL, e.g.
That link can be then directly added to your site wherever you need as normal content, and you can create a series of links for the different language suggestions you want to make (a visitor can pick any language once viewing a translation).
But if you’re editing your own theme, and want something more dynamic based on the page you are on, some code like this could be used:
<?php $args = '/?_x_tr_sl=auto&_x_tr_tl='; $path = \Concrete\Core\Support\Facade\Url::to(\Concrete\Core\Page\Page::getCurrentPage()); $pieces = parse_url($path); $url = 'https://' . str_replace('.', '-', str_replace('-', '--', $pieces['host'])) . '.translate.goog' . $pieces['path'] . $args; ?> <p> Translate this page into <a target="_blank" href="<?= $url . 'fr'; ?>">French</a>, <a target="_blank" href="<?= $url . 'es'; ?>">Spanish</a>, <a target="_blank" href="<?= $url . 'ar'; ?>">Arabic</a>, <a target="_blank" href="<?= $url . 'ru'; ?>">Russian</a>, and other languages </p>