Merging html and fields into i18n

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Merging html and fields into i18n

Postby Morley » Tue Oct 19, 2004 5:41 pm

Using HTML in i18n works well. But what about merging both HTML and field calls simultaneously.

I need to convert the following into i18n:
Code: Select all
var msg = '';
msg += '<html>Welcome <b><font color="red">' + user_name + '</font></b><br>';
msg += 'of <b><font color="red">' + gusercomid$to_com.company_name + '</font></b> ID ' + globals.gservoy_id;
plugins.dialogs.showInfoDialog( 'Info',msg);
I've tried the following workaround which, on the face of it, is logical, but it's missing a critical factor -- it also doesn't work.
Code: Select all
var title = i18n.getI18NMessage('7office.dlg.welcome');
var msg = '';
msg += '<html>' + i18n.getI18NMessage('7office.dlg.welcomemsg1') + '<b><font color="red">' + user_name + '</font></b><br>';
msg += ' ' + i18n.getI18NMessage('7office.dlg.welcomemsg2') + ' <b><font color="red">' + gusercomid$to_com.company_name;
msg += '</font></b> ' + i18n.getI18NMessage('7office.dlg.welcomemsg3') + ' ' + globals.gservoy_id
plugins.dialogs.showInfoDialog(title, msg);
Is there a way someone has worked out?
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby bcusick » Tue Oct 19, 2004 6:58 pm

Hi Morley,

I do this all the time. What doesn't work in your code? You're on the right track.

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby Morley » Tue Oct 19, 2004 7:41 pm

bcusick wrote:I do this all the time. What doesn't work in your code? You're on the right track.
The first attempt renders the first word properly, thereafter forgets that it's interpreting html. In the following I added <html> before each piece of html code.
Code: Select all
var title = i18n.getI18NMessage('7office.dlg.welcome');
var msg = '';
msg += '<html>' + i18n.getI18NMessage('7office.dlg.welcomemsg1') + '<html><b><font color="red">' + user_name + '<html></font></b><br>';
msg += ' ' + i18n.getI18NMessage('7office.dlg.welcomemsg2') + '<html><b><font color="red"> ' + gusercomid$to_com.company_name;
msg += '<html></font></b> ' + i18n.getI18NMessage('7office.dlg.welcomemsg3') + ' ' + globals.gservoy_id
plugins.dialogs.showInfoDialog(title, msg);
Better, but I'm missing something. There's a line break at each section, rather than a continuous line of text.
Attachments
i18nProblem.png
i18nProblem.png (8.01 KiB) Viewed 5035 times
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby bcusick » Tue Oct 19, 2004 9:31 pm

Morley,

Take out the var msg = '' - you don't need it.

I can't duplicate your results. If I do this code:

Code: Select all
var x = "<html><b>" + i18n.getI18NMessage("s.solution_title") + "</b>"
x += " _ " + i18n.getI18NMessage("s.tt_admin")

plugins.dialogs.showInfoDialog( "title", x, "ok")


Everything is just as expected (one line).

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby Morley » Wed Oct 20, 2004 3:15 pm

Bob, the difference between your code and mine is I'm switching into and out of bold and red, back and forth. Here's my code, then what I'm after done without i18n, followed by what this code renders. I have my doubts if Servoy can currently do what I'm attempting.
Code: Select all
var title = i18n.getI18NMessage('7office.dlg.welcome');
var msg = '<html>' + i18n.getI18NMessage('7office.dlg.welcomemsg1') + '<b><font color="red">' + user_name + '</font></b><br> ';
msg += + i18n.getI18NMessage('7office.dlg.welcomemsg2') + '<b><font color="red"> ' + gusercomid$to_com.company_name;
msg += '</font></b> ' + i18n.getI18NMessage('7office.dlg.welcomemsg3') + ' ' + globals.gservoy_id
plugins.dialogs.showInfoDialog(title, msg);

Attachments
msg2.PNG
msg2.PNG (7.05 KiB) Viewed 5018 times
msg.PNG
msg.PNG (9.18 KiB) Viewed 5018 times
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby IT2Be » Wed Oct 20, 2004 3:29 pm

Why don't you do this:

the key '7office.dlg.welcomemsg' looks like:
Code: Select all
<html>Welcome <b><font color="red">{0}</font></b><br> of <b><font color="red">{1}</font></b> ID {2}</html>


the method looks like:
Code: Select all
var msg = i18n.getI18NMessage('7office.dlg.welcomemsg', new Array(user_name, gusercomid$to_com.company_name, globals.gservoy_id));
plugins.dialogs.showInfoDialog(title, msg);
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby bcusick » Wed Oct 20, 2004 4:23 pm

Marcel - excellent!

I totally forgot about replacing the placeholders with array values!

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby Morley » Wed Oct 20, 2004 4:47 pm

Brilliant! Here's the proof. Thanks Marcel
Attachments
msg4.PNG
msg4.PNG (7.56 KiB) Viewed 4997 times
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby IT2Be » Wed Oct 20, 2004 4:48 pm

So, you won't ever doubt servoy from now till death do you part :lol:
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 27 guests

cron