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