VirtualBox

source: vbox/trunk/src/libs/dita-ot-1.8.5/doc/dev_ref/plugin-addgeneratedtext.html@ 98878

最後變更 在這個檔案從98878是 98584,由 vboxsync 提交於 2 年 前

Docs: bugref:10302. Setting svn properties of DITA-OT library.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 10.5 KB
 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4<html xml:lang="en-us" lang="en-us">
5<head>
6<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7<meta name="copyright" content="(C) Copyright 2005"/>
8<meta name="DC.rights.owner" content="(C) Copyright 2005"/>
9<meta name="DC.Type" content="reference"/>
10<meta name="DC.Title" content="Modifying or adding generated text"/>
11<meta name="abstract" 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 &lt;note&gt; element."/>
12<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 &lt;note&gt; element."/>
13<meta name="DC.Relation" scheme="URI" content="../dev_ref/plugins-overview.html"/>
14<meta name="DC.Relation" scheme="URI" content="../readme/DITA-globalization-xhtml.html"/>
15<meta name="DC.Format" content="XHTML"/>
16<meta name="DC.Identifier" content="plugin-addgeneratedtext"/>
17<meta name="DC.Language" content="en-us"/>
18<link rel="stylesheet" type="text/css" href="../commonltr.css"/>
19<link rel="stylesheet" type="text/css" href="../dita-ot-doc.css"/>
20<title>Modifying or adding generated text</title>
21</head>
22<body id="plugin-addgeneratedtext">
23
24
25<h1 class="title topictitle1">Modifying or adding generated text</h1>
26
27
28<div class="body refbody"><p class="shortdesc">Generated text is the term for strings that are automatically
29added by the build, such as "Note" before the contents of a &lt;note&gt;
30element.</p>
31
32<div class="section"><div class="p">The generated text extension point is used to add new
33strings to the default set of generated text. There are several reasons
34you may want to use this:<ul class="ul">
35<li class="li">It can be used to add new text for your own processing extensions;
36for example, it could be used to add localized versions of the string
37"User response" to aid in rendering troubleshooting information.</li>
38
39<li class="li">It can be used to override the default strings in the toolkit;
40for example, it could be used to reset the English string "Figure"
41to "Fig".</li>
42
43<li class="li">It can be used to add support for new languages (for non-PDF transforms
44only; PDF requires more complicated localization support). For example,
45it could be used to add support for Vietnamese or Gaelic; it could
46also be used to support a new variant of a previously supported language,
47such as Australian English.</li>
48
49</ul>
50</div>
51<dl class="dl">
52<dt class="dt dlterm"><samp class="ph codeph">dita.xsl.strings</samp></dt>
53
54<dd class="dd">Add new strings to generated text file. </dd>
55
56</dl>
57 </div>
58
59<div class="example"><h2 class="title sectiontitle">Example: adding new strings</h2><p class="p">First copy the
60file <span class="ph filepath">xsl/common/strings.xml</span> to your plug-in,
61and edit it to contain the languages that you are providing translations
62for ("en-us" must be present). For this sample, copy the file into
63your plug-in as <span class="ph filepath">xsl/my-new-strings.xml</span>. The new
64strings file will look something like this:</p>
65<pre class="pre codeblock">&lt;?xml version="1.0" encoding="utf-8"?&gt;
66&lt;!-- Provide strings for my plug-in; this plug-in supports
67 English, Icelandic, and Russian. --&gt;
68&lt;langlist&gt;
69 &lt;lang xml:lang="en" filename="mystring-en-us.xml"/&gt;
70 &lt;lang xml:lang="en-us" filename="mystring-en-us.xml"/&gt;
71 &lt;lang xml:lang="is" filename="mystring-is-is.xml"/&gt;
72 &lt;lang xml:lang="is-is" filename="mystring-is-is.xml"/&gt;
73 &lt;lang xml:lang="ru" filename="mystring-ru-ru.xml"/&gt;
74 &lt;lang xml:lang="ru-ru" filename="mystring-ru-ru.xml"/&gt;
75&lt;/langlist&gt;</pre>
76<p class="p">Next, copy the file <span class="ph filepath">xsl/common/strings-en-us.xml</span> to
77your plug-in, and replace the content with your own strings (be sure
78to give them unique name attributes). Do the same for each language
79that you are providing a translation for. For example, the file <span class="ph filepath">mystring-en-us.xml</span> might
80contain:</p>
81<pre class="pre codeblock">&lt;?xml version="1.0" encoding="utf-8"?&gt;
82&lt;strings xml:lang="en-us"&gt;
83 &lt;str name="String1"&gt;English generated text&lt;/str&gt;
84 &lt;str name="Another String"&gt;Another String in English&lt;/str&gt;
85&lt;/strings&gt;</pre>
86<p class="p">Use the following extension code to include
87your strings in the set of generated text: </p>
88<pre class="pre codeblock">&lt;plugin id="com.example.strings"&gt;
89 &lt;feature extension="dita.xsl.strings" file="xsl/my-new-strings.xml"/&gt;
90&lt;/plugin&gt;</pre>
91<p class="p">The string is now available to the "getString"
92template used in many DITA-OT XSLT files. For example, if processing
93in a context where the xml:lang value is "en-us", the following call
94would return "Another String in English":</p>
95<pre class="pre codeblock">&lt;xsl:call-template name="getString"&gt;
96 &lt;xsl:with-param name="stringName" select="'Another String'"/&gt;
97&lt;/xsl:call-template&gt;
98</pre>
99<div class="note note"><span class="notetitle">Note:</span> If two plug-ins define the same string, the results
100will be non-deterministic, so multiple plug-ins should not try to
101create the same generated text string. One common way to avoid this
102problem is to ensure the name attributes used to look up the string
103value are related to the ID or purpose of your plug-in.</div>
104</div>
105
106<div class="example"><h2 class="title sectiontitle">Example: modifying existing strings</h2><p class="p">The
107process for modifying existing generated text is exactly the same
108as for adding new text, except that the strings you provide override
109values that already exist. To begin, set up the <span class="ph filepath">xsl/my-new-strings.xml</span> file
110in your plug-in as in the previous example. </p>
111<p class="p">Next, copy the
112file <span class="ph filepath">xsl/common/strings-en-us.xml</span> to your plug-in,
113and choose the strings you wish to change (be sure to leave the name
114attribute unchanged, because this is the key used to look up the string).
115Create a strings file for each language that needs to modify existing
116strings. For example, the new file <span class="ph filepath">mystring-en-us.xml</span> might
117contain:</p>
118<pre class="pre codeblock">&lt;?xml version="1.0" encoding="utf-8"?&gt;
119&lt;strings xml:lang="en-us"&gt;
120 &lt;str name="Figure"&gt;Fig&lt;/str&gt;
121 &lt;str name="Draft comment"&gt;ADDRESS THIS DRAFT COMMENT&lt;/str&gt;
122&lt;/strings&gt;</pre>
123<p class="p">To integrate the new strings, use the
124same method as above to add these strings to your <span class="ph filepath">plugin.xml</span> file.
125Once this plug-in is integrated, where XHTML output previously generated
126the term "Figure", it will now generate "Fig"; where it previously
127generated "Draft comment", it will now generate "ADDRESS THIS DRAFT
128COMMENT". The same strings in other languages will not be modified
129unless you also provide new versions for those languages.</p>
130<div class="note note"><span class="notetitle">Note:</span> If
131two plug-ins override the same string in the same language, the results
132will be non-deterministic (either string may be used under different
133conditions). Multiple plug-ins should not override the same generated
134text string for a single language.</div>
135</div>
136
137<div class="example"><h2 class="title sectiontitle">Example: adding a new language</h2><div class="p">The process
138for adding a new language is exactly the same as for adding new text,
139except you are effectively just translating an existing strings file.
140To begin, set up the <span class="ph filepath">xsl/my-new-strings.xml</span> file
141in your plug-in as in the previous examples. In this case, the only
142difference is that you are adding a mapping to new languages; for
143example, the following file would be used to set up support for Vietnamese:<pre class="pre codeblock">&lt;?xml version="1.0" encoding="utf-8"?&gt;
144&lt;!-- Map languages with xml:lang="vi" or xml:lang="vi-vn"
145 to the translations in this plug-in. --&gt;
146&lt;langlist&gt;
147 &lt;lang xml:lang="vi" filename="strings-vi.xml"/&gt;
148 &lt;lang xml:lang="vi-vn" filename="strings-vi.xml"/&gt;
149&lt;/langlist&gt;</pre>
150</div>
151<p class="p">Next, copy the file <span class="ph filepath">xsl/common/strings-en-us.xml</span> to
152your plug-in, and rename it to match the language you wish to add.
153For example, to support Vietnamese strings you may want to pick a
154name like <span class="ph filepath">strings-vi.xml</span>. In that file, change
155the <samp class="ph codeph">xml:lang</samp> attribute on the root element to match
156your new language.</p>
157<p class="p">Once the file is ready, translate the contents
158of each <samp class="ph codeph">&lt;str&gt;</samp> element (be sure to leave the name
159attribute unchanged). Repeat this process for each new language you
160wish to add.</p>
161<p class="p">To integrate the new languages, use the same method
162as above to add these strings to your <span class="ph filepath">plugin.xml</span> file.
163Once this plug-in is integrated, non-PDF builds will include support
164for Vietnamese; instead of generating the English word "Caution",
165the element <samp class="ph codeph">&lt;note type="caution" xml:lang="vi"&gt;</samp> may
166generate something like "<dfn class="term" xml:lang="vi" lang="vi">chú ý</dfn>".</p>
167<div class="note note"><span class="notetitle">Note:</span> If
168two plug-ins add support for the same language using different
169values, the results will be non-deterministic (translations from either
170plug-in may be picked up under different conditions).</div>
171</div>
172
173</div>
174
175<div class="related-links">
176<div class="familylinks">
177<div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../dev_ref/plugins-overview.html" title="The DITA Open Toolkit comes with a built in mechanism for adding in extensions through plug-ins. These plug-ins may do a wide variety of things, such as adding support for specialized DITA DTDs or Schemas, integrating processing overrides, or even providing entirely new output transforms. Plug-ins are the best way to extend the toolkit in a way that is consistent, easily sharable, and easy to preserve through toolkit upgrades.">Creating DITA-OT plug-ins</a></div>
178</div>
179<div class="relinfo relref"><strong>Related reference</strong><br/>
180<div><a class="link" href="../readme/DITA-globalization-xhtml.html" title="The DITA Open Toolkit (DITA-OT) supports over 50 languages and language variants for the HTML- and XHTML-based transformations, for example, Eclipse Help, HTML Help, and TocJS.">Languages supported by the core toolkit</a></div>
181</div>
182</div>
183
184</body>
185</html>
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette