Marcel Posted May 7, 2019 Posted May 7, 2019 Hey, in the upper right corner of my page I (php noob) want an "EN" button when a user enters the website. If he/she wants to switch to english, he/she can hit the "EN" button and the content + navbar is in english. What I have: - I installed the language and multi language modules. - I switched the content field (textarea) to multi-language. So far the language is linked with the account settings. So in my "test-account" user's account, if I change from default to english, the website is in english - good. But I don't have a login system in the front-end and I want this for guest users who don't have accounts. How can I trigger this? Thank you in advance.
wbmnfktr Posted May 7, 2019 Posted May 7, 2019 There is an example in the _main.php of the Multilanguage Site Profile. You can see it here: https://github.com/processwire/processwire/blob/master/site-languages/templates/_main.php#L65 2
szabesz Posted May 7, 2019 Posted May 7, 2019 4 hours ago, Marcel said: How can I trigger this? As long as the language switcher is concerned: if you only have two languages, then you can do this in your template file: <a href="<?= $page->localUrl($languages->findOther()->first()) ?>"><?= $user->language->name == "default" ? "EN" : "HU" ?></a> Regarding translatable strings, I recommend this method (but in the forum you can certainly find other methods too in order to get inspiration from) : 2
pwired Posted May 7, 2019 Posted May 7, 2019 Here you go, pwired's super language switcher: <ul> <?php $i = 1; foreach($languages as $language) { $var[$i] = $page->localUrl($language); $i++; } echo "<li>" . "<a href=" . '"' . $var[3] . '"' . ">" . "Deutsch" . "</a>" . "</li>"; echo "<li>" . "<a href=" . '"' . $var[2] . '"' . ">" . "English" . "</a>" . "</li>"; echo "<li>" . "<a href=" . '"' . $var[1] . '"' . ">" . "Español" . "</a>" . "</li>"; ?> </ul> Feel free to modify for your own needs, and beautify <ul>, <li> and <a> with your own custom css Here is a recommended read not to fall into unexpected not working language urls:https://processwire.com/talk/topic/19356-language-switcher-do-i-need-to-update-all-urls-in-the-api/ 2
Marcel Posted May 8, 2019 Author Posted May 8, 2019 Cool! Thank you guys! I will go through this all. 1
Marcel Posted May 13, 2019 Author Posted May 13, 2019 Has anyone an idea how I can access the language tab of a field? And is this even possible? When I try the following I just get the account related output (language): $pages->get(1)->get("content_info"); But I would like to have like the particular language like ...->language->default I don't find the right part in the api thank you in advance
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now