PySide Internationalization/ja

From Qt Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

日本語 English

PySideプログラムの国際化

まず、次のようにプロジェクトファイルを作成します。 kalam.pro

SOURCES = main.py
TRANSLATIONS = i18n/en_GB.ts  i18n/eo_EO.ts

TRANSLATIONSでは、これから作成する翻訳したい言語の翻訳ファイルを指定します(この例ではイギリス英語とエスペラント語)。

次のコマンドを実行します。

# Ubuntuの場合、このツールはpyside-toolsパッケージに含まれています
$ pyside-lupdate kalam.pro

これでQt Linguist( Linguistのチュートリアル )で使用する翻訳ファイルが作成されました。 Qt Linguistで.tsファイルを読み込み、各項目をダブルクリックして訳を入力します。翻訳が済んだら「?」アイコンをクリックして完了アイコンに切り替えます。最後に「ファイル」→「リリース」を実行してqmファイルを作成します。Qtのtranslatorはこのqmファイルを使ってアプリケーションの翻訳を行います。

アプリケーションの翻訳対応は次のように簡単に追加できます。

 translator = QtCore.QTranslator()
 translator.load('i18n/eo_EO')
 app = QtGui.QApplication(sys.argv)
 app.installTranslator(translator)

上の例ではエスペラント語の翻訳をロードしています。

QObjectは翻訳された文字列を返す関数trをもっています。先ほど使用したpyside-lupdateコマンドはソースコードをスキャンして、関数trを呼んでいるインスタンスの場所を探しています。 self.tr('sksddsl') QObject.tr('xyz') MyClassX.tr('nanana')