<QtTranslation>
翻訳対象の文字列をマークする。詳細...
| Header: | #include <QtTranslation> |
関数
| QString | qtTrId(const char *id, int n = -1) |
マクロ
| QT_TRANSLATE_NOOP3(context, sourceText, disambiguation) | |
| QT_TRANSLATE_NOOP(context, sourceText) | |
| QT_TRANSLATE_N_NOOP3(context, sourceText, comment) | |
| QT_TRANSLATE_N_NOOP(context, sourceText) | |
| QT_TRID_NOOP(id) | |
(since 6.3) | QT_TRID_N_NOOP(id) |
| QT_TR_NOOP(sourceText) | |
| QT_TR_N_NOOP(sourceText) |
「翻訳用のソースコードの記述」も参照してください 。
関数のドキュメント
QString qtTrId(const char *id, int n = -1)
qtTrId 関数は、翻訳済みの文字列を検索して返します。
id で指定された翻訳済み文字列を返します。一致する文字列が見つからない場合は、その ID 自体が返されます。通常の状況では、このようなことは起こらないはずです。
n >= 0 の場合、結果の文字列内のすべての「%n 」が、「n 」の10進表記に置き換えられます。さらに、n の値に応じて、翻訳テキストが異なる場合があります。
メタデータやコメントは、QObject::tr() のドキュメントに記載されている通り渡すことができます。さらに、次のようなソース文字列テンプレートを指定することも可能です:
//% <C string>
または
\begincomment% <C string> \endcomment
例:
//% "%n fooish bar(s) found.\n"
//% "Do you want to continue?"
QString text = qtTrId("qtn_foo_bar", n);この関数で使用可能な QM ファイルを作成するには、lrelease ツールに-idbased オプションを指定する必要があります。
警告: このメソッドは 、呼び出し前にすべての翻訳ツールがインストールされている場合にのみ再入可能です。翻訳処理中に翻訳ツールのインストールや削除を行うことはサポートされていません。そうすると、クラッシュやその他の予期しない動作を引き起こす可能性があります。
注:この関数は再入可能です。
関連項目: QObject::tr()、QCoreApplication::translate()、および「Qt による国際化」。
マクロのドキュメント
QT_TRANSLATE_NOOP3(context, sourceText, disambiguation)
UTF-8エンコードされた文字列リテラル `sourceText ` を、指定された `context ` および `disambiguation` を用いて遅延変換の対象としてマークします。`context ` は通常クラスであり、文字列リテラルとして指定する必要があります。文字列リテラル `disambiguation ` は、それ以外が同一である文字列を区別するための短いセマンティックタグである必要があります。
このマクロは、lupdate に文字列を収集するよう指示し、sourceText およびdisambiguation として渡された 2 つの文字列リテラルからなる匿名構造体に展開されます。
例:
static struct { const char *source; const char *comment; } greeting_strings[] =
{
QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",
"A really friendly hello"),
QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",
"A really friendly goodbye")
};
QString FriendlyConversation::greeting(int type)
{
return tr(greeting_strings[type].source,
greeting_strings[type].comment);
}
QString global_greeting(int type)
{
return qApp->translate("FriendlyConversation",
greeting_strings[type].source,
greeting_strings[type].comment);
}関連項目: QT_TR_NOOP()、QT_TRANSLATE_NOOP()、および「Qt による国際化」。
QT_TRANSLATE_NOOP(context, sourceText)
UTF-8 エンコードされた文字列リテラル `sourceText ` を、指定された `context` での遅延変換の対象としてマークします。`context ` は通常クラス名であり、これも文字列リテラルとして指定する必要があります。
このマクロは、lupdate に対してその文字列を収集するよう指示し、sourceText 自体に展開されます。
例:
static const char *greeting_strings[] = {
QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
};
QString FriendlyConversation::greeting(int type)
{
return tr(greeting_strings[type]);
}
QString global_greeting(int type)
{
return qApp->translate("FriendlyConversation",
greeting_strings[type]);
}QT_TR_NOOP()、QT_TRANSLATE_NOOP3()、および「Qt による国際化」も参照してください 。
QT_TRANSLATE_N_NOOP3(context, sourceText, comment)
UTF-8 エンコードされた文字列リテラル `sourceText ` を、指定された `context ` および `comment` において、分子依存の遅延変換の対象としてマークします。`context ` は通常クラスであり、文字列リテラルとして指定する必要があります。文字列リテラル `comment ` は、それ以外が同一である文字列を区別するための短いセマンティックタグである必要があります。
このマクロは、lupdate にその文字列を収集するよう指示し、sourceText およびcomment として渡された 2 つの文字列リテラルからなる匿名構造体へと展開されます。
例:
static struct { const char * const source; const char * const comment; } status_strings[] = {
QT_TRANSLATE_N_NOOP3("Message Status", "Hello, you have %n message(s)",
"A login message status"),
QT_TRANSLATE_N_NOOP3("Message status", "You have %n new message(s)",
"A new message query status")
};
QString FriendlyConversation::greeting(int type, int count)
{
return tr(status_strings[type].source,
status_strings[type].comment, count);
}
QString global_greeting(int type, int count)
{
return qApp->translate("Message Status",
status_strings[type].source,
status_strings[type].comment,
count);
}関連項目: QT_TR_NOOP()、QT_TRANSLATE_NOOP()、QT_TRANSLATE_NOOP3()、およびQt による国際化。
QT_TRANSLATE_N_NOOP(context, sourceText)
指定されたcontext において、分子依存の遅延変換を行うため、UTF-8エンコードされた文字列リテラルsourceText をマークします。context は通常クラス名であり、これも文字列リテラルとして指定する必要があります。
このマクロは、lupdate に対してその文字列を収集するよう指示し、sourceText 自体に展開されます。
例:
static const char * const greeting_strings[] = {
QT_TRANSLATE_N_NOOP("Welcome Msg", "Hello, you have %n message(s)"),
QT_TRANSLATE_N_NOOP("Welcome Msg", "Hi, you have %n message(s)")
};
QString global_greeting(int type, int msgcnt)
{
return translate("Welcome Msg", greeting_strings[type], nullptr, msgcnt);
}QT_TRANSLATE_NOOP()、QT_TRANSLATE_N_NOOP3()、および「Qt による国際化」も参照してください 。
QT_TRID_NOOP(id)
QT_TRID_NOOP マクロは、動的変換の対象となる ID を指定します。
このマクロの唯一の目的は、qtTrId() のようなメタデータを関連付けるためのアンカーを提供することです。
このマクロは、id に展開されます。
例:
static const char * const ids[] = {
//% "This is the first text."
QT_TRID_NOOP("qtn_1st_text"),
//% "This is the second text."
QT_TRID_NOOP("qtn_2nd_text"),
0
};
void TheClass::addLabels()
{
for (int i = 0; ids[i]; ++i)
new QLabel(qtTrId(ids[i]), this);
}qtTrId() およびQt による国際化も参照してください 。
[since 6.3] QT_TRID_N_NOOP(id)
QT_TRID_N_NOOP マクロは、分子依存の動的変換を行うための ID を指定します。
このマクロの唯一の目的は、qtTrId() のようなメタデータを紐付けるためのアンカーを提供することです。
このマクロは、id に展開されます。
例:
static const char * const ids[] = {
//% "%n foo(s) found."
QT_TRID_N_NOOP("qtn_foo"),
//% "%n bar(s) found."
QT_TRID_N_NOOP("qtn_bar"),
0
};
QString result(int type, int n)
{
return qtTrId(ids[type], n);
}このマクロは Qt 6.3 で導入されました。
qtTrId() および「Qt による国際化」も参照してください 。
QT_TR_NOOP(sourceText)
現在のコンテキスト(クラス)において、UTF-8 エンコードされた文字列リテラル `sourceText ` を遅延変換の対象としてマークします。
このマクロは、lupdate に対してこの文字列を収集するよう指示し、sourceText 自体に展開されます。
例:
QString FriendlyConversation::greeting(int type)
{
static const char *greeting_strings[] = {
QT_TR_NOOP("Hello"),
QT_TR_NOOP("Goodbye")
};
return tr(greeting_strings[type]);
}マクロ QT_TR_NOOP_UTF8() はこれと同一であり、非推奨となっています。これは他のすべての _UTF8 マクロにも当てはまります。
QT_TRANSLATE_NOOP() およびQt による国際化も参照してください 。
QT_TR_N_NOOP(sourceText)
現在のコンテキスト(クラス)において、分子依存の遅延変換の対象となる UTF-8 エンコードされた文字列リテラル `sourceText ` を指定します。
このマクロは、lupdate に対してこの文字列を収集するよう指示し、sourceText 自体に展開されます。
このマクロは、sourceText に展開されます。
例:
const char * const StatusClass::status_strings[] = {
QT_TR_N_NOOP("There are %n new message(s)"),
QT_TR_N_NOOP("There are %n total message(s)")
};
QString StatusClass::status(int type, int count)
{
return tr(status_strings[type], nullptr, count);
}「 QT_TR_NOOP 」 および「Qt による国際化」も参照してください 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.