You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
342 lines
15 KiB
342 lines
15 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/i18n/i18n.doc:4 -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Internationalization</title>
|
|
<style type="text/css"><!--
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
a:link { color: #004faf; text-decoration: none }
|
|
a:visited { color: #672967; text-decoration: none }
|
|
body { background: #ffffff; color: black; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr bgcolor="#E5E5E5">
|
|
<td valign=center>
|
|
<a href="index.html">
|
|
<font color="#004faf">Home</font></a>
|
|
| <a href="classes.html">
|
|
<font color="#004faf">All Classes</font></a>
|
|
| <a href="mainclasses.html">
|
|
<font color="#004faf">Main Classes</font></a>
|
|
| <a href="annotated.html">
|
|
<font color="#004faf">Annotated</font></a>
|
|
| <a href="groups.html">
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
| <a href="functions.html">
|
|
<font color="#004faf">Functions</font></a>
|
|
</td>
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Internationalization</h1>
|
|
|
|
|
|
<p>
|
|
This example shows how to internationalize applications. Start it with
|
|
<pre># i18n de</pre><p> to get a german version and with
|
|
<pre># i18n en</pre><p> to get the english version.
|
|
<p> Refer also to <a href="i18n.html">the internationalization documentation</a>.
|
|
<p> <hr>
|
|
<p> Header file:
|
|
<p> <pre>/****************************************************************************
|
|
** $Id: qt/mywidget.h 3.3.8 edited Jan 11 14:37 $
|
|
**
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of an example program for TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#ifndef MYWIDGET_H
|
|
#define MYWIDGET_H
|
|
|
|
#include <<a href="tqmainwindow-h.html">tqmainwindow.h</a>>
|
|
#include <<a href="tqstring-h.html">tqstring.h</a>>
|
|
|
|
class MyWidget : public <a href="tqmainwindow.html">TQMainWindow</a>
|
|
{
|
|
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
|
|
|
|
public:
|
|
MyWidget( <a href="tqwidget.html">TQWidget</a>* parent=0, const char* name = 0 );
|
|
|
|
signals:
|
|
void closed();
|
|
|
|
protected:
|
|
void closeEvent(TQCloseEvent*);
|
|
|
|
private:
|
|
static void initChoices(TQWidget* parent);
|
|
};
|
|
|
|
#endif
|
|
</pre>
|
|
|
|
<p> <hr>
|
|
<p> Implementation:
|
|
<p> <pre>/****************************************************************************
|
|
** $Id: qt/mywidget.cpp 3.3.8 edited Jan 11 14:37 $
|
|
**
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of an example program for TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#include <<a href="tqbuttongroup-h.html">tqbuttongroup.h</a>>
|
|
#include <<a href="tqradiobutton-h.html">tqradiobutton.h</a>>
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
#include <<a href="tqlistbox-h.html">tqlistbox.h</a>>
|
|
#include <<a href="tqcombobox-h.html">tqcombobox.h</a>>
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
#include <<a href="qhbox-h.html">ntqhbox.h</a>>
|
|
#include <<a href="qvbox-h.html">ntqvbox.h</a>>
|
|
#include <<a href="qaccel-h.html">ntqaccel.h</a>>
|
|
#include <<a href="tqpopupmenu-h.html">tqpopupmenu.h</a>>
|
|
#include <<a href="tqmenubar-h.html">tqmenubar.h</a>>
|
|
#include <<a href="tqstatusbar-h.html">tqstatusbar.h</a>>
|
|
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
|
|
|
|
#include "mywidget.h"
|
|
|
|
<a name="f525"></a>MyWidget::MyWidget( <a href="tqwidget.html">TQWidget</a>* parent, const char* name )
|
|
: <a href="tqmainwindow.html">TQMainWindow</a>( parent, name )
|
|
{
|
|
<a href="ntqvbox.html">TQVBox</a>* central = new <a href="ntqvbox.html">TQVBox</a>(this);
|
|
<a name="x1923"></a> central-><a href="tqframe.html#setMargin">setMargin</a>( 5 );
|
|
<a name="x1924"></a> central-><a href="ntqhbox.html#setSpacing">setSpacing</a>( 5 );
|
|
<a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>(central);
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* file = new <a href="tqpopupmenu.html">TQPopupMenu</a>(this);
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( <a href="tqobject.html#tr">tr</a>("E&xit"), tqApp, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()),
|
|
<a name="x1921"></a> TQAccel::<a href="ntqaccel.html#stringToKey">stringToKey</a>(<a href="tqobject.html#tr">tr</a>("Ctrl+Q")) );
|
|
<a href="tqmainwindow.html#menuBar">menuBar</a>()->insertItem( <a href="tqobject.html#tr">tr</a>("&File"), file );
|
|
|
|
<a href="tqwidget.html#setCaption">setCaption</a>( <a href="tqobject.html#tr">tr</a>( "Internationalization Example" ) );
|
|
|
|
<a href="tqstring.html">TQString</a> l;
|
|
<a href="tqmainwindow.html#statusBar">statusBar</a>()->message( <a href="tqobject.html#tr">tr</a>("Language: English") );
|
|
|
|
( void )new <a href="tqlabel.html">TQLabel</a>( <a href="tqobject.html#tr">tr</a>( "The Main Window" ), central );
|
|
|
|
<a href="tqbuttongroup.html">TQButtonGroup</a>* gbox = new <a href="tqbuttongroup.html">TQButtonGroup</a>( 1, TQGroupBox::Horizontal,
|
|
<a href="tqobject.html#tr">tr</a>( "View" ), central );
|
|
(void)new <a href="tqradiobutton.html">TQRadioButton</a>( <a href="tqobject.html#tr">tr</a>( "Perspective" ), gbox );
|
|
(void)new <a href="tqradiobutton.html">TQRadioButton</a>( <a href="tqobject.html#tr">tr</a>( "Isometric" ), gbox );
|
|
(void)new <a href="tqradiobutton.html">TQRadioButton</a>( <a href="tqobject.html#tr">tr</a>( "Oblique" ), gbox );
|
|
|
|
initChoices(central);
|
|
}
|
|
|
|
static const char* choices[] = {
|
|
TQT_TRANSLATE_NOOP( "MyWidget", "First" ),
|
|
TQT_TRANSLATE_NOOP( "MyWidget", "Second" ),
|
|
TQT_TRANSLATE_NOOP( "MyWidget", "Third" ),
|
|
0
|
|
};
|
|
|
|
void <a name="f526"></a>MyWidget::initChoices(TQWidget* parent)
|
|
{
|
|
<a href="tqlistbox.html">TQListBox</a>* lb = new <a href="tqlistbox.html">TQListBox</a>( parent );
|
|
for ( int i = 0; choices[i]; i++ )
|
|
<a name="x1925"></a> lb-><a href="tqlistbox.html#insertItem">insertItem</a>( <a href="tqobject.html#tr">tr</a>( choices[i] ) );
|
|
}
|
|
|
|
<a name="x1927"></a>void MyWidget::<a href="tqwidget.html#closeEvent">closeEvent</a>(TQCloseEvent* e)
|
|
{
|
|
TQWidget::<a href="tqwidget.html#closeEvent">closeEvent</a>(e);
|
|
emit closed();
|
|
}
|
|
</pre>
|
|
|
|
<p> <hr>
|
|
<p> Main:
|
|
<p> <pre>/****************************************************************************
|
|
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
|
|
**
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of an example program for TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
|
|
#include <<a href="tqtranslator-h.html">tqtranslator.h</a>>
|
|
#include <<a href="tqfileinfo-h.html">tqfileinfo.h</a>>
|
|
#include <<a href="qmessagebox-h.html">ntqmessagebox.h</a>>
|
|
#include <<a href="tqcheckbox-h.html">tqcheckbox.h</a>>
|
|
#include <<a href="qvbox-h.html">ntqvbox.h</a>>
|
|
#include <<a href="qlayout-h.html">ntqlayout.h</a>>
|
|
#include <<a href="tqbuttongroup-h.html">tqbuttongroup.h</a>>
|
|
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
|
|
#include <<a href="tqsignalmapper-h.html">tqsignalmapper.h</a>>
|
|
#include <<a href="tqtextcodec-h.html">tqtextcodec.h</a>>
|
|
#include <stdlib.h>
|
|
|
|
#if defined(Q_OS_UNIX)
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include "mywidget.h"
|
|
|
|
//#define USE_I18N_FONT
|
|
|
|
class TQVDialog : public <a href="tqdialog.html">TQDialog</a> {
|
|
public:
|
|
TQVDialog(TQWidget *parent=0, const char *name=0, bool modal=FALSE,
|
|
WFlags f=0) : <a href="tqdialog.html">TQDialog</a>(parent,name,modal,f)
|
|
{
|
|
<a href="qvboxlayout.html">TQVBoxLayout</a>* vb = new <a href="qvboxlayout.html">TQVBoxLayout</a>(this,8);
|
|
<a name="x1938"></a> vb-><a href="ntqlayout.html#setAutoAdd">setAutoAdd</a>(TRUE);
|
|
hb = 0;
|
|
sm = new <a href="tqsignalmapper.html">TQSignalMapper</a>(this);
|
|
<a name="x1946"></a> connect(sm,TQ_SIGNAL(<a href="tqsignalmapper.html#mapped">mapped</a>(int)),this,TQ_SLOT(done(int)));
|
|
}
|
|
void addButtons( const <a href="tqstring.html">TQString</a>& cancel=TQString::null,
|
|
const <a href="tqstring.html">TQString</a>& ok=TQString::null,
|
|
const <a href="tqstring.html">TQString</a>& mid1=TQString::null,
|
|
const <a href="tqstring.html">TQString</a>& mid2=TQString::null,
|
|
const <a href="tqstring.html">TQString</a>& mid3=TQString::null)
|
|
{
|
|
<a name="x1948"></a> addButton(ok.<a href="tqstring.html#isNull">isNull</a>() ? TQObject::tr("OK") : ok, 1);
|
|
if ( !mid1.<a href="tqstring.html#isNull">isNull</a>() ) addButton(mid1,2);
|
|
if ( !mid2.<a href="tqstring.html#isNull">isNull</a>() ) addButton(mid2,3);
|
|
if ( !mid3.<a href="tqstring.html#isNull">isNull</a>() ) addButton(mid3,4);
|
|
addButton(cancel.<a href="tqstring.html#isNull">isNull</a>() ? TQObject::tr("Cancel") : cancel, 0);
|
|
}
|
|
|
|
void addButton( const <a href="tqstring.html">TQString</a>& text, int result )
|
|
{
|
|
if ( !hb )
|
|
hb = new <a href="ntqhbox.html">TQHBox</a>(this);
|
|
<a href="tqpushbutton.html">TQPushButton</a> *c = new <a href="tqpushbutton.html">TQPushButton</a>(text, hb);
|
|
<a name="x1947"></a> sm-><a href="tqsignalmapper.html#setMapping">setMapping</a>(c,result);
|
|
<a name="x1945"></a> connect(c,TQ_SIGNAL(<a href="tqbutton.html#clicked">clicked</a>()),sm,TQ_SLOT(<a href="tqsignalmapper.html#map">map</a>()));
|
|
}
|
|
|
|
private:
|
|
<a href="tqsignalmapper.html">TQSignalMapper</a> *sm;
|
|
<a href="ntqhbox.html">TQHBox</a> *hb;
|
|
};
|
|
|
|
MyWidget* showLang(TQString lang)
|
|
{
|
|
|
|
static TQTranslator *translator = 0;
|
|
|
|
<a name="x1934"></a> tqApp-><a href="ntqapplication.html#setPalette">setPalette</a>(TQPalette(TQColor(220-rand()%64,220-rand()%64,220-rand()%64)));
|
|
|
|
lang = "mywidget_" + lang + ".qm";
|
|
<a href="tqfileinfo.html">TQFileInfo</a> fi( lang );
|
|
|
|
<a name="x1937"></a> if ( !fi.<a href="tqfileinfo.html#exists">exists</a>() ) {
|
|
<a name="x1940"></a> TQMessageBox::<a href="ntqmessagebox.html#warning">warning</a>( 0, "File error",
|
|
TQString("Cannot find translation for language: "+lang+
|
|
"\n(try eg. 'de', 'ko' or 'no')") );
|
|
return 0;
|
|
}
|
|
if ( translator ) {
|
|
<a name="x1932"></a> tqApp-><a href="ntqapplication.html#removeTranslator">removeTranslator</a>( translator );
|
|
delete translator;
|
|
}
|
|
translator = new <a href="tqtranslator.html">TQTranslator</a>( 0 );
|
|
<a name="x1950"></a> translator-><a href="tqtranslator.html#load">load</a>( lang, "." );
|
|
<a name="x1930"></a> tqApp-><a href="ntqapplication.html#installTranslator">installTranslator</a>( translator );
|
|
MyWidget *m = new MyWidget;
|
|
<a name="x1951"></a> m-><a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - <a href="i18n.html#i18n">i18n</a> - " + m-><a href="tqwidget.html#caption">caption</a>() );
|
|
return m;
|
|
}
|
|
|
|
int main( int argc, char** argv )
|
|
{
|
|
<a href="ntqapplication.html">TQApplication</a> app( argc, argv );
|
|
|
|
const char* qm[]=
|
|
{ "ar", "cs", "de", "el", "en", "eo", "fr", "it", "jp", "ko", "no", "ru", "zh", 0 };
|
|
|
|
#if defined(Q_OS_UNIX)
|
|
srand( getpid() << 2 );
|
|
#endif
|
|
|
|
<a href="tqstring.html">TQString</a> lang;
|
|
if ( argc == 2 )
|
|
lang = argv[1];
|
|
|
|
if ( argc != 2 || lang == "all" ) {
|
|
TQVDialog dlg(0,0,TRUE);
|
|
TQCheckBox* qmb[sizeof(qm)/sizeof(qm[0])];
|
|
int r;
|
|
if ( lang == "all" ) {
|
|
r = 2;
|
|
} else {
|
|
<a href="tqbuttongroup.html">TQButtonGroup</a> *bg = new <a href="tqbuttongroup.html">TQButtonGroup</a>(4,TQt::Vertical,"Choose Locales",&dlg);
|
|
<a name="x1949"></a> <a href="tqstring.html">TQString</a> loc = TQTextCodec::<a href="tqtextcodec.html#locale">locale</a>();
|
|
for ( int i=0; qm[i]; i++ ) {
|
|
qmb[i] = new <a href="tqcheckbox.html">TQCheckBox</a>((const char*)qm[i],bg);
|
|
qmb[i]->setChecked( loc == qm[i] );
|
|
}
|
|
dlg.addButtons("Cancel","OK","All");
|
|
<a name="x1936"></a> r = dlg.<a href="tqdialog.html#exec">exec</a>();
|
|
}
|
|
if ( r ) {
|
|
<a name="x1928"></a> <a href="tqrect.html">TQRect</a> screen = tqApp-><a href="ntqapplication.html#desktop">desktop</a>()->availableGeometry();
|
|
bool tight = screen.<a href="tqrect.html#width">width</a>() < 1024;
|
|
<a name="x1942"></a> int x=screen.<a href="tqrect.html#left">left</a>()+5;
|
|
int y=screen.<a href="tqrect.html#top">top</a>()+25;
|
|
for ( int i=0; qm[i]; i++ ) {
|
|
if ( r == 2 || qmb[i]->isChecked() ) {
|
|
MyWidget* w = showLang((const char*)qm[i]);
|
|
|
|
if( w == 0 ) exit( 0 );
|
|
TQObject::<a href="tqobject.html#connect">connect</a>(w, TQ_SIGNAL(closed()), tqApp, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()));
|
|
<a name="x1953"></a> w-><a href="tqwidget.html#setGeometry">setGeometry</a>(x,y,197,356);
|
|
w-><a href="tqwidget.html#show">show</a>();
|
|
if ( tight ) {
|
|
x += 8;
|
|
y += 8;
|
|
} else {
|
|
x += 205;
|
|
if ( x > 1000 ) {
|
|
x = 5;
|
|
y += 384;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
exit( 0 );
|
|
}
|
|
} else {
|
|
<a href="tqstring.html">TQString</a> lang = argv[1];
|
|
<a href="tqwidget.html">TQWidget</a>* m = showLang(lang);
|
|
app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( m );
|
|
m-><a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - i18n");
|
|
m-><a href="tqwidget.html#show">show</a>();
|
|
}
|
|
|
|
#ifdef USE_I18N_FONT
|
|
memorymanager->savePrerenderedFont(font.handle(),FALSE);
|
|
#endif
|
|
|
|
// While we run "all", kill them all
|
|
return app.<a href="ntqapplication.html#exec">exec</a>();
|
|
|
|
}
|
|
</pre>
|
|
|
|
<p>See also <a href="examples.html">Examples</a>.
|
|
|
|
<!-- eof -->
|
|
<p><address><hr><div align=center>
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
<td>Copyright © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|