Summary: Talk page for MultiLanguage.
Maintainer: Blues
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.


Anyone a idea how to add a active-language page variable to this script? The following seams not to work:

 $FmtPV['$userlang'] = "'$userlang'";

Oky I got one, don't no if it's best practice:

 $userlang = $_COOKIE['userlang'];
 $FmtPV['$userlang'] = "'$userlang'";

noskule July 02, 2007, at 06:59 AM

Linda Ursin? August 12, 2012, at 10:35 AM

Do any of you know exactly where the files for the flags should be placed? I've tried several locations, but I can't get them to show.

I can't get the DefaultLanguage to show. Language pages are only shown after a cookie was set. The text after the (:if:) tag is shown to in all languages. Debugging a bit: it has something to do with $PCache[$pagename]['languages']. It is not loading the languages key from the wiki file. I couldn't find the way to load those keys, here on Renato

I couldn't get my default language for first time visitors, too, but because of a feature rather than a bug: The browser's preferred languages prevail over the recipe's default languages. I didn't want that, because our university browsers prefer English over Dutch (my default). So I simply disregard the browser preferences by deleting the following three lines from the recipe:

	} else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $userlang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);


Very nice script. I'm just wondering how I change XLPage definitions. I tried with

    if ($userlang == 'de') {

This seams only to work if userlang is spezified in the url with ?userlang=XX, or if there is a (if userlang XX) statement is in the page. How do I change this that it keeps the language also if there is no (:if userlang . .. staement?noskule April 15, 2006, at 03:58 PM

Yes, I have the same problem (lean skin). flox April 15, 2006, at 05:30 PM
I guess this is because the script only gests executed if a (:if userlang XX markup is present in the wikitext. So we have to search a way to execute the script with every pageload not only if the markup is present. Do you have any idea how? Better would be a variable $ExecuteMultilanguageOnPageLoad = 1 (mabe with a shorter name) . . ..noskule April 16, 2006, at 04:32 AM
The script is already executed at every page load even if no multilanguage markup is present.
The problem is in the way that default languages work. For example, if the user selected german (with a ?userlang=de in the URL but in the current page german is not defined, then the language will automatically switch to the default (let's say english), thus $userlang becomes 'en'.
The original language request of the user, though, is kept in a cookie so that if the user which selected german will at a certain point go to a page where german is defined then it will display german.
So, if you wish to select the XL page regardless of the page definition but according to user selection, you can use the cookie ($_COOKIE['userlang']).
eg. if ($_COOKIE['userlang'] == 'de') { ...
I hope that it is enough for your needs.

Blues April 17, 2006, at 03:11 AM

yep thats great. I did update the Configuration Section, I hope thats ok. grz nos
Please note, though, that using this in the configuration may lead to pages displaying contents in two different languages (one from the XL page based on user selection, and one from the markup based on languages defined). Which might be not desirable.

Blues April 17, 2006, at 06:27 AM

I have a problem: my Site.SideBar contains English and Italian versions, however only some of my main pages contain Italian versions. On a page with no Italian version the English version of the SideBar is used instead of the Italian version. Is there a way to fix this? Also, if the page doesn't contain any (:if userlang en:) then my SideBar is empty because none of the translations are displayed.

Chris Morison? August 08, 2006, at 05:39 AM

I have the same problem as above. I love this recipe but I would like to have more flexibility. Let me try to describe my view about this.
1. A parameter should define the default language, whatever is the cookie or the choice of the user.
2. The marker (:if userlang xx:) .... (:if:) could be called as many times as wished in the same page, including the SideBar.
3. Inside the marker if userlang doesn't fit any, use the default language instead if exists. If nothing fits, blank text.
4. Outside the marker leave the text as it is.

Philippe? August 19, 2006, at 05:39 PM

I'm also wondering about the above sidebar problem. I really don't want to have to go through all my files and add (:if userlang en:) when I don't have or need a different language version. I tried to put something like that in the group header file but expressions don't seem to bridge the gap from header to text body. Actually all we really need to fix this is an (:else:) command, but I guess I'm just too used to more robust programming languages to think of a simple solution (without infrastructure changes). If anyone has figured out a good way to solve this issue please reply. Thanks.

Kale Stutzman? September 11, 2006, at 10:19 AM

My solution is as follows. Edit the multilanguage.php script and insert the lines:
$Conditions['userlang2'] = '$GLOBALS[\'userlang2\']==$condparm';
before line 54:
if ($pagename=='') {
Then only use (:if userlang ..:) on main pages, and use (:if userlang2 ..:) on SideBar, Footer, and any other pages. The problem is caused by the variable userlang being reset to default if the current main page doesn't contain the chosen language, forcing the SideBar and other pages into a different language. My solution works by setting userlang2 before userlang is reset. Works for me, but please test first...

Chris Morison? September 21, 2006, at 10:07 AM

It does work for me as well, Chris.
Just, if you ask for a language which is not defined with (:if userlang2 ..:) then the SideBar comes out empty, again.

Luigi November 27, 2006

I can't find out how to specify a different page title for each language ("multilanguage titles support"). Might this be a misunterstanding, is there no possibility to translate the page titles? Martin Zbinden, November 26, 2006

Please try:

(:if userlang tr:)
(:title Turkish Title:)
Turkish text
(:if userlang de:)
(:title German Title:)
German text
(:if userlang it:)
(:title Italian Title:)
Italian text

Luigi November 27, 2006

Very useful script. I have two problems though. First, when PageNotFound is loaded, the language links become edit links ?action=edit and are lacking ?userlang=XX. This is a problem because the page creation reverts to the default language instead of the current userlang.

Second, I have to click on the language switch link twice before it "takes" on headers/footers. I can see that the cookie does change to the new language - and the page text too - on the first click, but the headers/footers don't. SteP 7 February, 2007

I found how to fix both problems. I think this fix may fix other people's problems, and make userlang2, as proposed in another comment, unnecessary.
Change the code to set the cookie array userlang element for the current page -- see php manual, setcookie common errors.

So in version 1.0b of the script, tested with PmWiki 2.1.27, change around line 52

	} else {
		$userlang = $DefaultLanguages[0];
	$_COOKIE['userlang']=$userlang; // add this line

It fixed all my problems. Good luck. SteP February 12, 2007, at 03:35 PM

Somebody know if is possible that with this recipe the links generated to another language goes to a different site that also is using PMWiki. Example:

I have I want to put the english option on the left for this page but going not in the same domain.. if somebody clicks in english then will be sent to

Is this possible?

Thanks in advance Pablo

Ventolin? April 12, 2007

Version 1.1 works better with the Category group than the previous versions, however there's still a problem. In Category.GroupFooter included by Category pages, userlang is set to the default language, instead of the language set in the cookie. This ends up displaying the skin in the cookie language, and page contents in the default language. I tried this fix which seems to be working OK here, though it needs more testing on sites where multilanguage.php is in use.
After line 85 add the two lines marked 'SteP added'.

85		} else {
86			$userlang = $_COOKIE['userlang']; // SteP added
87			if($userlang=='')                 // SteP added
88			$userlang = $DefaultLanguages[0];

Good luck! SteP August 19, 2007, at 08:53 PM

I had this problem not with GroupFooter(s), but with the whole site. If your wiki is only displaying the default language translation, use this fix. Renato

SteP July 28, 2009 List threads and describe how to patch function MultiLanguageTitle to support the PTV markup {Group.Page$Title}.

See also MultiLanguageViews

There's a problem when used with the IncludePage function: if there is e.g. a specification to include a specific number of lines into the current page, enclosed in multiple if statements, this works correctly in the first language, but in the second one it hides the entire section, where the page was supposed to be placed. JanBrejcha

Caution: # 1.0b - 03.04.2006 fix (Fixed a problem when $pagename is not set)
If somebody change - $DefaultGroup = "Anygroup"; - in config.php it must be bevor the inclusion of multilanguge.php, which seem's to be normal.

Buz if you use famconfig.php mulitlangange.php must be after execution of config.php. But I'm wondering, wether this fix is correct all, as it's IMHO the task of pmwiki to assemble the pages. My application find's the correct entries again when commenting out this fix.
PatrickOgay Oct 15, 2007, at 01:00 PM

I am using it since some time and I find the "recipe" useful, now I have many pages with 1, 2 or 3 different versions of the text. I use pmwiki to manage a small personal website.

I am now trying to generate automatically the index pages for the different sections (I should have done it in advance...) and I found an issue. I use the following line in order to select only the pages with the german language:

 pagelist order=-ctime group=-PmWiki*,-Site* name=-RecentChanges fmt=#titlesummary if="langinpage de {=$FullName}"

The titlesummary template is the following:

[[#titlesummary]] [[{=$FullName} | {=$Titlespaced}]] -> {=$Description} ({=$LastModified}) [[#titlesummaryend]]

It works, but I am not able to select only the description of the specified language. I always get all the three descriptins. Is there a workaround?

Default language doesn't work. So if i have two languages in a page, 'de' and 'en', no one is displayed. But I set $DefaultLanguages = array('de','en');

flox (19.03.2006)

Did you set the $DefaultLanguages before including the script? If yes, could you explain better? Make some experiment with different combinations?

Blues March 30, 2006, at 06:32 AM

Yes. Before including the script. You can test it here. I have to use for example?userlang=en, before the variable userlang is avaiable. flox March 31, 2006, at 02:41 PM

Please try the new version (1.0b) and see if the problem is solved.

Blues April 03, 2006, at 05:38 AM

It seems to be solved. Thank you very much!


Talk page for the MultiLanguage recipe (users?).