Skip to content

Commit f75692a

Browse files
authored
Merge pull request #347 from xephon2/develop-patch-2
Explain the two different XML structures for adding and modifying strings.
2 parents 2f2f167 + 1d16219 commit f75692a

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

topics/plugin-addgeneratedtext.dita

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,35 @@
4444
<dd>Add new strings to generated text file. </dd>
4545
</dlentry>
4646
</dl>
47+
<note>There are two different XML structures for adding new or modifying existing strings. Both can be used with
48+
the latest DITA-OT. The new structure (root element <xmlelement>vars</xmlelement>) has the benefit to add custom
49+
parameters to the string, such as the current page number, but the old structure (root element
50+
<xmlelement>strings</xmlelement>) is still valid. For example, the old structure is still used in the
51+
<b>org.dita.base</b> plugin and the new structure is used in <b>org.dita.pdf2</b>. The following code snippets
52+
represent the same information in the old and the new structure. If you are interested in the capabilities of
53+
the parameter mechanism, please have a look at the XML files stored in
54+
<filepath>org.dita.pdf2\cfg\common\vars</filepath>.
55+
<codeblock
56+
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
57+
>&lt;?xml version="1.0" encoding="utf-8"?>
58+
&lt;strings xml:lang="en-US">
59+
&lt;str name="String1">English generated text&lt;/str>
60+
&lt;/strings></codeblock>
61+
<codeblock
62+
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
63+
>&lt;?xml version="1.0" encoding="UTF-8"?>
64+
&lt;vars xmlns="http://www.idiominc.com/opentopic/vars">
65+
&lt;variable id="String1">English generated text&lt;/variable>
66+
&lt;/vars></codeblock>
67+
</note>
4768
</section>
4869
<example>
4970
<title>Example: adding new strings</title>
5071
<p>First, copy the file <filepath>xsl/common/strings.xml</filepath> from the base plug-in directory
5172
<filepath>plugins/org.dita.base</filepath> to your plug-in, and edit it to contain the languages that you are
5273
providing translations for ("en-US" must be present). For this sample, copy the file into your plug-in as
53-
<filepath>xsl/my-new-strings.xml</filepath>. The new strings file will look something like this:</p><codeblock
74+
<filepath>xsl/my-new-strings.xml</filepath>. The new strings file will look something like this:</p>
75+
<codeblock
5476
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
5577
>&lt;?xml version="1.0" encoding="utf-8"?>
5678
&lt;!-- Provide strings for my plug-in; this plug-in supports
@@ -66,21 +88,24 @@
6688
<p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> from the base plug-in directory
6789
<filepath>plugins/org.dita.base</filepath> to your plug-in, and replace the content with your own strings (be
6890
sure to give them unique name attributes). Do the same for each language that you are providing a translation
69-
for. For example, the file <filepath>mystring-en-us.xml</filepath> might contain:</p><codeblock
91+
for. For example, the file <filepath>mystring-en-us.xml</filepath> might contain:</p>
92+
<codeblock
7093
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
7194
>&lt;?xml version="1.0" encoding="utf-8"?>
7295
&lt;strings xml:lang="en-US">
7396
&lt;str name="String1">English generated text&lt;/str>
7497
&lt;str name="Another String">Another String in English&lt;/str>
7598
&lt;/strings></codeblock>
76-
<p>Use the following extension code to include your strings in the set of generated text: </p><codeblock
99+
<p>Use the following extension code to include your strings in the set of generated text:</p>
100+
<codeblock
77101
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
78102
>&lt;plugin id="com.example.strings">
79103
&lt;feature extension="dita.xsl.strings" file="xsl/my-new-strings.xml"/>
80104
&lt;/plugin></codeblock>
81105
<p>The string is now available to the "getVariable" template used in many DITA-OT XSLT files. For example, if
82106
processing in a context where the xml:lang value is "en-US", the following call would return "Another String in
83-
English":</p><codeblock
107+
English":</p>
108+
<codeblock
84109
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
85110
>&lt;xsl:call-template name="getVariable">
86111
&lt;xsl:with-param name="id" select="'Another String'"/>
@@ -93,12 +118,13 @@
93118
<title>Example: modifying existing strings</title>
94119
<p>The process for modifying existing generated text is exactly the same as for adding new text, except that the
95120
strings you provide override values that already exist. To begin, set up the
96-
<filepath>xsl/my-new-strings.xml</filepath> file in your plug-in as in the previous example. </p>
121+
<filepath>xsl/my-new-strings.xml</filepath> file in your plug-in as in the previous example.</p>
97122
<p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> from the base plug-in directory
98123
<filepath>plugins/org.dita.base</filepath> to your plug-in, and choose the strings you wish to change (be sure
99124
to leave the name attribute unchanged, because this is the key used to look up the string). Create a strings
100125
file for each language that needs to modify existing strings. For example, the new file
101-
<filepath>mystring-en-us.xml</filepath> might contain:</p><codeblock
126+
<filepath>mystring-en-us.xml</filepath> might contain:</p>
127+
<codeblock
102128
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
103129
>&lt;?xml version="1.0" encoding="utf-8"?>
104130
&lt;strings xml:lang="en-US">

0 commit comments

Comments
 (0)