Poor man's multilanguage enhancement v2.0 - enhanced

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Fexxx
Posts: 36
Joined: Fri 10. Jun 2005, 15:20

Post by Fexxx »

navigation = site strucure (category title:) ?
ChantalC
Posts: 16
Joined: Sun 24. Jul 2005, 18:25
Location: Berlin
Contact:

Post by ChantalC »

Hi Fulvio,

I tested your script. It's working good, but the switching is too slow.

When does your next Version come?

I could need it.
Gruß / regards

CC
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

sorry, here it is:
same usage, paste this code below in a file called languages.js

-------------------------------------------------------------------------

/*
* Shows document in specified language, via Javascript
* For use with phpwcms language extensions
*
* Remembers user preferred language via cookies. Language cookie expires at end of session (browser close)
*/
var strCurrentLanguage = 'IT'; // language to start with (default language)
var aAvailableLanguages = new Array('IT','EN','DE'); // array pf available languages in the document
var strLanguageCookieName = 'currentLanguage'; // name of the cookie where selected language is stored
var strInvisibleOnLoadClass = 'invisibleonload'; // name of the class wick marks elements invisible on page load (this script makes them visible)
var bLanguageDebug = false; // if set to true show alerts during transoformation steps


// ----------------------------------------------------------------------
// Do not edit below this line
// ----------------------------------------------------------------------
function addEventFunction(strEvent, fFunction, oObject)
{
if (!oObject) oObject = window;
if (oObject.addEventListener) {
oObject.addEventListener(strEvent, fFunction, true);
return true;
} else if (oObject.attachEvent) {
return oObject.attachEvent('on'+strEvent, fFunction);
} else {
return false;
}
}
function setLanguageCookie()
{
document.cookie = strLanguageCookieName+"="+strCurrentLanguage;
}
function getLanguageCookie() {
var strCookie=""+document.cookie;
var iPos=strCookie.indexOf(strLanguageCookieName);
if (iPos==-1) return "";
var iPos2=strCookie.indexOf(';',iPos);
if (iPos2==-1) iPos2=strCookie.length;
return unescape(strCookie.substring(iPos+strLanguageCookieName.length+1,iPos2));
}
function langTagOpen(strLanguage)
{
return '{'+strLanguage+'}';
}
function langTagClose(strLanguage)
{
return '{/'+strLanguage+'}';
}
function stripLanguage(strText,strLanguage)
{
var aSplittedText = strText.split(langTagOpen(strLanguage));
var strLanguageText = aSplittedText[0];
for (var i = 1; i < aSplittedText.length; i++) {
var aSplittedText2 = aSplittedText.split(langTagClose(strLanguage));
strLanguageText += aSplittedText2[1];
}
return strLanguageText;
}
function parseTextLanguage(strText)
{
var strLanguageText = strText;
for (var i = 0; i < aAvailableLanguages.length; i++) {
if (aAvailableLanguages != strCurrentLanguage) {
strLanguageText = stripLanguage(strLanguageText,aAvailableLanguages);
}
}
strLanguageText = strLanguageText.replace(new RegExp(langTagOpen(strCurrentLanguage),"g"),'');
strLanguageText = strLanguageText.replace(new RegExp(langTagClose(strCurrentLanguage),"g"),'');
return strLanguageText;
}
function parseLanguageDocument()
{
if (bLanguageDebug) alert('languages.js: Starting...');
var prefLanguage = getLanguageCookie();
var prefOk = false;
for (var i = 0; i < aAvailableLanguages.length; i++) {
if (aAvailableLanguages == prefLanguage) prefOk = true;
}
if (!prefOk)
setLanguageCookie();
else {
strCurrentLanguage = prefLanguage;
setLanguageCookie();
}
parseLanguageElements();
if (bLanguageDebug) alert('languages.js: Translation done.');
}
function parseLanguageElements(oNode)
{
if (!oNode) oNode = document.body;
if (strInvisibleOnLoadClass=="") return;
if (oNode.className == strInvisibleOnLoadClass) {
if (!oNode.innerHTML) return;
if (!oNode.originalHTML) oNode.originalHTML = oNode.innerHTML;
oNode.innerHTML = parseTextLanguage(oNode.originalHTML);
if (bLanguageDebug) alert('languages.js: Translated block.');
oNode.style.visibility = 'visible';
if (bLanguageDebug) alert('languages.js: Block made visible.');
}
if (!oNode.childNodes) return;
for (var i = 0; i < oNode.childNodes.length; i++)
parseLanguageElements(oNode.childNodes);
}
function changeLanguage(strLanguage)
{
if (strLanguage == strCurrentLanguage) return;
for (var i = 0; i < aAvailableLanguages.length; i++) {
if (aAvailableLanguages == strLanguage) {
strCurrentLanguage = strLanguage;
setLanguageCookie();
parseLanguageElements();
}
}
}
addEventFunction('load',parseLanguageDocument);
Completeness is reached through subtraction, not through addition
ChantalC
Posts: 16
Joined: Sun 24. Jul 2005, 18:25
Location: Berlin
Contact:

