|
44 | 44 | <dd>Add new strings to generated text file. </dd> |
45 | 45 | </dlentry> |
46 | 46 | </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 | + ><?xml version="1.0" encoding="utf-8"?> |
| 58 | +<strings xml:lang="en-US"> |
| 59 | + <str name="String1">English generated text</str> |
| 60 | +</strings></codeblock> |
| 61 | + <codeblock |
| 62 | + outputclass="language-xml normalize-space show-line-numbers show-whitespace" |
| 63 | + ><?xml version="1.0" encoding="UTF-8"?> |
| 64 | +<vars xmlns="http://www.idiominc.com/opentopic/vars"> |
| 65 | + <variable id="String1">English generated text</variable> |
| 66 | +</vars></codeblock> |
| 67 | + </note> |
47 | 68 | </section> |
48 | 69 | <example> |
49 | 70 | <title>Example: adding new strings</title> |
50 | 71 | <p>First, copy the file <filepath>xsl/common/strings.xml</filepath> from the base plug-in directory |
51 | 72 | <filepath>plugins/org.dita.base</filepath> to your plug-in, and edit it to contain the languages that you are |
52 | 73 | 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 |
54 | 76 | outputclass="language-xml normalize-space show-line-numbers show-whitespace" |
55 | 77 | ><?xml version="1.0" encoding="utf-8"?> |
56 | 78 | <!-- Provide strings for my plug-in; this plug-in supports |
|
66 | 88 | <p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> from the base plug-in directory |
67 | 89 | <filepath>plugins/org.dita.base</filepath> to your plug-in, and replace the content with your own strings (be |
68 | 90 | 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 |
70 | 93 | outputclass="language-xml normalize-space show-line-numbers show-whitespace" |
71 | 94 | ><?xml version="1.0" encoding="utf-8"?> |
72 | 95 | <strings xml:lang="en-US"> |
73 | 96 | <str name="String1">English generated text</str> |
74 | 97 | <str name="Another String">Another String in English</str> |
75 | 98 | </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 |
77 | 101 | outputclass="language-xml normalize-space show-line-numbers show-whitespace" |
78 | 102 | ><plugin id="com.example.strings"> |
79 | 103 | <feature extension="dita.xsl.strings" file="xsl/my-new-strings.xml"/> |
80 | 104 | </plugin></codeblock> |
81 | 105 | <p>The string is now available to the "getVariable" template used in many DITA-OT XSLT files. For example, if |
82 | 106 | 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 |
84 | 109 | outputclass="language-xml normalize-space show-line-numbers show-whitespace" |
85 | 110 | ><xsl:call-template name="getVariable"> |
86 | 111 | <xsl:with-param name="id" select="'Another String'"/> |
|
93 | 118 | <title>Example: modifying existing strings</title> |
94 | 119 | <p>The process for modifying existing generated text is exactly the same as for adding new text, except that the |
95 | 120 | 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> |
97 | 122 | <p>Next, copy the file <filepath>xsl/common/strings-en-us.xml</filepath> from the base plug-in directory |
98 | 123 | <filepath>plugins/org.dita.base</filepath> to your plug-in, and choose the strings you wish to change (be sure |
99 | 124 | to leave the name attribute unchanged, because this is the key used to look up the string). Create a strings |
100 | 125 | 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 |
102 | 128 | outputclass="language-xml normalize-space show-line-numbers show-whitespace" |
103 | 129 | ><?xml version="1.0" encoding="utf-8"?> |
104 | 130 | <strings xml:lang="en-US"> |
|
0 commit comments