For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2007 > msgcat support in bwidget









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author msgcat support in bwidget
relaxmike

2007-10-25, 7:19 pm

Hello,
I have been using the bwidget package since several years.
It is excellent but does not provide support for multi-lingual
softwares.
In fact, it is not a huge work to insert msgcat commands in the
bwidget
package. In the begining, i tuned a special version of bwidget for my
personal needs,
but this leads to code duplication. Now, the additionnal commands
are separated from the bwidget core, but I am still not satisfied.
Other Tcl developers had the same idea :
http://groups.google.com/group/comp...read/753a8d556=
6dc6654/428e157e4311c2bd?lnk=3Dgst&q=3Dbwidget+msgcat#428e157e4311c2bd
Has anybody experience with inserting msgcat support into bwidget ?
Micha=EBl

PS
For example, in the mainframe widget, it is easy to overload the
_parse_name
command so that messages get automatically translated :

rename MainFrame::_parse_name MainFrame::__parse_name
proc MainFrame::_parse_name { menuname } {
set translatedName [::msgcat::mc $menuname]
set parsedName [MainFrame::__parse_name $translatedName]
return $parsedName
}

Since version 1.3 of msgcat, the msgcat facility provides support to
distinguish between
different namespaces. We can change the overloading to :

rename MainFrame::_parse_name MainFrame::__parse_name
proc MainFrame::_parse_name { menuname } {
set translatedName [mynamespace::translate $menuname]
set parsedName [MainFrame::__parse_name $translatedName]
return $parsedName
}
proc mynamespace::translate { original } {
set translated [::msgcat::mc $original]
return $translated
}

I think that there would a possibility that the BWidget package
could take an external translation command as an argument, like this :

BWidget::setTranslationCommand procname

and use it everywhere it is necessary (with, by default, no
translation when the command
is not defined). Modifications would be applied in the mainframe, but
also in the button,
passwddlg, etc...

ZB

2007-10-25, 7:19 pm

Dnia 25.10.2007 relaxmike <michael.baudin@gmail.com> napisał/a:

> Has anybody experience with inserting msgcat support into bwidget ?


And does it really need some special kind of "inserting"? :-O

I'm using just sequences like: "[::msgcat::mc menuItemFile]" - and it just
works...
--
ZB
relaxmike

2007-10-25, 7:19 pm

You are right !
But with N entries in one application, you must insert N
"[::msgcat::mc menuItemFile]".
This is not feasible for N > 10.

On 25 oct, 23:02, ZB <zbREMOVE_THIS@AND_THISispid.com.pl> wrote:
> Dnia 25.10.2007 relaxmike <michael.bau...@gmail.com> napisa=B3/a:
>
>
> And does it really need some special kind of "inserting"? :-O
>
> I'm using just sequences like: "[::msgcat::mc menuItemFile]" - and it just
> works...
> --
> ZB



ZB

2007-10-25, 7:19 pm

Dnia 25.10.2007 relaxmike <michael.baudin@gmail.com> napisał/a:
> You are right !
> But with N entries in one application, you must insert N
> "[::msgcat::mc menuItemFile]".
> This is not feasible for N > 10.


Currently I'm making it such way. If there does exists a better one - it
could be interesting.
--
ZB
Larry W. Virden

2007-10-26, 8:10 am

On Oct 25, 2:44 pm, relaxmike <michael.bau...@gmail.com> wrote:
> package. In the begining, i tuned a special version of bwidget for my
> personal needs,
> but this leads to code duplication.


I would think that you could just submit changes to the bwidget code
at sf.net web site and let the developers add your changes into
bwidget. That way, there isn't any additional work.

relaxmike

2007-10-27, 8:10 am

In fact, the whole process of internationalizing an application would
be :
- take a Tcl software with no msgcat use at all,
- overload Tk and BWidgets so that it uses your particular translation
command,
- configure msgcat with the proper msg directory,
- create the <yourlanguage>.msg script,
- the software is automatically translated.

For example, one can overload the Tk message box with :

if {[info commands "::tk_messageBox"]=="::tk_messageBox"} then {
rename ::tk_messageBox ::_tk_messageBox
proc ::tk_messageBox {args} {
set command [list "::_tk_messageBox"]
foreach {key value} $args {
if {$key=="-title" || $key=="-message"} then {
set value [mynamespace::translate $value]
}
lappend command $key $value
}
set answer [eval $command]
return $answer
}
}

In fact, this should be included in a overloading package :
package require internat
internat::overload "TkMessageBox" "mynamespace::translate"
internat::overload "TkLabel" "mynamespace::translate"
internat::overload "TkLabelFrame" "mynamespace::translate"
internat::overload "BwidgetMainFrame" "mynamespace::translate"
etc...

relaxmike

2007-11-23, 4:31 am

Hi,
I invite interested people to discuss with more details this subject
on the wiki :
http://wiki.tcl.tk/20290
where I describe one attempt at translating a Tcl script with no
modification of the source.
Regards,
Micha=EBl
Arjen Markus

2007-11-23, 8:11 am

On 23 nov, 10:12, relaxmike <michael.bau...@gmail.com> wrote:
> Hi,
> I invite interested people to discuss with more details this subject
> on the wiki :http://wiki.tcl.tk/20290
> where I describe one attempt at translating a Tcl script with no
> modification of the source.
> Regards,
> Micha=EBl


frink may be helpful here: http://wiki.tcl.tk/2611

It can extract literal text from the source code.

Regards,

Arjen
suchenwi

2007-11-23, 8:11 am

On 25 Okt., 22:40, relaxmike <michael.bau...@gmail.com> wrote:
> You are right !
> But with N entries in one application, you must insert N
> "[::msgcat::mc menuItemFile]".
> This is not feasible for N > 10.


umm.. you can simplify the calls with
namespace import msgcat::mc
and
[mc File]
is just 3 bytes longer than "File"...
relaxmike

2007-11-23, 7:13 pm

> is just 3 bytes longer than "File"...
My problem is not the number of bytes, but the number of files in
which the modifications has to be made.

In fact, what I would like to have is a way that all Tk widgets
created
using "tk_chooseDirectory", for example, use a particular translation
command :
tk_chooseDirectory set -translationcmd "mycommand"
In an object-oriented language, this would lead to a modification of a
static field
of the class behind each "tk_chooseDirectory" object.
This is not possible with current Tk widgets, since no translation
commands can be
set to the class underlying the tk_chooseDirectory widget. One can
only set the option
database for background colors etc...
Is this why msgcat is not included in the Tcl core, but only available
as a Tcl package ?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com