Jump to content

Change Default Language to be None-English | Walk Trough


horst
 Share

Recommended Posts

Change Default Language to be None-English | Walk Trough

When you start a new (single) language site and the default language shouldn't be English, you can change it this way:

Go to the modules core section:

pw_change-default-language__002.thumb.jpg.bc0be0ddf0ca31082da556d88407fc54.jpg

 

Select the Language ones by the filter function:

pw_change-default-language__003.thumb.jpg.dadd7e12d2e246d0195c29220194ae47.jpg

 

We have four language related modules here, but for a single language site in none english,
we only need the base module, named "Languages Support". So go on and install it.

pw_change-default-language__004.thumb.jpg.e9fa294589eb9aab1c9d849e8fc484ef.jpg

 

After that, you can leave it, ... 

pw_change-default-language__005.thumb.jpg.da49118b6996334225125ea121a6bdba.jpg

 

... and switch to the newly created Language section under SETUP:

pw_change-default-language__006.thumb.jpg.b52c53018304d58a5524cf9814b3ce03.jpg

 

Select the default language

pw_change-default-language__008.thumb.jpg.c6ab28344d0f532feeb2b582ee093c63.jpg

 

Enter your new language name or its Shortcut and save the page.
I will use DE for a single language site in german here as example:

pw_change-default-language__009.thumb.jpg.225a124c069eb17895cf5cb05b262b3a.jpg

 

Now I go to the ProcessWire online modules directory, down to the subsection for language packs and select
and download my desired (german) one: 

pw_change-default-language__010.thumb.jpg.755b7f9644080edb9d548b348022d492.jpg

 

pw_change-default-language__011.thumb.jpg.52e550006f97070c9b4e859013f20854.jpg

 

pw_change-default-language__012.thumb.jpg.19c4883d4d2e0be7ae6cbfaf207a3557.jpg

 

pw_change-default-language__013.thumb.jpg.55f4cebc4b5c94da37d6a73dd362f664.jpg

 

After downloading a lang pack as ZIP, I go back into my SETUP > LANGUAGES > default language page in admin,
select the downloaded lang pack ZIP and install it:

pw_change-default-language__014.thumb.jpg.1f10ef4f16c17e379f386ef01e08feb8.jpg

 

pw_change-default-language__015.thumb.jpg.2fc150e3c9d1ab6c2649fd8290f26e57.jpg

 

pw_change-default-language__017.thumb.jpg.7f84b2e81f41bcdda4042af11046a048.jpg

 

 

After the ZIP is uploaded, the files are extracted and installed, most of my screen is already in
the new default language. To get all fully switched, we save and leave that page, ...

pw_change-default-language__018.thumb.jpg.a37607ae2e2da189dc0709a18d5809ac.jpg

 

... and completely logout from the admin.

pw_change-default-language__019.thumb.jpg.56d5d07b246c8e7a98fb1b58d7f36fc8.jpg

 

Now, of course, we directly login back, ...

pw_change-default-language__021.thumb.jpg.df04b91ee8ead4e6699641890a56ff68.jpg

... and see, that now also the cached parts of the admin have switched to the new default language. ?

pw_change-default-language__022.thumb.jpg.8002c445925f5ef1125abe3c3c8463a1.jpg

 

That was it for a single language site in none english.

 

If you want to have a multi language site, just add more languages to the SETUP > LANGUAGES section.

When using a multi language site, I think you also want to use multi language input fields, and maybe different page names for your language page pendents. If so, you need to go into MODULES > CORE > filter LANGUAGE and install what you need or want to use of it, (if not already done).

Thanks for reading and happy coding, ?

 

  • Like 15
  • Thanks 7
Link to comment
Share on other sites

  • horst pinned this topic
8 hours ago, kongondo said:

Excellent work @horst. Thanks for obliging and doing this ?

 

Thanks @kongondo,

You also have a not inconsiderable share on it. You encouraged me to improve a post that was to short with a much to vague description by giving me directly a list of improvements.
So thanks for your work on this! ?

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
  • 9 months later...

A brilliant tutorial.

Did this with the minimal multilanguage site offered for installation. Default language is now German as wanted. 

Then I uninstalled and reinstalled English.

The main menu 'home' link is pointing to 'pw/<german homepage>, which is  as it should be, while the 'about' link points to 'pw/en/about', which should be 'pw/about'. 

In the page settings of the 'about' page the hierarchy of the DE page is 'en/about', while the hierarchy string for the EN page is '/about'. See attached screenshot.

The link of the latter is pointing to http://butoh-tanz.de/pw/about/ but clicking it we end up on http://butoh-tanz.de/pw/en/about/ 

