horst Posted May 10, 2020 Posted May 10, 2020 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: Select the Language ones by the filter function: 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. After that, you can leave it, ... ... and switch to the newly created Language section under SETUP: Select the default language 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: Now I go to the ProcessWire online modules directory, down to the subsection for language packs and select and download my desired (german) one: 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: 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, ... ... and completely logout from the admin. Now, of course, we directly login back, ... ... and see, that now also the cached parts of the admin have switched to the new default language. ? 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, ? 15 7
kongondo Posted May 10, 2020 Posted May 10, 2020 Excellent work @horst. Thanks for obliging and doing this ? 3
horst Posted May 10, 2020 Author Posted May 10, 2020 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! ? 1
dotnetic Posted June 3, 2020 Posted June 3, 2020 Thanks @horst for this tutorial, which is very good for new users. I also updated the link in the README of the german language pack: https://github.com/jmartsch/pw-lang-de/blob/master/README.md 1
dlen Posted March 25, 2021 Posted March 25, 2021 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.
horst Posted March 25, 2021 Author Posted March 25, 2021 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: Does this solve your issue? 1
dlen Posted March 27, 2021 Posted March 27, 2021 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'?
dotnetic Posted March 28, 2021 Posted March 28, 2021 Please show us the code that you use to generate the hreflang output.
dlen Posted March 28, 2021 Posted March 28, 2021 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.
dotnetic Posted March 29, 2021 Posted March 29, 2021 Please check if the name of your german language is really "de", if not, please add it. I am not talking about the de name of the homepage, but the name of the language
dlen Posted March 29, 2021 Posted March 29, 2021 The name is "default" - or did you mean another place to look?
dotnetic Posted March 30, 2021 Posted March 30, 2021 @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; ?> 1
dlen Posted April 1, 2021 Posted April 1, 2021 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. 2
cwsoft Posted May 31, 2023 Posted May 31, 2023 @horstThanks for the tutorial. Still useful for newbies like me. Now I have a German backend too, great! 2
neophron Posted February 13, 2024 Posted February 13, 2024 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. 1
Kaj Kandler Posted November 7, 2024 Posted November 7, 2024 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?
dotnetic Posted November 8, 2024 Posted November 8, 2024 @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 2
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