Qt 에서 멀티언어 설정을 하고 있습니다.

pofp77의 이미지

안녕하세요.. ^^"

Qt 멀티언어 설정 중 도대체가 안되는 부문이 있어서 문의 드립니다.

코드는 간단한 예제프로그램을 참조하여 만들었습니다.

Title메뉴(Language)가 있고 Language를 누르면 1 German, 2 English, 3 Korean 의 Action메뉴가 나타납니다.
그 중에 언어를 선택하면 Title 부분의 Language 글자를 각각의 언어에 맞게 변경하려고 하는데요.
선택 시 setTitle(tr("&Language"));를 해도 변경이 되질 않습니다.

.qm 코드는 각 언어에 맞게 3개를 만들었습니다.

혹시 적극적으로 도와주실분이 계실지 몰라서 전체코드 첨부합니다..^^;;

코드는 아래와 같습니다..

#include
#include
#include
#include
#include "mainwindow.h"

MainWindow::MainWindow()
{
createMenus();
retranslateUi();
}

void MainWindow::createMenus()
{
languageMenu = new QMenu(this);

languageActionGroup = new QActionGroup(this);
connect(languageActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(switchLanguage(QAction *)));

QDir qmDir = directoryOf(".");
QStringList fileNames = qmDir.entryList(QStringList("multilang_*.qm"));

for(int i=0;i {
QString locale = fileNames[i];
locale.remove(0, locale.indexOf('_') + 1);
locale.chop(3);

QTranslator translator;
translator.load(fileNames[i], qmDir.absolutePath());
QString language = translator.translate("MainWindow", "English");

QAction *action = new QAction(tr("&%1 %2")
.arg(i+1).arg(language), this);
action->setCheckable(true);
action->setData(locale);

languageMenu->addAction(action);
languageActionGroup->addAction(action);

if(language == "English")
action->setCheckable(true);
}
menuBar()->addMenu(languageMenu);
}

void MainWindow::retranslateUi()
{
languageMenu->setTitle(tr("&Language"));
}

void MainWindow::switchLanguage(QAction *action)
{
QString locale = action->data().toString();
QString qmPath = directoryOf(".").absolutePath();

appTranslator->load("multilang_"+locale, qmPath);
qtTranslator->load("qt_"+locale, qmPath);
}

void MainWindow::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LocaleChange)
{
QString qmPath = directoryOf(".").absolutePath();
appTranslator->load("multilang_"+QLocale::system().name(), qmPath);
qtTranslator->load("qt_"+QLocale::system().name(), qmPath);
retranslateUi();
}
QMainWindow::changeEvent(event);
}

QDir MainWindow::directoryOf(const QString &subdir)
{
QDir dir(QApplication::applicationDirPath());
dir.cd(subdir);
return dir;
}

File attachments: 
첨부파일 크기
Binary Data multilang.tar.gz26.11 KB
towstock의 이미지

Qt 사이트에서 발췌했습니다. 혹시 참고가 될지??

Dynamic Translation

Some applications, such as Qt Linguist, must be able to support changes to the user's language settings while they are still running. To make widgets aware of changes to the installed QTranslators, reimplement the widget's changeEvent() function to check whether the event is a LanguageChange event, and update the text displayed by widgets using the tr() function in the usual way. For example:

void QWidget::changeEvent(QEvent *event)
{
if (e->type() == QEvent::LanguageChange) {
titleLabel->setText(tr("Document Title"));
...
okPushButton->setText(tr("&OK"));
} else
QWidget::changeEvent(event);
}
All other change events should be passed on by calling the default implementation of the function.

The list of installed translators might change in reaction to a LocaleChange event, or the application might provide a user interface that allows the user to change the current application language.

The default event handler for QWidget subclasses responds to the QEvent::LanguageChange event, and will call this function when necessary; other application components can also force widgets to update themselves by posting the LanguageChange event to them.

원문은 아래 링크에서 확인하실 수 있습니다.

http://doc.qt.nokia.com/4.5/i18n.html#dynamic-translation

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.