-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
PropertyResourceBundle
for localization (#357)
Co-authored-by: Basil Crow <[email protected]> Co-authored-by: Jesse Glick <[email protected]>
- Loading branch information
1 parent
2c1c07b
commit 3b5035c
Showing
7 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
jelly/src/test/java/org/kohsuke/stapler/jelly/ResourceBundleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.kohsuke.stapler.jelly; | ||
|
||
import hudson.util.VersionNumber; | ||
import io.jenkins.lib.versionnumber.JavaSpecificationVersion; | ||
import java.net.URL; | ||
import java.util.Locale; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assume.assumeThat; | ||
|
||
public class ResourceBundleTest { | ||
|
||
private static final URL RESOURCE_BUNDLE = ResourceBundleTest.class.getResource("/org/kohsuke/stapler/jelly/ResourceBundleTest/index.properties"); | ||
private static final String FILE_PATH = RESOURCE_BUNDLE.toExternalForm().replace(".properties", ""); | ||
private static final ResourceBundle resourceBundle = new ResourceBundle(FILE_PATH); | ||
|
||
@Test | ||
public void format() { | ||
String helloWorld = resourceBundle.format(Locale.ENGLISH, "hello_world"); | ||
|
||
assertThat(helloWorld, is("Hello, World!")); | ||
} | ||
|
||
@Test | ||
public void formatFallsBackToDefaultIfMissing() { | ||
String helloWorld = resourceBundle.format(Locale.FRANCE, "hello_world"); | ||
|
||
assertThat(helloWorld, is("Hello, World!")); | ||
} | ||
|
||
@Test | ||
public void formatLocaleOverrideInPlace() { | ||
String helloWorld = resourceBundle.format(Locale.CANADA, "hello_world"); | ||
|
||
assertThat(helloWorld, is("Welcome, World!")); | ||
} | ||
|
||
@Test | ||
public void formatLocaleNonISO_8859_1() { | ||
String helloWorld = resourceBundle.format(Locale.CHINA, "hello_world"); | ||
|
||
assertThat(helloWorld, is("你好,世界!简化")); | ||
} | ||
|
||
@Test | ||
public void formatLocaleNonISO_8859_1_encoded_with_utf8() { | ||
assumeThat("Requires Java 9+", true, is(JavaSpecificationVersion.forCurrentJVM() | ||
.isNewerThan(new VersionNumber("8")) | ||
)); | ||
String helloWorld = resourceBundle.format(Locale.TRADITIONAL_CHINESE, "hello_world"); | ||
|
||
assertThat(helloWorld, is("你好世界!")); | ||
} | ||
|
||
@Test | ||
public void formatLocaleISO_8859_1_high_range_character_invalid_utf_8() { | ||
String helloWorld = resourceBundle.format(Locale.FRANCE, "french"); | ||
|
||
assertThat(helloWorld, is("Français")); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
jelly/src/test/resources/org/kohsuke/stapler/jelly/ResourceBundleTest/index.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_world=Hello, World! |
1 change: 1 addition & 0 deletions
1
jelly/src/test/resources/org/kohsuke/stapler/jelly/ResourceBundleTest/index_en_CA.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_world=Welcome, World! |
1 change: 1 addition & 0 deletions
1
jelly/src/test/resources/org/kohsuke/stapler/jelly/ResourceBundleTest/index_fr_FR.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
french=Fran�ais |
1 change: 1 addition & 0 deletions
1
jelly/src/test/resources/org/kohsuke/stapler/jelly/ResourceBundleTest/index_zh_CN.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_world=\u4f60\u597d\uff0c\u4e16\u754c\uff01\u7b80\u5316 |
1 change: 1 addition & 0 deletions
1
jelly/src/test/resources/org/kohsuke/stapler/jelly/ResourceBundleTest/index_zh_TW.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_world=你好世界! |