Example #1
0
 /** used to test */
 public static void main(String[] args) {
   if (args.length < 1) {
     System.out.println("Need at least one arg as the key to the resource bundle, then params");
   }
   List params = new LinkedList();
   for (int k = 1; k < args.length; k++) params.add(args[k]);
   GetText gt1 = new GetText();
   GetText gt2 = new GetText();
   gt1.loadResource();
   System.out.println("bundle: " + gt1.getBundleName());
   try {
     String text = gt1.text(args[0]);
     String cnv = gt1.convert(args[0], "alttext", params);
     System.out.println("text: " + text);
     System.out.println("converted: " + cnv);
   } catch (MissingResourceException e) {
     System.err.println(
         "Can't find resource for bundle " + gt1.getBundleName() + ", key " + args[0]);
   }
   // let's try another
   gt2.setLocale(Locale.GERMAN);
   gt2.loadResource();
   System.out.println("bundle: " + gt2.getBundleName());
   try {
     String text = gt2.text(args[0]);
     String cnv = gt2.convert(args[0], "alttext", params);
     System.out.println("text: " + text);
     System.out.println("converted: " + cnv);
   } catch (MissingResourceException e) {
     System.err.println(
         "Can't find resource for bundle " + gt2.getBundleName() + ", key " + args[0]);
   }
 }
Example #2
0
 /**
  * <br>
  * <em>Purpose:</em> get the text from the resource bundle, but if not found, return key <br>
  * <em>State Read:</em> textResources.getString(resourceKey) <br>
  * <em>Assumptions:</em> resource bundle is lazily loaded if not already loaded
  *
  * @param resourceKey, String
  * @return String, translated, but if not found, return the key
  */
 public String translate(String resourceKey) {
   try {
     if (textResources == null) loadResource();
     String resource = textResources.getString(resourceKey);
     return resource;
   } catch (MissingResourceException e) {
     return resourceKey;
   }
 }
Example #3
0
 /**
  * <br>
  * <em>Purpose:</em> get the text from the resource bundle <br>
  * <em>State Read:</em> textResources.getString(resourceKey) <br>
  * <em>Assumptions:</em> resource bundle is lazily loaded if not already loaded
  *
  * @param resourceKey, String
  * @return String
  * @exception MissingResourceException
  */
 public String text(String resourceKey) throws MissingResourceException {
   if (textResources == null) loadResource();
   String resource = textResources.getString(resourceKey);
   return resource;
 }