Post by ChantalC »

Hi Fulvio,

First thanks for your new langague code.

I have uploaded your new languages.js file, but now the switch between the languages works not anymore. Now I see both Languages = DE and EN.

:cry:
Gruß / regards

CC
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

you should have links like

<a href="#" onmouseover="changeLanguage('IT');">link</a>

it's working on http://www.fieradellamusica.it - try to look at the source code... :?
Completeness is reached through subtraction, not through addition
ChantalC
Posts: 16
Joined: Sun 24. Jul 2005, 18:25
Location: Berlin
Contact:

Post by ChantalC »

Yes, I had this links. I only changed the languages.js file.

But I don't understand it anymore, the new file will not work. I'm driving crasy. :cry:

Working with the old languages.js: http://www.artdeco-zeidler.de/index.php?tische

Not working the new languages.js: http://www.artdeco-zeidler.de/index.php?sofa

Do you have any idea?
Gruß / regards

CC
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

did you insert
<style type="text/css">.invisibleonload {visibility:hidden}</style>

before?
Completeness is reached through subtraction, not through addition
ChantalC
Posts: 16
Joined: Sun 24. Jul 2005, 18:25
Location: Berlin
Contact:

Post by ChantalC »

Yes, I have seen this in your sourcecode.
Gruß / regards

CC
ChantalC
Posts: 16
Joined: Sun 24. Jul 2005, 18:25
Location: Berlin
Contact:

Post by ChantalC »

Fulvio Romanin wrote:did you insert
<style type="text/css">.invisibleonload {visibility:hidden}</style>

before?

Now it works great. Thanks for this script.

I found the required parts to set the "invisibleonloads".

Thanks.
Gruß / regards

CC
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

glad you liked it ;)
Completeness is reached through subtraction, not through addition
sebby
Posts: 28
Joined: Thu 28. Apr 2005, 00:31

Post by sebby »

Hello all-

For those beginners like me experiencing difficulties with the second version of this nice script from Fulvio, don't forget the following changes in your template:

(1) Add this line in your html head:
<style type="text/css">.invisibleonload {visibility:hidden}</style>

(2) your multilang content must be delimited by the "invisibleonload" class tag:

<div class="invisibleonload">{CONTENT}</div>

so open your header with: <div class="invisibleonload"> and close your tag in the footer section of your template '</div>').

Cheers !

Sebby
Last edited by sebby on Sun 29. Jan 2006, 16:57, edited 2 times in total.
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

thx sebby! :D
Completeness is reached through subtraction, not through addition
Evoplure
Posts: 43
Joined: Fri 8. Jul 2005, 02:59

Post by Evoplure »

brans wrote:I have added this mod to the dev forum:
--...--/index.php/topic,117.0.html
I found some problems installing the mod, so I made some changes in the code. They worked for me, but I don't know if they will be useful for other people. Anyway, I posted that changes in:

--...--/index.php/topic,185.0.html
* Maybe I'm wrong * Maybe not *
tsl
Posts: 28
Joined: Sat 27. Aug 2005, 16:34

Post by tsl »

Thanks Fulvio for this excellent mod :D
It just made my week!

I have however a question:
Is it possible to make the switch to other laguages only when you actually click on a link or i.e an image? Now the switch is made just by moving the cursor over it (probably from the "onmouseover" tag). It's also set when you click off course.

Thank you
-tsl-
tsl
Posts: 28
Joined: Sat 27. Aug 2005, 16:34

Post by tsl »

Ok, just changed from onmouseover to onClick in the links did it!

Another question...
How can I limit the built in search content type in wcms v1.8 to only display the current lang content?
Possible?

Thanks
-tsl-
Post Reply