12,964
回編集
257行目: | 257行目: | ||
# TSファイルからQMファイルが生成される。 | # TSファイルからQMファイルが生成される。 | ||
# Qtソフトウェアを実行して、文言が翻訳されているかどうかを確認する。 | # Qtソフトウェアを実行して、文言が翻訳されているかどうかを確認する。 | ||
<br><br> | |||
== TSファイルのフォーマット == | |||
Qt Linguistが使用するTSファイルのフォーマットは、DTDにより記述されている。<br> | |||
DTDの詳細を知りたい場合は、https://www.w3.org/TR/1998/REC-xml-19980210 を確認すること。<br> | |||
<br> | |||
<u>このフォーマットは、今後のQtのリリースで変更される可能性があることに注意する。</u><br> | |||
<br> | |||
<syntaxhighlight lang="dtd"> | |||
<!-- | |||
! | |||
! Some notes to the DTD: | |||
! | |||
! The location element is set as optional since it was introduced first in Qt 4.2. | |||
! The userdata element is set as optional since it was introduced first in Qt 4.4. | |||
! The vanished message type was introduced first in Qt 5.2. | |||
! | |||
--> | |||
<!-- | |||
! Macro used in order to escape byte entities not allowed in an xml document | |||
! for instance, only #x9, #xA and #xD are allowed characters below #x20. | |||
--> | |||
<!ENTITY % evilstring '(#PCDATA | byte)*' > | |||
<!ELEMENT byte EMPTY> | |||
<!-- value contains decimal (e.g. 1000) or hex (e.g. x3e8) unicode encoding of one char --> | |||
<!ATTLIST byte value CDATA #REQUIRED> | |||
<!-- | |||
! This element wildcard is no valid DTD. No better solution available. | |||
! extra elements may appear in TS and message elements. Each element may appear | |||
! only once within each scope. The contents are preserved verbatim; any | |||
! attributes are dropped. Currently recognized extra tags include: | |||
! extra-po-msgid_plural, extra-po-old_msgid_plural | |||
! extra-po-flags (comma-space separated list) | |||
! extra-loc-layout_id | |||
! extra-loc-feature | |||
! extra-loc-blank | |||
--> | |||
<!ELEMENT extra-* %evilstring; > | |||
<!ELEMENT TS (defaultcodec?, extra-**, dependencies?, (context|message)+) > | |||
<!ATTLIST TS | |||
version CDATA #IMPLIED | |||
sourcelanguage CDATA #IMPLIED | |||
language CDATA #IMPLIED> | |||
<!-- The encoding to use in the QM file by default. Default is ISO-8859-1. --> | |||
<!ELEMENT defaultcodec (#PCDATA) > | |||
<!ELEMENT context (name, comment?, (context|message)+) > | |||
<!ATTLIST context | |||
encoding CDATA #IMPLIED> | |||
<!ELEMENT dependencies (dependency+) > | |||
<!ATTLIST dependency | |||
catalog CDATA #IMPLIED> | |||
<!ELEMENT name %evilstring; > | |||
<!-- This is "disambiguation" in the (new) API, or "msgctxt" in gettext speak --> | |||
<!ELEMENT comment %evilstring; > | |||
<!-- Previous content of comment (result of merge) --> | |||
<!ELEMENT oldcomment %evilstring; > | |||
<!-- The real comment (added by developer/designer) --> | |||
<!ELEMENT extracomment %evilstring; > | |||
<!-- Comment added by translator --> | |||
<!ELEMENT translatorcomment %evilstring; > | |||
<!ELEMENT message (location*, source?, oldsource?, comment?, oldcomment?, extracomment?, translatorcomment?, translation?, userdata?, extra-**) > | |||
<!-- | |||
! If utf8 is "true", the defaultcodec is overridden and the message is encoded | |||
! in UTF-8 in the QM file. If it is "both", both source encodings are stored | |||
! in the QM file. | |||
--> | |||
<!ATTLIST message | |||
id CDATA #IMPLIED | |||
utf8 (true|false|both) "false" | |||
numerus (yes|no) "no"> | |||
<!ELEMENT location EMPTY> | |||
<!-- | |||
! If the line is omitted, the location specifies only a file. | |||
! | |||
! location supports relative specifications as well. Line numbers are | |||
! relative (explicitly positive or negative) to the last reference to a | |||
! given filename; each file starts with current line 0. If the filename | |||
! is omitted, the "current" one is used. For the 1st location in a message, | |||
! "current" is the filename used for the 1st location of the previous message. | |||
! For subsequent locations, it is the filename used for the previous location. | |||
! A single TS file has either all absolute or all relative locations. | |||
--> | |||
<!ATTLIST location | |||
filename CDATA #IMPLIED | |||
line CDATA #IMPLIED> | |||
<!ELEMENT source %evilstring;> | |||
<!-- Previous content of source (result of merge) --> | |||
<!ELEMENT oldsource %evilstring;> | |||
<!-- | |||
! The following should really say one evilstring macro or several | |||
! numerusform or lengthvariant elements, but the DTD can't express this. | |||
--> | |||
<!ELEMENT translation (#PCDATA|byte|numerusform|lengthvariant)* > | |||
<!-- | |||
! If no type is set, the message is "finished". | |||
! Length variants must be ordered by falling display length. | |||
! variants may not be yes if the message has numerus yes. | |||
--> | |||
<!ATTLIST translation | |||
type (unfinished|vanished|obsolete) #IMPLIED | |||
variants (yes|no) "no"> | |||
<!-- Deprecated. Use extra-* --> | |||
<!ELEMENT userdata (#PCDATA)* > | |||
<!-- | |||
! The following should really say one evilstring macro or several | |||
! lengthvariant elements, but the DTD can't express this. | |||
! Length variants must be ordered by falling display length. | |||
--> | |||
<!ELEMENT numerusform (#PCDATA|byte|lengthvariant)* > | |||
<!ATTLIST numerusform | |||
variants (yes|no) "no"> | |||
<!ELEMENT lengthvariant %evilstring; > | |||
</syntaxhighlight> | |||
<br><br> | |||
== テキストIDベースの翻訳 == | |||
テキストID翻訳機構は、ローカライゼーションのための産業用強度の高いシステムである。<br> | |||
ソフトウェアの各テキスト(文言)には一意の識別子(テキストID)が割り当てられており、これらの識別子はプレーンテキストの代わりにソースコード内で直接使用される。<br> | |||
このため、ユーザーインターフェースの開発者には少し手間が掛かるが、大量の翻訳済みテキストの管理が非常に容易になる。<br> | |||
<br> | |||
<u>※注意</u><br> | |||
<u>1つのソフトウェアでは、プレーンテキストベースの機能のみ、または、テキストIDベースの機能のみを使用する必要がある。</u><br> | |||
<u>これらを混在させると、翻訳されるテキストのセットが不完全なものになってしまうことに注意する。</u><br> | |||
<br> | |||
==== テキストIDを使用したローカライゼーション ==== | |||
プレーンテキストではなくテキストIDを使用する場合、ソフトウェアのローカライゼーションの一般的な方法は同じであるが、細部が少し異なる。<br> | |||
<br> | |||
* テキストIDベースの翻訳システム用の関数とマクロは、プレーンテキストシステムとは異なる。<br><code>qsTr</code>メソッドの代わりに<code>qsTrId</code>メソッド、<code>QT_TR_NOOP</code>メソッドの代わりに<code>QT_TRID_NOOP</code>マクロを使用する。 | |||
*: <br> | |||
* プレーンテキスト文字列ではなく、テキストIDをユーザインターフェース文字列として使用する。 | |||
*: 例. <code>qsTrId("id-back-not-front")</code> | |||
*: <br> | |||
* テキストIDを持つコンテキストパラメータを指定することはできない。<br>同じ綴りで異なる意味を持つ単語がある場合、これらは別々のテキストIDを必要とする。 | |||
*: 例. <code>qsTrId("id-back-backstep")</code>は、バックステップの"Back"とオブジェクトの背面である"Back"を区別する。 | |||
*: <br> | |||
* 開発において、ユーザインターフェースに表示されるテキスト(文言)は、<code>//%</code>のコメントで示される。<br>これを付加しない場合は、ユーザインターフェイスにテキストIDが表示される。<br><br>これは、パラメータを持つテキストがある場合に特に重要である。<br>コメントには、文字列中のパラメータインジケータを含める必要がある。 | |||
*: 例. <code>//% "ファイル数: %1"</code> | |||
*: <br> | |||
* 翻訳者に追加情報を提供する<code>//:</code>コメントは、プレーンテキストシステムでは任意である。<br><u>しかし、テキストIDベースのシステムでは、この追加情報が必須となる。</u><br>これは、追加情報が無い場合はテキストIDしか得られず、翻訳者はさらなる文脈なしに翻訳することができないかもしれないからである。<br><br>長い説明的なテキストIDを使用してコメントを使用しないこともできるが、コメントの方が理解しやすい場合がある。 | |||
<br> | |||
下表に、テキストIDベースとプレーンテキストベースの翻訳を比較したものを示す。<br> | |||
<center> | |||
{| class="wikitable" | style="background-color:#fefefe;" | |||
|+ テキストIDベースとプレーンテキストベースの翻訳の比較 | |||
|- | |||
! style="background-color:#66CCFF;" | テキストIDベース | |||
! style="background-color:#66CCFF;" | プレーンテキストベース | |||
|- | |||
| | |||
<syntaxhighlight lang="qml"> | |||
Text { | |||
id: backTxt; | |||
//: The back of the object, not the front | |||
//% "Back" | |||
//~ Context Not related to back-stepping | |||
text: qsTrId("id-back-not-front"); | |||
} | |||
</syntaxhighlight> | |||
| | |||
<syntaxhighlight lang="qml"> | |||
Text { | |||
id: backTxt; | |||
//: The back of the object, not the front | |||
//~ Context Not related to back-stepping | |||
text: qsTr("Back","Not front") | |||
} | |||
</syntaxhighlight> | |||
|} | |||
</center> | |||
<br> | |||
==== テキストIDを使用したローカライズ ==== | |||
テキストIDを使用したローカライズは、プレーンテキストの場合とほぼ同じ手順で行う。<br> | |||
<br> | |||
<code>lupdate</code>コマンドを使用して、tsファイルへの翻訳を行う。<br> | |||
lupdate <Qtプロジェクトファイル>.pro | |||
<br> | |||
<u>※注意</u><br> | |||
<u>翻訳ファイルのソース値はプレーンテキストではなく、テキストIDであることに注意する。</u><br> | |||
<u>つまり、翻訳者が正しい翻訳を行うためには、説明的なテキストID、または、優れた追加コメント、またはその両方が必要である。</u><br> | |||
<br> | |||
テキストIDベースのユーザインターフェイスでは、TSファイルに以下に示すようなコンテンツが含まれる。<br> | |||
<nowiki> | |||
<message id="id-back-not-front"> | |||
<source>Back</source> | |||
<extracomment>The back of the object, not the front</extracomment> | |||
<translation type="unfinished"></translation> | |||
<extra-Context>Not related to back-stepping</extra-Context> | |||
</message> | |||
</nowiki> | |||
<br> | |||
<code>lrelease</code>コマンドを使用する場合、翻訳されたテキストのキーがプレーンテキストではなく、テキストIDに基づくことを指定する必要がある。<br> | |||
<code>qsTr</code>メソッドを使用して、ソースコード内の文字列を指定した場合、<code>id</code>属性が設定されていないため、<code>lrelease</code>コマンドでは無視される。<br> | |||
<br> | |||
<code>lrelease</code>コマンドは、ソフトウェアのためにコンパイルされた全ての翻訳であるQMファイルを生成する。<br> | |||
lrelease -idbased <Qtプロジェクトファイル>.pro | |||
<br><br> | <br><br> | ||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ:Qt]] | [[カテゴリ:Qt]] |