Hi,
For one of my projects, I needed a simple way of getting different
strings depending on the language that the user would want, so I patched
the org.apache.turbine.services.localization.Localization class to add a
method with the next signature:
getString (String string, String language)
Here's the patch, I think it doesn't break anything, and it's useful for
me at least (I hope lines don't get wrapped):
----------- START PATCH ---------------------
---
Apache-Turbine-20010120/src/java/org/apache/turbine/services/localization/Localization.java
Wed Aug 30 20:09:19 2000
+++
Apache-Turbine-20010120-ark/src/java/org/apache/turbine/services/localization/Localization.java
Sat Jan 20 22:04:22 2001
@@ -61,6 +61,7 @@
// Turbine stuff.
import org.apache.turbine.util.RunData;
+import org.apache.turbine.services.resources.TurbineResources;
import org.apache.turbine.services.*;
/**
@@ -126,6 +127,22 @@
.getService(LocalizationService.SERVICE_NAME))
.getBundle(data)
.getString ( str );
+ }
+
+ /**
+ * Convenience method that pulls a localized string off the
LocalizationService
+ * using the default ResourceBundle name defined in the
TurbineResources.properties
+ * file and the specified language name in ISO format.
+ *
+ * @param str Name of string.
+ * @param lang Desired language for the localized string.
+ * @return A localized string.
+ */
+
+ public static String getString (String str, String lang)
+ {
+ String bundleName =
TurbineResources.getString("locale.default.bundle", "");
+ return Localization.getBundle (bundleName, new Locale (lang,
"")).getString (str);
}
/**
-------------- END PATCH -------------------------------
Also, I fixed a small detail in TurbineLocalizationService:
---
Apache-Turbine-20010120/src/java/org/apache/turbine/services/localization/TurbineLocalizationService.java
Wed Aug 30 20:09:19 2000
+++
Apache-Turbine-20010120-ark/src/java/org/apache/turbine/services/localization/TurbineLocalizationService.java
Sat Jan 20 22:13:11 2001
@@ -229,12 +229,7 @@
locale);
// Cache the ResourceBundle in memory.
- locales.put( locale, rb );
-
- // Can't call getLocale(), because that is jdk2. This
- // needs to be changed back, since the above approach
- // caches extra Locale and Bundle objects.
- // locales.put( rb.getLocale(), rb );
+ locales.put( rb.getLocale(), rb );
return rb;
}
Thanks,
Arkaitz.
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]