Skip to content

Commit 552d32a

Browse files
mawinter69krissterntimja
authored
Add documentation how to make plugins localizable (#408)
Co-authored-by: Kris Stern <krisstern@outlook.com> Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
1 parent f0a33cb commit 552d32a

File tree

12 files changed

+144
-0
lines changed

12 files changed

+144
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.jenkins.plugins.designlibrary;
2+
3+
import hudson.Extension;
4+
5+
@Extension
6+
public class Localization extends UISample {
7+
8+
@Override
9+
public String getIconFileName() {
10+
return "symbol-language-outline plugin-ionicons-api";
11+
}
12+
13+
@Override
14+
public String getDescription() {
15+
return Messages.Localization_description();
16+
}
17+
18+
public String getMessage() {
19+
return Messages.Localization_message();
20+
}
21+
22+
public String getGreet() {
23+
return Messages.Localization_greet("World");
24+
}
25+
26+
@Override
27+
public Category getCategory() {
28+
return Category.PATTERN;
29+
}
30+
31+
@Extension
32+
public static final class DescriptorImpl extends UISampleDescriptor {}
33+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
The MIT License
3+
4+
Copyright (c) 2025, Markus Winter
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
-->
24+
<?jelly escape-by-default='true'?>
25+
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:s="/lib/samples">
26+
<s:layout>
27+
<p class="jdl-paragraph jenkins-!-margin-bottom-3">${%leadParagraph}</p>
28+
<s:section title="${%titlejava}" description="${%howtojava}">
29+
<s:group>
30+
<s:preview fullWidth="true">
31+
<f:entry>
32+
${it.message}<br/>
33+
${it.greet}
34+
</f:entry>
35+
</s:preview>
36+
<s:code-panes>
37+
<s:code-pane title="Localize.java">
38+
<s:code language="java" file="Localize.java"/>
39+
</s:code-pane>
40+
<s:code-pane title="Messages.properties">
41+
<s:code file="Messages.properties"/>
42+
</s:code-pane>
43+
<s:code-pane title="Messages_de.properties">
44+
<s:code file="Messages_de.properties"/>
45+
</s:code-pane>
46+
</s:code-panes>
47+
</s:group>
48+
</s:section>
49+
<s:section title="${%titlejelly}" description="${%howtojelly}">
50+
<s:group>
51+
<s:preview fullWidth="true">
52+
<f:entry>
53+
${%How to localize texts in Jelly}<br/>
54+
${%longtext}<br/>
55+
${%hello('World')}
56+
</f:entry>
57+
</s:preview>
58+
<s:code-panes>
59+
<s:code-pane title="localize.jelly">
60+
<s:code file="localize.jelly"/>
61+
</s:code-pane>
62+
<s:code-pane title="localize.properties">
63+
<s:code file="localize.properties"/>
64+
</s:code-pane>
65+
<s:code-pane title="localize_de.properties">
66+
<s:code file="localize_de.properties"/>
67+
</s:code-pane>
68+
</s:code-panes>
69+
</s:group>
70+
</s:section>
71+
</s:layout>
72+
</j:jelly>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
titlejava=Localize text in Java
2+
howtojava=Create a file <em>Messages.properties</em> in the package folder. After compilation, the class Messages has corresponding methods for the texts.
3+
hello=Hello {0}
4+
titlejelly=Localize text in Jelly
5+
howtojelly=Use <em>$&#123;%Text}</em> to create texts that can be localized. Create a properties files for content longer than a few words.
6+
longtext=A longer text that should not appear inline in the jelly file.
7+
leadParagraph=A detailed explanation how to localize texts in Java and Jelly files can be found in the jenkins.io developer guide <a href="https://www.jenkins.io/doc/developer/internationalization/" target="_blank">Internationalization and Localization</a>.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
longtext=Ein längerer Text, der nicht inline in der Jelly-Datei erscheinen soll.
2+
hello=Hallo {0}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Localization.description=Ensures texts can be displayed in the user''s language.
2+
Localization.message=How to localize texts in Java
3+
Localization.greet=Hello {0}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Localization.description=Stellt sicher, dass Texte in der Sprache des Benutzers angezeigt werden können.
2+
Localization.message=So lokalisieren Sie Texte in Java
3+
Localization.greet=Hallo {0}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Localize {
2+
public String getMessage() {
3+
return Messages.Localize_message();
4+
}
5+
6+
public String getGreet() {
7+
return Messages.Localize_greet("World");
8+
}
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Localize.message=How to localize texts in Java
2+
Localize.greet=Hello {0}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Localize.message=So lokalisieren Sie Texte in Java
2+
Localize.greet=Hallo {0}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core">
3+
${%How to localize texts in Jelly}
4+
${%longtext}
5+
${%hello('World')}
6+
</j:jelly>

0 commit comments

Comments
 (0)