Multilanguage

Gast

start at the begin, step by step

#1 - i start with a fresh wb 2.11, all filters activated, but not OpF, JQueryUI, these are the defaults after a new install

#2 - add some pages, BG and EN with type "menu-link", Home-BG and Home-EN with type "wysiwyg" (only to try it). Be sure, that every page has the correct language. Every Subpage (Child) of an Mainpage like BG or EN must have the language from this Parent-Page. it's recommended, to start with the main language and adding there all needed subpages / child for this tree-part

Example-tree here -> https://i.gyazo.com/cc254a6f014b0b44d3911e0e3e282776.png

#3 - the page code
if you have the exact page structure in all language-tree's (here under BG or under EN), WB set the pagescodes automatically, if you click in one page on the pagesettings on the link "pagecode". it is very important, that every page has the correct page code. otherwhise, you get a error, when you switch the pages or you get a redirect to the main-page.

#4 - the code for the index.php
i add your template to my installation (in a fresh WB 2.11). The code is a exact copy from the example in DefaultTemplate (WB-Package) - it works without problems and i can switch the languages from page to page

1. your code to prevent this file for directly access (outside from WB)
if (!defined('WB_PATH')) die(header('Location: ../../index.php'));
Redirect's to a higher level with a relative path like this example (with ../) is a security risk. its possible, to manipulate links like this. it is possible, to come with a manipulated link out of this wb-installation and directly into the server document root or more

WB use since WB 2.10 an prevention like this without a redirect
/* -------------------------------------------------------- */
// Must include code to stop this file being accessed directly
if (!defined('SYSTEM_RUN')) {header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); echo '404 File not found'flush(); exit;}
/* -------------------------------------------------------- */


2. - read the actual language of the selected page

$sPageLang    strtolower(isset($wb->page) || ($wb instanceof frontend) ? $wb->page['language'] : 'EN');
means in simple words: if it's not possible to read the page language, set it to EN (english - if you dont have a english page in this project, change the code to your main language - in your case maybe the favorite Language BG. Write this Language-code in upper Letter. if you not sure about the correct language code, take a look into the favorite language file in folder /languages

3. read the actual page-id
$iPageId = (defined('PAGE_ID') ? PAGE_ID 0);
it's important to use the the flag menu

4. the flag menu - controler
$iMultiLang 0;$sMultiLang ''; if (function_exists('language_menu')){$sMultiLang language_menu('png',false); $iMultiLang intval(!empty($sMultiLang) ? 0);} 
check, if it possible to use the function, result set this switch to true or false
language_menu('png',false) - possible file type's gif, png, svg

5. build href-lang links (optional)
the follow code is only needed, if you want the href-links. if you use this, be sure, that this code in placed behind the open <head> and the closing </head>

if (!function_exists('LangPadeId')) {function LangPadeId(){return $iPageId;}}
if (function_exists('LangPadeId')&&$iMultiLang) {
?>
<!--
    <link rel="alternate" hreflang="x-default" href="[wblink<?php echo LangPadeId($sPageLang);?>]" />
    <link rel="alternate" hreflang="de" href="[wblink<?php echo LangPadeId('DE');?>]" />
    <link rel="alternate" hreflang="en" href="[wblink<?php echo LangPadeId('EN');?>]" />
-->
<?php
    
}
?>


#6 - the flag menu - somewhere between open <body> and closing </body>
the div-block around is only a example, important is the php-code there
<div id="lang" style="height: 2.925em;">
            <?
php if(trim($sMultiLang)!=''){ ?>
            <?php echo $sMultiLang?>
            <?php ?>
        </div>


#7 - working without filters
if your project dont use any filters, specially without FrontendCSS, FrontendJS, RegisterModFiles, SnippetJS, you have to include the file /modules/WbLingual/include.php manually. (and also every other include file from other snippets)

QuoteYou didn't understand me dbs, when I put the codes from the default template the page crash (that's why I removed them and you didn't saw them) ... the menu disappear and only one word stay somewhere behind the logo ... and the EN language doesn't work properly.

for example - if i remove the engine of your car, you cannot drive. And if you add the engine again and it doesnt run and because ot this, you remove it again, the car will not drive - you understand?   :wink:

Step #1 - #4 are only some hints, very important are #2 and #3
from the points 1 - 7, you can remove No.5, if not needed, but all other things are neccessary. every little step is important, it's like a car - if i forgot to add the fuel, the car will not drive, if i forget to add the battery, the car will not drive e.g.

P.S. go to your advanced wb-settings - server settings, set PHP-Errors to production or development for the time, where you work on it, so you get some more informations about possible errors in your error log

if you get more problem's, give us also the used PHP-version - see info-Window here ->







crnogorac081

when i click EN flag i get error and infinite _GET parameter &lng=En..
Web developer

dbs

Hi, i see no WBLingual js. You have before end body this?:
<?php  register_frontend_modfiles_body(); ?>

This loads the frontend_body.js of WBLingual. Maybe it helps.

This part in your index can be removed:
/*       
<!-- show_menu2 -->
*/
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

rumen

You didn't understand me dbs, when I put the codes from the default template the page crash (that's why I removed them and you didn't saw them) ... the menu disappear and only one word stay somewhere behind the logo ... and the EN language doesn't work properly.

Look here now: http://zapryanov.faith/pages/nachalo.php

dbs

Can't see something of multilanguage in your template.
I can't do your work. :wink:
Please look into the DefaultTemplate of WB 2.11. There are some places with multilingual.
First try something.
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

rumen

No, it is my template which is still under development .

This is (attached) without images and fonts, because otherwise the file is big and WB forum reject it.

dbs

Is this the right DefaultTemplate?
In my 2.11 i see in line 42,43
$sPageLang    = strtolower(isset($wb->page) || ($wb instanceof frontend) ? $wb->page['language'] : 'EN');
$iPageId = (defined('PAGE_ID') ? PAGE_ID : 0);
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

rumen

When I call the EN page from back end I get error:

The page isn't redirecting properly

Cliqz has detected that the server is redirecting the request for this address in a way that will never complete.

    This problem can sometimes be caused by disabling or refusing to accept cookies.


And in the address of the browser I see

http://zapryanov.faith/pages/home.php?lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN&lang=EN



And it should be only:

http://zapryanov.faith/pages/home.php?lang=EN

rumen

Maybe I do something wrong, but when I put this code the page crashes.

<?php
// if function LangPadeId doesn't exists, you have to upgrade WBLingual Switcher Add-on to latest version'
if (!function_exists('LangPadeId')) {function LangPadeId(){return PAGE_ID;}}
// to show flags in frontend
    
$iMultiLang 0;$sMultiLang ''; if (function_exists('language_menu')){$sMultiLang language_menu('png',false); $iMultiLang intval(!empty($sMultiLang) ? 0);}
    if (
function_exists('LangPadeId')&&$iMultiLang) {
?>


    <link rel="alternate" hreflang="x-default" href="[wblink<?php echo LangPadeId($sPageLang);?>]" />
    <link rel="alternate" hreflang="de" href="[wblink<?php echo LangPadeId('DE');?>]" />
    <link rel="alternate" hreflang="en" href="[wblink<?php echo LangPadeId('EN');?>]" />



dbs

Take a look into the defaultTemplate.
The menue structure for multilingual is the same like before.
EN,DE,NL... now can also be normal pages (not only menue_link).
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

rumen

I saw there is no need to install multilingual module in 2.11. But - how it works? Any docs? Idea? Hint?