VirtualBox

source: vbox/trunk/src/libs/dita-ot-1.8.5/docsrc/dev_ref/plugin-addgeneratedtext.dita@ 99507

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

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

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

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