Qtのドキュメントからの引用は次のとおりです。
翻訳ファイルやアイコンなど、一部のリソースはユーザーのロケールに基づいて変更する必要があります。これは、適切なロケール文字列を指定して、qresource タグに lang 属性を追加することによって行われます。例えば:
<qresource> <file>cut.jpg</file> </qresource> <qresource lang="fr"> <file alias="cut.jpg">cut_fr.jpg</file> </qresource>
ユーザーのロケールがフランス語の場合 (つまり、QLocale::system().name() が「fr_FR」を返す)、:/cut.jpg は cut_fr.jpg 画像への参照になります。その他のロケールでは、cut.jpg が使用されます。
私はこれをやろうとして失敗します。これは私の *.qrc ファイルの一部です:
<qresource>
<file>HtmlTemplates/angle.html</file>
<file>HtmlTemplates/bottom.html</file>
<file>HtmlTemplates/top.html</file>
</qresource>
<qresource lang="en">
<file alias="HtmlTemplates/angle.html">HtmlTemplates/en/angle.html</file>
<file alias="HtmlTemplates/bottom.html">HtmlTemplates/en/bottom.html</file>
<file alias="HtmlTemplates/top.html">HtmlTemplates/en/top.html</file>
</qresource>
ご覧のとおり、マニュアルの例とまったく同じパターンに従います。ただし、このファイルをコンパイルしようとすると、次のようになります。
..\Blinky_2.0\resources.qrc: Warning: potential duplicate alias detected: 'angle.html'
..\Blinky_2.0\resources.qrc: Warning: potential duplicate alias detected: 'bottom.html'
..\Blinky_2.0\resources.qrc: Warning: potential duplicate alias detected: 'top.html'
また、QtCreator で *.qrc ファイルを変更しようとすると、lang
属性が削除されて間違った状態にリセットされます。
<qresource prefix="/">
<file>HtmlTemplates/angle.html</file>
<file>HtmlTemplates/bottom.html</file>
<file>HtmlTemplates/top.html</file>
<file alias="HtmlTemplates/angle.html">HtmlTemplates/en/angle.html</file>
<file alias="HtmlTemplates/bottom.html">HtmlTemplates/en/bottom.html</file>
<file alias="HtmlTemplates/top.html">HtmlTemplates/en/top.html</file>
</qresource>
そのため、コード内のさまざまなロケールのリソースを反復処理する必要があります。何か足りないのですか、それとも Qt のバグですか? Qt のバージョンは 4.8.4、QtCreator のバージョンは 2.8.1 です。