Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
- Add setBundle() to R in order to manually set the ResourceBundle
- Update R.get() to handle MissingResourceException by using printing "key:param1:...:paramN"
  • Loading branch information
Matt David committed Sep 5, 2016
commit 702bab666958a7cb11c0e41a76149e0a55a968e5
25 changes: 23 additions & 2 deletions src/main/java/org/jitsi/dnssec/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.jitsi.dnssec;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
Expand All @@ -22,13 +23,33 @@ public final class R {
private R() {
}

/**
* Programmatically set the ResourceBundle to be used.
*
* @param rb ResourceBundle to Be Used.
*/
public static void setBundle(ResourceBundle rb) {
R.rb = rb;
}

/**
* Gets a translated message.
* @param key The message key to retrieve.
*
* @param key The message key to retrieve.
* @param values The values that fill placeholders in the message.
* @return The formatted message.
*/
public static String get(String key, Object... values) {
return MessageFormat.format(rb.getString(key), values);
try {
return MessageFormat.format(rb.getString(key), values);
}
catch (MissingResourceException e) {
StringBuilder sb = new StringBuilder(key);
for (Object val : values) {
sb.append(":");
sb.append(val.toString());
}
return sb.toString();
}
}
}