plugin-addgeneratedtext.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <html lang="en-us"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2019"><meta name="DC.rights.owner" content="(C) Copyright 2019"><meta name="DC.type" content="reference"><meta name="description" content="Generated text is the term for strings that are automatically added by the build, such as &#34;Note&#34; before the contents of a note element."><meta name="DC.subject" content=", note, xml:lang, languages, adding support for, English, Icelandic, Russian, Vietnamese, Gaelic, strings, generated text, draft, localizing generated text"><meta name="keywords" content=", note, xml:lang, languages, adding support for, English, Icelandic, Russian, Vietnamese, Gaelic, strings, generated text, draft, localizing generated text"><meta name="DC.relation" scheme="URI" content="../topics/globalization.html"><meta name="DC.relation" scheme="URI" content="../topics/globalization-languages.html"><meta name="DC.format" content="HTML5"><meta name="DC.identifier" content="plugin-addgeneratedtext"><meta name="DC.language" content="en-US"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Customizing generated text</title></head><body id="plugin-addgeneratedtext"><header role="banner"><div class="header">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../topics/installing-client.html">Installing DITA-OT</a></li><li><a href="../topics/alternative-input-formats.html">Authoring formats</a></li><li><a href="../topics/building-output.html">Building output</a></li><li><a href="../parameters/index.html">Setting parameters</a></li><li><a href="../topics/customizing.html">Customizing DITA-OT</a><ul><li><a href="../topics/html-customization.html">Customizing HTML</a></li><li><a href="../topics/pdf-customization.html">Customizing PDF</a></li><li><a href="../topics/custom-plugins.html">Working with plug-ins</a></li><li><a href="../extension-points/plugin-extension-points.html">Extension points</a></li><li><a href="../topics/migration.html">Migrating customizations</a></li><li><a href="../topics/globalization.html">Globalizing DITA content</a><ul><li><a href="../topics/globalization-support.html">Globalization support</a></li><li class="active"><a href="../topics/plugin-addgeneratedtext.html">Customizing generated text</a></li><li><a href="../topics/globalization-languages.html">Supported languages</a></li></ul></li><li><a href="../topics/rebuilding-docs.html">Rebuilding documentation</a></li></ul></li><li><a href="../topics/troubleshooting-overview.html">Troubleshooting</a></li><li><a href="../reference/index.html">Reference</a></li><li><a href="../topics/dita-and-dita-ot-resources.html">Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Customizing generated text</h1>
  8. <div class="body refbody"><p class="shortdesc">Generated text is the term for strings that are automatically added by the build, such as "Note" before the
  9. contents of a <code class="keyword markupname xmlelement">&lt;note&gt;</code> element.</p>
  10. <section class="section">
  11. <div class="p">The generated text extension point is used to add new strings to the default set of generated text. There are
  12. several reasons you may want to use this:
  13. <ul class="ul">
  14. <li class="li">It can be used to add new text for your own processing extensions; for example, it could be used to add
  15. localized versions of the string "User response" to aid in rendering troubleshooting information.</li>
  16. <li class="li">It can be used to override the default strings in the toolkit; for example, it could be used to reset the
  17. English string "Figure" to "Fig".</li>
  18. <li class="li">It can be used to add support for new languages (for non-PDF transforms only; PDF requires more
  19. complicated localization support). For example, it could be used to add support for Vietnamese or Gaelic; it
  20. could also be used to support a new variant of a previously supported language, such as Australian
  21. English.</li>
  22. </ul></div>
  23. <dl class="dl">
  24. <dt class="dt dlterm"><code class="ph codeph">dita.xsl.strings</code></dt>
  25. <dd class="dd">Add new strings to generated text file. </dd>
  26. </dl>
  27. </section>
  28. <div class="example"><h2 class="title sectiontitle">Example: adding new strings</h2>
  29. <p class="p">First copy the file <span class="ph filepath">xsl/common/strings.xml</span> to your plug-in, and edit it to contain the
  30. languages that you are providing translations for ("en-US" must be present). For this sample, copy the file into
  31. your plug-in as <span class="ph filepath">xsl/my-new-strings.xml</span>. The new strings file will look something like
  32. this:</p><pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  33. &lt;!-- Provide strings for my plug-in; this plug-in supports
  34. English, Icelandic, and Russian. --&gt;
  35. &lt;langlist&gt;
  36. &lt;lang xml:lang="en" filename="mystring-en-us.xml"/&gt;
  37. &lt;lang xml:lang="en-US" filename="mystring-en-us.xml"/&gt;
  38. &lt;lang xml:lang="is" filename="mystring-is-is.xml"/&gt;
  39. &lt;lang xml:lang="is-IS" filename="mystring-is-is.xml"/&gt;
  40. &lt;lang xml:lang="ru" filename="mystring-ru-ru.xml"/&gt;
  41. &lt;lang xml:lang="ru-RU" filename="mystring-ru-ru.xml"/&gt;
  42. &lt;/langlist&gt;</code></pre>
  43. <p class="p">Next, copy the file <span class="ph filepath">xsl/common/strings-en-us.xml</span> to your plug-in, and replace the content
  44. with your own strings (be sure to give them unique name attributes). Do the same for each language that you are
  45. providing a translation for. For example, the file <span class="ph filepath">mystring-en-us.xml</span> might contain:</p><pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  46. &lt;strings xml:lang="en-US"&gt;
  47. &lt;str name="String1"&gt;English generated text&lt;/str&gt;
  48. &lt;str name="Another String"&gt;Another String in English&lt;/str&gt;
  49. &lt;/strings&gt;</code></pre>
  50. <p class="p">Use the following extension code to include your strings in the set of generated text: </p><pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;plugin id="com.example.strings"&gt;
  51. &lt;feature extension="dita.xsl.strings" file="xsl/my-new-strings.xml"/&gt;
  52. &lt;/plugin&gt;</code></pre>
  53. <p class="p">The string is now available to the "getVariable" template used in many DITA-OT XSLT files.
  54. For example, if processing in a context where the xml:lang value is "en-US", the following
  55. call would return "Another String in English":</p><pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;xsl:call-template name="getVariable"&gt;
  56. &lt;xsl:with-param name="id" select="'Another String'"/&gt;
  57. &lt;/xsl:call-template&gt;</code></pre>
  58. <div class="note note note_note"><span class="note__title">Note:</span> If two plug-ins define the same string, the results will be non-deterministic, so multiple plug-ins should
  59. not try to create the same generated text string. One common way to avoid this problem is to ensure the name
  60. attributes used to look up the string value are related to the ID or purpose of your plug-in.</div>
  61. </div>
  62. <div class="example"><h2 class="title sectiontitle">Example: modifying existing strings</h2>
  63. <p class="p">The process for modifying existing generated text is exactly the same as for adding new text, except that the
  64. strings you provide override values that already exist. To begin, set up the
  65. <span class="ph filepath">xsl/my-new-strings.xml</span> file in your plug-in as in the previous example. </p>
  66. <p class="p">Next, copy the file <span class="ph filepath">xsl/common/strings-en-us.xml</span> to your plug-in, and choose the strings
  67. you wish to change (be sure to leave the name attribute unchanged, because this is the key used to look up the
  68. string). Create a strings file for each language that needs to modify existing strings. For example, the new
  69. file <span class="ph filepath">mystring-en-us.xml</span> might contain:</p><pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  70. &lt;strings xml:lang="en-US"&gt;
  71. &lt;str name="Figure"&gt;Fig&lt;/str&gt;
  72. &lt;str name="Draft comment"&gt;ADDRESS THIS DRAFT COMMENT&lt;/str&gt;
  73. &lt;/strings&gt;</code></pre>
  74. <p class="p">To include the new strings, use the same method as above to add these strings to your
  75. <span class="ph filepath">plugin.xml</span> file. Once this plug-in is installed, where XHTML output previously generated
  76. the term "Figure", it will now generate "Fig"; where it previously generated "Draft comment", it will now
  77. generate "ADDRESS THIS DRAFT COMMENT". The same strings in other languages will not be modified unless you also
  78. provide new versions for those languages.</p><div class="note note note_note"><span class="note__title">Note:</span> If two plug-ins override the same string in the same
  79. language, the results will be non-deterministic (either string may be used under different conditions). Multiple
  80. plug-ins should not override the same generated text string for a single language.</div>
  81. </div>
  82. <div class="example"><h2 class="title sectiontitle">Example: adding a new language</h2>
  83. <div class="p">The process for adding a new language is exactly the same as for adding new text, except you are effectively
  84. just translating an existing strings file. To begin, set up the <span class="ph filepath">xsl/my-new-strings.xml</span> file
  85. in your plug-in as in the previous examples. In this case, the only difference is that you are adding a mapping
  86. to new languages; for example, the following file would be used to set up support for
  87. Vietnamese:<pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  88. &lt;!-- Map languages with xml:lang="vi" or xml:lang="vi-vn"
  89. to the translations in this plug-in. --&gt;
  90. &lt;langlist&gt;
  91. &lt;lang xml:lang="vi" filename="strings-vi.xml"/&gt;
  92. &lt;lang xml:lang="vi-VN" filename="strings-vi.xml"/&gt;
  93. &lt;/langlist&gt;</code></pre></div>
  94. <p class="p">Next, copy the file <span class="ph filepath">xsl/common/strings-en-us.xml</span> to your plug-in, and rename it to match
  95. the language you wish to add. For example, to support Vietnamese strings you may want to pick a name like
  96. <span class="ph filepath">strings-vi.xml</span>. In that file, change the <code class="keyword markupname xmlatt">@xml:lang</code> attribute on the root
  97. element to match your new language.</p>
  98. <p class="p">Once the file is ready, translate the contents of each <code class="keyword markupname xmlelement">&lt;str&gt;</code> element (be sure to leave
  99. the name attribute unchanged). Repeat this process for each new language you wish to add.</p>
  100. <p class="p">To include the new languages, use the same method as above to add these strings to your
  101. <span class="ph filepath">plugin.xml</span> file. Once this plug-in is installed, non-PDF builds will include support for
  102. Vietnamese; instead of generating the English word "Caution", the element <code class="ph codeph">&lt;note type="caution"
  103. xml:lang="vi"&gt;</code> may generate something like "<dfn class="term" lang="vi">chú ý</dfn>".</p><div class="note note note_note"><span class="note__title">Note:</span> If two
  104. plug-ins add support for the same language using different values, the results will be non-deterministic
  105. (translations from either plug-in may be picked up under different conditions).</div>
  106. </div>
  107. </div>
  108. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../topics/globalization.html" title="The DITA standard supports content that is written in or translated to any language. In general, DITA Open Toolkit passes content through to the output format unchanged. DITA-OT uses the values for the xml:lang and dir attributes that are set in the source content to provide globalization support.">Globalizing DITA content</a></div></div><div class="linklist relinfo relref"><strong>Related reference</strong><br><ul class="linklist"><li class="linklist"><a class="link" href="../topics/globalization-languages.html" title="The following languages are supported for all PDF, XHTML, and HTML5-based transformation types.">Languages supported by the core toolkit</a></li></ul></div></nav></article></main></body></html>