Implemented: Groovy DSL add label method
Improve the groovy dsl with a simple method 'label' to resolve an uiLabel instead of use 'UtilProperty.getMessage()' on groovy script.
Previously we used:
UtilProperties.getMessage("AccountingUiLabels", "AccountingUpdatePaymentPermissionError", 'locale'))
Now we can write:
label("AccountingUiLabels", "AccountingUpdatePaymentPermissionError")
package org.apache.ofbiz.service.engine
import org.apache.ofbiz.base.util.Debug
+import org.apache.ofbiz.base.util.UtilProperties
import org.apache.ofbiz.entity.util.EntityQuery
import org.apache.ofbiz.service.DispatchContext
import org.apache.ofbiz.service.LocalDispatcher
@@ -142,4 +143,18 @@ abstract class GroovyBaseScript extends Script {
def logVerbose(String message) {
Debug.logVerbose(message, getModule())
}
+
+ def label(String ressource, String message) {
+ return label(ressource, message, null)
+ }
+ def label(String ressource, String message, Map context) {
+ Locale locale = this.binding.getVariable('locale')
+ if (!locale) {
+ locale = Locale.getDefault()
+ }
+ if (context) {
+ return UtilProperties.getMessage(ressource, message, context, locale)
+ }
+ return UtilProperties.getMessage(ressource, message, locale)
+ }
}
