Jump to content

Multi-language frontend


brandy
 Share

Recommended Posts

Hi!

I have a very simple page, which I want to expand with 4 or more languages.
The first thing you find is the multi-language fields-page on processwire.com.

So I installed the modules and setup the different languages - now I have an tab for every language, which is fine.
But now my question is how the system recognizes the browser-language and connect it to my personally set up language?

For example: My language under Setup is called "Deutsch", how does the system know, if it´s on a browser with German on, that it should show the content of the field "Deutsch"?

Thanks a lot!

Link to comment
Share on other sites

The system doesn't know that. You need to add a language switcher to your frontend so that the user can decide: https://processwire.com/talk/topic/12243-language-switcher-on-front-end/

There's also a module to auto-detect the user's language, but I've never used it: https://processwire.com/talk/topic/8733-autodetect-language/

 

 

Link to comment
Share on other sites

Thanks a lot!

This one sounds good to me:
 

<?php foreach($languages as $language) : ?>
<?php if($user->language->id == $language->id) :?>
<span class="active"><?=$language->title?></span>
<?php else : ?>
 <a href="<?=$page->localUrl($language)?>"><?=$language->title?></a>
 <?php endif;?>
<?php endforeach;?>

But I got an error!
Is there something else to do, so that the system can read the languages?

Link to comment
Share on other sites

Yes - thanks a lot:

 #0 wire/core/Page.php (1512): Wire->___callUnknown('localUrl', Array)
#1 wire/core/Wire.php (419): Page->___callUnknown('localUrl', Array)
#2 wire/core/WireHooks.php (952): Wire->_callMethod('___callUnknown', Array)
#3 wire/core/Wire.php (484): WireHooks->runHooks(Object(HomePage), 'callUnknown', Array)
#4 wire/core/Wire.php (487): Wire->__call('callUnknown', Array)
#5 site/templates/home.php (148): Wire->__call('localUrl', Array)
#6 wire/core/TemplateFile.php (328): require('/var/www/web159...')
#7 wire/core/Wire.php (413): TemplateFile->___render()
#8 wire/core/WireHooks.php (952): Wire->_callMethod('___render', Array)
#9 wire/core/Wire.php (484): WireHooks->runHooks(Object(TemplateFile), 'render', Array)
#10 wire/modules/PageRender.module (575): Wire->__call('render', Array)
#11 wire/core/Wire.php (416): PageRender->___renderPage(Object(HookEvent))
#12 wire/core/WireHooks.php (952): Wire->_callMethod('___renderPage', Array)
#13 wire/core/Wire.php (484): WireHooks->runHooks(Object(PageRender), 'renderPage', Array)
#14 wire/core/WireHooks.php (1060): Wire->__call('renderPage', Array)
#15 wire/core/Wire.php (484): WireHooks->runHooks(Object(HomePage), 'render', Array)
#16 wire/modules/Process/ProcessPageView.module (184): Wire->__call('render', Array)
#17 wire/modules/Process/ProcessPageView.module (114): ProcessPageView->renderPage(Object(HomePage), Object(PagesRequest))
#18 wire/core/Wire.php (416): ProcessPageView->___execute(true)
#19 wire/core/WireHooks.php (952): Wire->_callMethod('___execute', Array)
#20 wire/core/Wire.php (484): WireHooks->runHooks(Object(ProcessPageView), 'execute', Array)
#21 index.php (55): Wire->__call('execute', Array)
#22 {main} 

 

Link to comment
Share on other sites

Sorry guys - I overworked the code:

<?php
	foreach($languages as $language) {
		if($user->language->id == $language->id){
		 echo "<span class=\"active\">{$language->title}</span>";
		} else {
 		 echo "<a href=\"{$page->localUrl($language)}\">{$language->title}</a>";
 		}
 	}?>

Still doesn´t work, but makes more sense now ?
I also tried this one:

<?php
	foreach($languages as $language){
		echo "<a href=\"{$page->localUrl($language)}\">{$language->title}</a>";
		}
	?>

But same error here:

Error: Exception: Method HomePage::localUrl does not exist or is not callable in this context (in wire/core/Wire.php line 563)

Thanks a lot - and sorry for my bad post before!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...