| name | ofbiz-plugins |
| description | This skill covers localization techniques in OFBiz that go beyond standard UI labels, focusing on data formatting and locale-aware logic. Use when this capability is needed. |
| metadata | {"author":"apache"} |
name: manage-localization-advanced
description: Manage advanced localization in OFBiz, including date/time formatting, currency conversion, and locale-specific data handling beyond simple labels.
Manage Localization Advanced Skill
This skill covers localization techniques in OFBiz that go beyond standard UI labels, focusing on data formatting and locale-aware logic.
Date and Time Localization
Use UtilDateTime for date arithmetic and locale-specific date retrieval.
Pattern: Formatting Dates
String formattedDate = UtilFormatOut.formatDate(myDate, "yyyy-MM-dd", locale, timeZone);
String formattedDateTime = UtilFormatOut.formatDateTime(myTimestamp, "yyyy-MM-dd HH:mm", locale, timeZone);
Pattern: Date Arithmetic
Timestamp monthStart = UtilDateTime.getMonthStart(nowTimestamp, timeZone, locale);
Timestamp weekLater = UtilDateTime.addDaysToTimestamp(nowTimestamp, 7);
Currency and Number Formatting
Use UtilFormatOut and UtilNumber for currency and numeric formatting.
Pattern: Formatting Currency
String priceStr = UtilFormatOut.formatCurrency(priceBigDecimal, "USD", locale);
String percentStr = UtilFormatOut.formatPercentage(discountDouble);
UOM (Unit of Measure) System
OFBiz uses the Uom and UomConversion entities for units of measure and currency conversion.
Pattern: Currency Conversion
Map<String, Object> results = dispatcher.runSync("convertUom", UtilMisc.toMap(
"uomId", "USD",
"uomIdTo", "EUR",
"originalValue", priceAmount
));
BigDecimal convertedValue = (BigDecimal) results.get("convertedValue");
Localized Data Storage
For properties stored in the database (e.g., system settings), use EntityUtilProperties.
Pattern: Localized DB Properties
<SystemProperty systemResourceId="general" systemPropertyId="currency.uom.id.default" systemPropertyValue="USD"/>
String currencyId = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", delegator);
Best Practices
- Always Pass Locale/TimeZone: Never rely on
Locale.getDefault() or TimeZone.getDefault() in multi-user web applications; always use the user's session locale and timezone.
- Use UOM Entities: Prefer the
Uom system for dimensions, weights, and currencies rather than hardcoding units.
- Handle GMT: Use
UtilDateTime.toGmtTimestampString() for logging or external API integrations that require a standard time representation.
- Prefer UtilFormatOut: Use the utility classes for formatting to ensure consistency across the application.
Source: apache/ofbiz-plugins — distributed by TomeVault.