Go AVDN
Display Localized Name/Desc

We have designed our solution of the demo app as:

To associate localizable information to Java packages and classes is by fetching these information as metadata from a MetaBundle associated with the package or class in question.

Now let's see it in practice.

The core code to fetch the internationalized annotations are these methods:

public String getLocalizedClassName(String className)
{
   MetaBundle meta = MetaBundle.get(className);
   try
   {
      return meta.getString("class/@name", locale);
   }
   catch (MetaNotFoundException e)
   {
   }
   return "Class Not Localized";
}

public String getLocalizedClassDescription(String className)
{
   MetaBundle meta = MetaBundle.get(className);
   try
   {
      return meta.getString("class/description", locale);
   }
   catch (MetaNotFoundException e)
   {
   }
   return "Class Not Localized";
}

public String getLocalizedPackageName(String packageName)
{
   MetaBundle meta = MetaBundle.get(packageName);
   try
   {
      return meta.getString("package/@name", locale);
   }
   catch (MetaNotFoundException e)
   {
   }
   return "Package Not Localized";
}

public String getLocalizedPackageDescription(String packageName)
{
   MetaBundle meta = MetaBundle.get(packageName);
   try
   {
      return meta.getString("package/description", locale);
   }
   catch (MetaNotFoundException e)
   {
   }
   return "Package Not Localized";
}

This snippet is from tutor/meta/Brief.java

How these methods are invoked and how text obtained from them are displayed onto the UI is left for the reader to find out from within tutor/meta/Brief.java.

-~----------~----~----~----~------~----~------~--~-----~--~----~--------

All MetaBundles annotating Java classes or packages shipped with the demo source are listed below, followed by the XML files authored for them respectively.

MetaBundle java with XML files:
java.meta
java_zh.meta
MetaBundle java.awt with XML files:
java/awt.meta
java/awt_zh.meta
MetaBundle java.awt.Frame with XML files:
java/awt/Frame.meta
MetaBundle java.lang with XML files:
java/lang.meta
java/lang_zh.meta
MetaBundle java.lang.Error with XML files:
java/lang/Error.meta
MetaBundle java.lang.Exception with XML files:
java/lang/Exception.meta
MetaBundle java.lang.Object with XML files:
java/lang/Object.meta
java/lang/Object_zh.meta
MetaBundle java.lang.RuntimeException with XML files:
java/lang/RuntimeException.meta
MetaBundle java.net.URI with XML files:
java/net/URI.meta
MetaBundle java.net.URL with XML files:
java/net/URL.meta
MetaBundle java.util with XML files:
java/util.meta
java/util_zh.meta
MetaBundle java.util.HashMap with XML files:
java/util/HashMap.meta
MetaBundle java.util.Hashtable with XML files:
java/util/Hashtable.meta
MetaBundle java.util.WeakHashMap with XML files:
java/util/WeakHashMap.meta
MetaBundle javax with XML files:
javax.meta
javax_zh.meta
MetaBundle javax.swing.JFrame with XML files:
javax/swing/JFrame.meta
MetaBundle org.w3c with XML files:
org/w3c.meta
MetaBundle org.xml with XML files:
org/xml.meta

This is all the demo app has for annotations of Java classes and packages. Far from sufficient? Sure, we all think so. Well, you'd see it's easy enough to extend this set of MetaBundles, just write more XML files, and you are able to see your contribution immediately on the Demo App's window by pressing [Reload MetaBundles] there.