plugin-addgeneratedtext.dita 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <reference id="plugin-addgeneratedtext" xml:lang="en-US">
  5. <title>Customizing generated text</title>
  6. <shortdesc>Generated text is the term for strings that are automatically added by the build, such as "Note" before the
  7. contents of a <xmlelement>note</xmlelement> element.</shortdesc>
  8. <prolog>
  9. <metadata>
  10. <keywords>
  11. <indexterm><xmlelement>note</xmlelement></indexterm>
  12. <indexterm><xmlatt>xml:lang</xmlatt></indexterm>
  13. <indexterm>languages<indexterm>adding support for</indexterm></indexterm>
  14. <indexterm>English</indexterm>
  15. <indexterm>Icelandic</indexterm>
  16. <indexterm>Russian</indexterm>
  17. <indexterm>Vietnamese</indexterm>
  18. <indexterm>Gaelic</indexterm>
  19. <indexterm>strings</indexterm>
  20. <indexterm>generated text</indexterm>
  21. <indexterm>draft<indexterm>localizing generated text</indexterm></indexterm>
  22. </keywords>
  23. </metadata>
  24. </prolog>
  25. <refbody>
  26. <section>
  27. <p>The generated text extension point is used to add new strings to the default set of generated text. There are
  28. several reasons you may want to use this:
  29. <ul>
  30. <li>It can be used to add new text for your own processing extensions; for example, it could be used to add
  31. localized versions of the string "User response" to aid in rendering troubleshooting information.</li>
  32. <li>It can be used to override the default strings in the toolkit; for example, it could be used to reset the
  33. English string "Figure" to "Fig".</li>
  34. <li>It can be used to add support for new languages (for non-PDF transforms only; PDF requires more
  35. complicated localization support). For example, it could be used to add support for Vietnamese or Gaelic; it
  36. could also be used to support a new variant of a previously supported language, such as Australian
  37. English.</li>
  38. </ul></p>
  39. <dl>
  40. <dlentry>
  41. <dt><codeph>dita.xsl.strings</codeph></dt>
  42. <dd>Add new strings to generated text file. </dd>
  43. </dlentry>
  44. </dl>
  45. </section>
  46. <example>
  47. <title>Example: adding new strings</title>
  48. <p>First copy the file <filepath>xsl/common/strings.xml</filepath> to your plug-in, and edit it to contain the
  49. languages that you are providing translations for ("en-US" must be present). For this sample, copy the file into
  50. your plug-in as <filepath>xsl/my-new-strings.xml</filepath>. The new strings file will look something like
  51. this:</p><codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="utf-8"?>
  52. &lt;!-- Provide strings for my plug-in; this plug-in supports
  53. English, Icelandic, and Russian. -->
  54. &lt;langlist>
  55. &lt;lang xml:lang="en" filename="mystring-en-us.xml"/>
  56. &lt;lang xml:lang="en-US" filename="mystring-en-us.xml"/>
  57. &lt;lang xml:lang="is" filename="mystring-is-is.xml"/>
  58. &lt;lang xml:lang="is-IS" filename="mystring-is-is.xml"/>
  59. &lt;lang xml:lang="ru" filename="mystring-ru-ru.xml"/>
  60. &lt;lang xml:lang="ru-RU" filename="mystring-ru-ru.xml"/>
  61. &lt;/langlist></codeblock>
  62. <p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> to your plug-in, and replace the content
  63. with your own strings (be sure to give them unique name attributes). Do the same for each language that you are
  64. providing a translation for. For example, the file <filepath>mystring-en-us.xml</filepath> might contain:</p><codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="utf-8"?>
  65. &lt;strings xml:lang="en-US">
  66. &lt;str name="String1">English generated text&lt;/str>
  67. &lt;str name="Another String">Another String in English&lt;/str>
  68. &lt;/strings></codeblock>
  69. <p>Use the following extension code to include your strings in the set of generated text: </p><codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;plugin id="com.example.strings">
  70. &lt;feature extension="dita.xsl.strings" file="xsl/my-new-strings.xml"/>
  71. &lt;/plugin></codeblock>
  72. <p>The string is now available to the "getVariable" template used in many DITA-OT XSLT files.
  73. For example, if processing in a context where the xml:lang value is "en-US", the following
  74. call would return "Another String in English":</p><codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;xsl:call-template name="getVariable">
  75. &lt;xsl:with-param name="id" select="'Another String'"/>
  76. &lt;/xsl:call-template></codeblock>
  77. <note>If two plug-ins define the same string, the results will be non-deterministic, so multiple plug-ins should
  78. not try to create the same generated text string. One common way to avoid this problem is to ensure the name
  79. attributes used to look up the string value are related to the ID or purpose of your plug-in.</note>
  80. </example>
  81. <example>
  82. <title>Example: modifying existing strings</title>
  83. <p>The process for modifying existing generated text is exactly the same as for adding new text, except that the
  84. strings you provide override values that already exist. To begin, set up the
  85. <filepath>xsl/my-new-strings.xml</filepath> file in your plug-in as in the previous example. </p>
  86. <p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> to your plug-in, and choose the strings
  87. you wish to change (be sure to leave the name attribute unchanged, because this is the key used to look up the
  88. string). Create a strings file for each language that needs to modify existing strings. For example, the new
  89. file <filepath>mystring-en-us.xml</filepath> might contain:</p><codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="utf-8"?>
  90. &lt;strings xml:lang="en-US">
  91. &lt;str name="Figure">Fig&lt;/str>
  92. &lt;str name="Draft comment">ADDRESS THIS DRAFT COMMENT&lt;/str>
  93. &lt;/strings></codeblock>
  94. <p>To include the new strings, use the same method as above to add these strings to your
  95. <filepath>plugin.xml</filepath> file. Once this plug-in is installed, where XHTML output previously generated
  96. the term "Figure", it will now generate "Fig"; where it previously generated "Draft comment", it will now
  97. generate "ADDRESS THIS DRAFT COMMENT". The same strings in other languages will not be modified unless you also
  98. provide new versions for those languages.</p><note>If two plug-ins override the same string in the same
  99. language, the results will be non-deterministic (either string may be used under different conditions). Multiple
  100. plug-ins should not override the same generated text string for a single language.</note>
  101. </example>
  102. <example>
  103. <title>Example: adding a new language</title>
  104. <p>The process for adding a new language is exactly the same as for adding new text, except you are effectively
  105. just translating an existing strings file. To begin, set up the <filepath>xsl/my-new-strings.xml</filepath> file
  106. in your plug-in as in the previous examples. In this case, the only difference is that you are adding a mapping
  107. to new languages; for example, the following file would be used to set up support for
  108. Vietnamese:<codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="utf-8"?>
  109. &lt;!-- Map languages with xml:lang="vi" or xml:lang="vi-vn"
  110. to the translations in this plug-in. -->
  111. &lt;langlist>
  112. &lt;lang xml:lang="vi" filename="strings-vi.xml"/>
  113. &lt;lang xml:lang="vi-VN" filename="strings-vi.xml"/>
  114. &lt;/langlist></codeblock></p>
  115. <p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> to your plug-in, and rename it to match
  116. the language you wish to add. For example, to support Vietnamese strings you may want to pick a name like
  117. <filepath>strings-vi.xml</filepath>. In that file, change the <xmlatt>xml:lang</xmlatt> attribute on the root
  118. element to match your new language.</p>
  119. <p>Once the file is ready, translate the contents of each <xmlelement>str</xmlelement> element (be sure to leave
  120. the name attribute unchanged). Repeat this process for each new language you wish to add.</p>
  121. <p>To include the new languages, use the same method as above to add these strings to your
  122. <filepath>plugin.xml</filepath> file. Once this plug-in is installed, non-PDF builds will include support for
  123. Vietnamese; instead of generating the English word "Caution", the element <codeph>&lt;note type="caution"
  124. xml:lang="vi"></codeph> may generate something like "<term xml:lang="vi">chú ý</term>".</p><note>If two
  125. plug-ins add support for the same language using different values, the results will be non-deterministic
  126. (translations from either plug-in may be picked up under different conditions).</note>
  127. </example>
  128. </refbody>
  129. </reference>