The language menu does show both 'de' and 'en' links, as desired. But the 'en' link points to '/pw' (the processwire root, one level below site root, as this is experimental) instead of 'pw/en/'. Clicking on any link in the language menu does not change anything on any page. The 'home' page stays German while all other pages stay English. 

So obviously this method does not achieve the goal to completely reverse the language hierarchy, with all German pages having a 'pw/<pagename>' URL and all English pages having a 'pw/en/<pagename>' URL. This is absolutely no critique, as you wrote your tutorial for a single language site. 

I just would be thankful for a hint how to achieve this URL string reversal. 

 

 

image.thumb.png.372887326e01b232c3ddfbc976cab010.png

Link to comment
Share on other sites

18 minutes ago, dlen said:

So obviously this method to completely reverse the language hierarchy, with all German pages having a 'pw/<pagename>' URL and all English pages having a 'pw/en/<pagename>' URL does not work. This is no critique, as you wrote yout tutorial for a single language site. 

You can set this under Homepage > edit like shown here:

image.png.2ddf37e3fae23dea3bb335c7bd975f1a.png

Does this solve your issue?

  • Like 1
Link to comment
Share on other sites

Brilliant. Now the menu works as advertized and the page URLs reflect the respective language, i.e. '/' in the case of German, '/en/' in the case of English. 

Only the hreflang attributes in the header links are causing some headscatching:

	<link rel='alternate' hreflang='home' href='http://butoh-tanz.de/pw/' />
	<link rel='alternate' hreflang='en' href='http://butoh-tanz.de/pw/en/' />	

The second looks o.k., while the first I do not understand. Shouldn't it be 'de'?

Link to comment
Share on other sites

Sure. It is the original code fresh after installation, in _main.php:

<?php
	
	// handle output of 'hreflang' link tags for multi-language
	// this is good to do for SEO in helping search engines understand
	// what languages your site is presented in	
	foreach($languages as $language) {
		// if this page is not viewable in the language, skip it
		if(!$page->viewable($language)) continue;
		// get the http URL for this page in the given language
		$url = $page->localHttpUrl($language); 
		// hreflang code for language uses language name from homepage
		$hreflang = $homepage->getLanguageValue($language, 'name'); 
		// output the <link> tag: note that this assumes your language names are the same as required by hreflang. 
		echo "\n\t<link rel='alternate' hreflang='$hreflang' href='$url' />";
	}
	
	?>
	

I could live with that for the time being, as it is only an SEO issue, but of course it would be nice having it working.

Link to comment
Share on other sites

@dlen I forgot, that the name of the default language is always default and can not be changed.

Please try this updated code. BTW: where did you took that code example from?

 

<?php
	
$alternate_languages = '';
foreach ($languages as $language) {
  // if this page is not viewable in the language, skip it
  if (!$page->viewable($language)) {
    continue;
  }
  // get the http URL for this page in the given language
  $url = $page->localHttpUrl($language);
  // output the <link> tag: note that this assumes your language names are the same as required by hreflang.
  if ($language->name === 'default') {
    $alternate_languages .= "\n\t<link rel='alternate' hreflang='x-default' href='$url' />";
  }
  else{
    $alternate_languages .= "\n\t<link rel='alternate' hreflang='{$language->name}' href='$url' />";
  }
}
	echo $alternate_languages;
	?>

 

  • Like 1
Link to comment
Share on other sites

Thx.

I used another solution, which does the job.

		foreach($languages as $language) {
			if(!$page->viewable($language)) continue;
			$url = $page->localHttpUrl($language);
			$hreflang = $homepage->getLanguageValue($language, 'name'); 
			if ($hreflang == 'home') $hreflang = 'x-Default';
			echo "\n\t<link rel='alternate' hreflang='$hreflang' href='$url' />";

The code example stems from the freshly installed multilanguage demo site.

  • Like 1
Link to comment
Share on other sites

  • 2 years later...
  • 8 months later...

Thanks for this cool explanation! I converted an existing website to a multilanguage site with DE and EN. After finishing all steps, I noticed, that in all fields the english tab was the active one. But it had to be the opposite way. So I deactivated / uninstalled  the Core -> Language -> Languages Support - Tabs module. Logged out and in and reinstalled the Languages Support - Tabs module. And voilà, now all DE tabs are the active ones.

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

So far I can see this works fine for changing the UI of the site.

However, my site still has 
```
<!DOCTYPE html>
<html lang="en">
    <head id="html-head">
```
in the source code? 

Is that supposed to be changed too with changing the default language?

Or do I have to change the _main.php file for that?

Link to comment
Share on other sites

@Kaj Kandler Do this in your _main.php:

$html_language_code = $user->language->name;

if ($user->language->name === "default") {
    $html_language_code = "de";
}
<html lang="{$html_language_code}">

This queries the language set by the user and sets the correct language code for the html tag

  • Like 2
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

×
×
  • Create New...