1
Chado
SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/15 14:24

  • Chado

  • Not too shy to talk

  • Posts: 113

  • Since: 2003/6/6 7


This hack will work with news, forum, wf-sections, tinycontent or any module that uses the textsanitizer.
After searching the boards and posting a couple questions that never were answered, I had a go at this myself and well…necessity is the mother of invention….I discovered the module.textsanitizer.php file and messed with it till I got it to work. I am not a coder, so I am sure that someone can improve on this. (More on that later)
First things first:
This hack assumes that you are using the multi-lingual hack that can be downloaded here from ModsCentral.
To install it on Xoops2.x, follow the instructions I posted here.
That will get your XOOPS to be multilingual.

Now to make your content multilingual:
1. Open the module.textsanitizer.php file in the class folder. Around line 145 is the function “&xoopsCodeDecode” After the line
Quote:
$replacements = array();

and before the line
Quote:
$patterns[] = "/\[ code](.*)\\[\/ code\]/esU";

Place this code:
Quote:
//multi-lingual hack by chad--if japanese show japanese else show nothing
global $xoopsConfig;
$patterns[] = "/\[japanese](.*)\[\/japanese\]/sU";
if ($xoopsConfig['language'] == "japanese") {
$replacements[] = '\\1';
} else {
$replacements[] ="" ;
}
//if english show english else show nothing
$patterns[] = "/\[english](.*)\[\/english\]/sU";
if ($xoopsConfig['language'] == "english") {
$replacements[] = '\\1';
} else {
$replacements[] = "";
}
//end multi-lingual hack

Of course you will change the language ('english','japanese') to reflect the languages that you are targeting. The name in the brackets has to match the name of your language pack that you downloaded (or created). You could add more if you are targeting more than 2 languages.

To use this:
When you add your article just enclose the section you want shown in a particular language in brackets with that language name. This is very similar to adding a url or code to an article. For example: Quote:
[english]This is my English text.[/english][japanese]kore ha nihongo desu.[/japanese] This text (not enclosed in brackets) will show up in both (all) languages.


If you are just targeting European languages, you may not have to worry about this, but if you are targeting multi-byte languages like Japanese you may have to manually change the character encoding of your English global.php file to match your japanese one.

That’s it! Basically very simple – If you are having problems with the layout, you probably are putting spaces between the codes.
I hope this helps!
Chad

2
Herko
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/15 19:57

  • Herko

  • XOOPS is my life!

  • Posts: 4238

  • Since: 2002/2/4 1


Excellent hack! Great work!

Herko

3
patagon
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/15 20:10

  • patagon

  • Quite a regular

  • Posts: 235

  • Since: 2002/1/8 0


Chado,

that looks really interesting, thanks for sharing it. Do you have a site where we can see this? i would like to see it working...

Thanks

4
WismeriL
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/15 20:23

  • WismeriL

  • Just popping in

  • Posts: 4

  • Since: 2003/7/7 1


I don't know if it's Chado website but this site :
http://peekaboo.s8.xrea.com:8080/
is using it, you can switch between english and japanese by clicking on the flags.

WismeriL

5
Chado
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/16 3:59

  • Chado

  • Not too shy to talk

  • Posts: 113

  • Since: 2003/6/6 7


Quote:
(More on that later)

I forgot to mention this, but while working on this hack, I tried to make it in such a way that it would automatically adapt to any language without having to go in and change the textsantizer code every time for each language - but I wasn't able to do it. So someone who knows php much better might be able to do it and make this hack something that could be used as is for anyone.....

So, instead of looking for each language (i.e. [english] or [japanese]), would it be possible to do something similar to the font or color code ([ font = Impact]) and have just one code that traps for different language - say something like [lang = english] and then have textsanitizer look at the language and if it is the current language then show the text, else don't show it. Does this make sense??

If someone could do this, it might be a much more useful hack for everyone.

Thanks,
Chad

6
hsalazar
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/16 17:28

  • hsalazar

  • Just popping in

  • Posts: 78

  • Since: 2003/2/6 1


Chad:

When I include the hack in module.textsanitizer.php, the admin side gives me this error message:

"Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/mesadepr/public_html/class/module.textsanitizer.php on line 286"

Obviously, as soon as I remove the hack everything works as usual.

Any thoughts on what is causing this?

PS: I noticed also that on line 149 there's this (I've added a space to separate the word "code" from the bracket):

$patterns[] = "/\[ code](.*)\[\/ code\]/esU";

and not this:

$patterns[] = "/[ code](.*)[/ code]/esU";

Perhaps you've used a different version of the file...

7
mvandam
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/16 19:09

  • mvandam

  • Quite a regular

  • Posts: 253

  • Since: 2003/2/7 2


Quote:

Any thoughts on what is causing this?


I have this problem before... When posting on the forums at xoops.org (or any XOOPS site), some characters in a [ code ] block are changed/removed/show up differently than entered. Generally it affects backslashes and maybe quotes, especially a problem for regexps. i.e. So what you see above is probably not what Chado actually has in the file...

8
patagon
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/16 19:13

  • patagon

  • Quite a regular

  • Posts: 235

  • Since: 2002/1/8 0


Thanks, it works perfectly on that site AFAIK. Seems useful for a future project I want to do, still I dont fully get how it works on the admin side (guess you add text in both languages) but I will look at it more once I'm using it...

9
hsalazar
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/16 20:22

  • hsalazar

  • Just popping in

  • Posts: 78

  • Since: 2003/2/6 1


So, perhaps now the logical step would be to ask Chad if he's willing to share the code in a different format, for example a zip file sent by mail...

Chad?

10
mvandam
Re: SOLVED - Making Xoops CONTENT Multilingual
  • 2003/7/16 23:40

  • mvandam

  • Quite a regular

  • Posts: 253

  • Since: 2003/2/7 2


In case you want this in a hurry...

In your above post, where you pointed out the difference between the line in your file and line in the post, you can basically see what changes you need:

i.e. add a backslash before '[', ']' and '/' in the regular expressions.

Login

Who's Online

245 user(s) are online (153 user(s) are browsing Support Forums)


Members: 0


Guests: 245


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits