Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Dec 15, 2015
1 parent 38a91c0 commit 99605f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/logic/l10n/Encodings.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Encodings {
static {
List<Charset> encodingsList = Charset.availableCharsets().values().stream().distinct()
.collect(Collectors.toList());
List<String> encodingsStringList = encodingsList.stream().map(c -> c.displayName()).distinct()
List<String> encodingsStringList = encodingsList.stream().map(Charset::displayName).distinct()
.collect(Collectors.toList());
ENCODINGS = encodingsList.toArray(new Charset[encodingsList.size()]);
ENCODINGS_DISPLAYNAMES = encodingsStringList.toArray(new String[encodingsStringList.size()]);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/sf/jabref/logic/l10n/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public static void setLanguage(String language) {
new EncodingControl(StandardCharsets.UTF_8));

// silent fallback to system locale when bundle is not found
if (!messages.getLocale().equals(locale)) {
if (!messages.getLocale().equals(locale) && !menuTitles.getLocale().equals(locale)) {
LOGGER.warn("Bundle for locale <" + locale + "> not found. Falling back to system locale <" + defaultLocale + ">");
locale = defaultLocale;
}
} catch (MissingResourceException e) {
LOGGER.warn("Bundle for locale <" + locale + "> not found. Fallback to system locale <" + defaultLocale
Expand Down Expand Up @@ -71,12 +72,11 @@ private static String translate(ResourceBundle resBundle, String idForErrorMessa
translation = key;
}

// replace %0, %1, ...
if ((translation != null) && !translation.isEmpty()) {
// also done if no params are given
return new LocalizationKeyParams(translation, params).replacePlaceholders();
if (translation == null || translation.isEmpty()) {
return key;
}
return key;

return new LocalizationKeyParams(translation, params).replacePlaceholders();
}

public static String lang(String key, String... params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public void testReplacePlaceholders() throws Exception {
assertEquals("What \n : %e %c a b", new LocalizationKeyParams("What \n : %e %c_%0 %1", "a", "b").replacePlaceholders());
}

@Test(expected = IllegalStateException.class)
public void testTooManyParams() {
new LocalizationKeyParams("", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class LocalizationKeyTest {

@Test
public void testConversionToPropertiesKey() {
assertEquals("test_\\:_\\=", new LocalizationKey("test : =").getPropertiesKey());
LocalizationKey localizationKey = new LocalizationKey("test : =");
assertEquals("test_\\:_\\=", localizationKey.getPropertiesKey());
assertEquals("test_:_=", localizationKey.getPropertiesKeyUnescaped());
assertEquals("test : =", localizationKey.getTranslationValue());
}

}

0 comments on commit 99605f1

Please sign in to comment.