Sprache zur laufzeit ändern [gelöst]

Alles rund um die Programmierung mit Qt
Antworten
archer
Beiträge: 306
Registriert: 2. Februar 2006 09:56

Sprache zur laufzeit ändern [gelöst]

Beitrag von archer »

Hallo,

kennt sich jemand mit dem QTranslator aus?

Ich möchte die Sprache meines Programms ändern.
Dieses möchte ich jedoch tun ohne das Programm zu beenden und neu zu starten.
Wie bringe ich die Oberfläche (meine ui-files) dazu eine andere Sprachdatei zu laden?


mfg archer
Zuletzt geändert von archer am 4. Februar 2008 11:22, insgesamt 1-mal geändert.
macman
Beiträge: 1738
Registriert: 15. Juni 2005 13:33
Wohnort: Gütersloh
Kontaktdaten:

Beitrag von macman »

Hatten wir erst kürzlich hier, such im Forum.
patrik08
Beiträge: 746
Registriert: 27. Februar 2006 10:48
Wohnort: DE Freiburg

Beitrag von patrik08 »

im offizielle qt3 ist ein beisbiel!

oder mit subversion

svn co http://ciz.ch/svnciz/dialog_qt/qt4_a/qt ... _i18n_QT3/
ordnerx

die linguistig file werden hineincompliliert...

oder appTranslator.load(find,transdir); ///// file , path resourcefile //////
reset doku und neues file laden...

Code: Alles auswählen

  #if defined( Q_WS_X11 )
    QString transdir=PREFIX"/share/qt4ds_x11/locale/";
    #endif
    #if defined( Q_WS_MACX )
    QString transdir="/Applications/qt4ds_mac.app/Contents/Resources/locale/";
    #endif
    #if defined(Q_WS_WIN)
    QString transdir=QCoreApplication::applicationDirPath()+"/locale/";
    #endif
    
    /* other way install all locale to QString workdir = QString( "%1/.%2/" ).arg( QDir::homePath(), QUIKCONFIG ); */
    /* best way build relase to put inside / CONFIG		+= qt warn_on release  */
    
    QString find = "qt4ds_" + QLocale::system().name().left(QLocale::system().name().indexOf("_"))+".qm";
    QString fullpath = transdir + find;
    QFileInfo fi( fullpath );

    if ( !fi.exists() ) {
	QMessageBox::warning( 0, "File error",
			      QString(" Cannot find translation file "+find+" for locale language: "+QLocale::system().name().left(QLocale::system().name().indexOf("_"))+
				      "\n Fullpath file is : "+fullpath+"\n insert file \""+find+"\" on subdir \""+transdir+"\" and all running ok!" ));  //////
	return 0;
    }
    
    
    /* debug_debug  section  */
    //// discovery what file to load ! ////////
    ///////file_put_contents("nameformat_name.dat",find);
    //// discovery what file to load ! ////////

    appTranslator.load(find,transdir);   ///// file , path resourcefile //////
    app.installTranslator(&appTranslator);

archer
Beiträge: 306
Registriert: 2. Februar 2006 09:56

Beitrag von archer »

Wenn ich das Baispiel richtig verstehe, wird der Translator gelöscht un neu angelegt.
Das habe ich auch getan.
Aber mein Problem ist folgendes:
- ich habe mein MainForm.
- nun erzeuge ich zu Laufzeit andere Widgets (Formulare) mit new.
- In diesen willich nun die Sprache ändern, ohne diese zu löschen und neu
zu erzeugen.

So wie ich das sehe werde ich mir wohl meine eigene Methode schreiben müssen, die die Texte "per Hand" setzt. Ähnlich dem changeLanguage() event.
Ich haate gehofft, ich kann einen neuen Translator laden und der gui sagen - alle texte neu einlesen.
pasnox
Beiträge: 7
Registriert: 28. März 2006 14:09

Beitrag von pasnox »

Hi,

Please don't distribute modified source of qt4ds monkey with the name of mine, because your qt4ds-monkey modified source is not the original, please considere rennaming it to what you want, or ask me to join the project on sourceforge if you want to add your modification.

P@sNox
patrik08
Beiträge: 746
Registriert: 27. Februar 2006 10:48
Wohnort: DE Freiburg

Beitrag von patrik08 »

this code is only sample ... to learn qt
your original code reside on http://sourceforge.net/projects/qt4ds-monkey
pasnox
Beiträge: 7
Registriert: 28. März 2006 14:09

Beitrag von pasnox »

Hi,

Ok for the lessons :p
I see your have post some unreadable french note on my french forum.
U can repost it in the uk forum please ?

UK Forum: http://sourceforge.net/forum/?group_id=163493

Nox,
Antworten