use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class GuiDebugDispatcherController method createInterceptComponentRenderer.
/*
* (non-Javadoc)
*
* @see org.olat.core.gui.render.debug.DebugHandler#createDebugComponentRenderer(org.olat.core.gui.components.ComponentRenderer)
*/
@Override
public ComponentRenderer createInterceptComponentRenderer(final ComponentRenderer originalRenderer) {
return new ComponentRenderer() {
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
if (debugURLBuilder != null && !DebugHelper.isProtected(source)) {
// remember source for later debug info access
String did = source.getDispatchID();
String didS = String.valueOf(did);
idToComponent.put(didS, source);
int lev = renderResult.getNestedLevel();
String cname = source.getClass().getName();
String cnameShort = cname.substring(cname.lastIndexOf('.') + 1);
// header before component
sb.append("<div class='o_dev_w'>");
sb.append("<div class='o_dev_h'><span id='o_guidebugst").append(did).append("' onmouseover=\"o_debu_show(this.parentNode.parentNode, jQuery('#o_guidebugtt").append(did).append("'))\">");
sb.append(source.getComponentName()).append(" (").append(cnameShort).append(")");
sb.append("</span></div>");
sb.append("<div class='o_dev_c'><div id='o_guidebugtt").append(did).append("' class='o_dev_i'>");
sb.append("Info: <b>").append(source.getComponentName()).append("</b> (" + cnameShort + ") id:");
sb.append(String.valueOf(source.getDispatchID())).append(" level:").append(lev);
Controller listC = Util.getListeningControllerFor(source);
if (listC != null) {
sb.append("<br /><b>controller:</b> <a target=\"_blank\" href=\"");
String controllerClassName = listC.getClass().getName();
debugURLBuilder.buildURI(sb, new String[] { "cid", "com", "class" }, new String[] { String.valueOf(did), "ojava", controllerClassName });
sb.append("\">");
sb.append(controllerClassName);
sb.append("</a>");
}
sb.append("<br /><i>listeners</i>: ");
if (!source.isEnabled()) {
sb.append(" NOT ENABLED");
}
String listeners = source.getListenerInfo();
sb.append(listeners);
if (!source.isVisible()) {
sb.append("<br />INVISIBLE");
}
sb.append("<br />");
// we must let the original renderer do its work so that the collecting translator is callbacked.
// we save the result in a new var since it is too early to append it to the 'stream' right now.
StringOutput sbOrig = new StringOutput();
try {
originalRenderer.render(renderer, sbOrig, source, ubu, translator, renderResult, args);
} catch (Exception e) {
String emsg = "exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage();
sbOrig.append("<span style=\"color:red\">Exception</span><br /><pre>" + emsg + "</pre>");
}
sb.append("</div>");
// add original component
sb.append(sbOrig);
sb.append("</div></div>");
} else {
// e.g. when the render process take place before the delegating
// component of this controller here was rendered.
// the delegating component should be placed near the <html> tag in
// order to be rendered first.
// the contentpane of the window and the first implementing container
// will not be provided with debug info, which is on purpose,
// since those are contents from the chiefcontroller which control the
// window.
// render original component
originalRenderer.render(renderer, sb, source, ubu, translator, renderResult, args);
}
}
@Override
public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
originalRenderer.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
}
@Override
public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
originalRenderer.renderBodyOnLoadJSFunctionCall(renderer, sb, source, rstate);
}
};
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class VelocityRenderDecorator method translateWithPackage.
/**
* Method to translate a key that comes from another package. This should be
* used rarely. When a key is used withing multiple packages is is usually
* better to use a fallback translator or to move the key to the default
* packages.
* <p>
* Used in context help system
* @param bundleName the package name, e.g. 'org.olat.core'
* @param key the key, e.g. 'my.key'
* @param args optional arguments, null if not used
* @return
*/
public String translateWithPackage(String bundleName, String key, String[] args) {
Translator pageTrans = renderer.getTranslator();
if (pageTrans == null)
return "{Translator is null: key_to_translate=" + key + "}";
Locale locale = pageTrans.getLocale();
Translator tempTrans = new PackageTranslator(bundleName, locale);
String result = tempTrans.translate(key, args);
if (result == null) {
return "{Invalid bundle name: " + bundleName + " and key: " + key + "}";
}
return result;
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class VelocityRenderDecorator method translate.
/**
* @param key
* @return
*/
public String translate(String key) {
Translator trans = renderer.getTranslator();
if (trans == null)
return "{Translator is null: key_to_translate=" + key + "}";
String res = trans.translate(key);
if (res == null)
return "?? key not found to translate: key_to_translate=" + key + " / trans info:" + trans + "}";
return res;
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class InlineTranslationInterceptHandlerController method createInterceptComponentRenderer.
public ComponentRenderer createInterceptComponentRenderer(final ComponentRenderer originalRenderer) {
return new ComponentRenderer() {
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
// ------------- show translator keys
// we must let the original renderer do its work so that the
// collecting translator is callbacked.
// we save the result in a new var since it is too early to
// append it
// to the 'stream' right now.
StringOutput sbOrig = new StringOutput();
try {
originalRenderer.render(renderer, sbOrig, source, ubu, translator, renderResult, args);
} catch (Exception e) {
String emsg = "exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage();
sbOrig.append("<span style=\"color:red\">Exception</span><br /><pre>" + emsg + "</pre>");
}
String rendered = sbOrig.toString();
String renderedWithHTMLMarkup = InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(rendered, inlineTranslationURLBuilder, getTranslator());
sb.append(renderedWithHTMLMarkup);
}
/**
* @see org.olat.core.gui.components.ComponentRenderer#renderHeaderIncludes(org.olat.core.gui.render.Renderer,
* org.olat.core.gui.render.StringOutput,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.render.URLBuilder,
* org.olat.core.gui.translator.Translator,
* org.olat.core.gui.render.RenderingState)
*/
@Override
public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
originalRenderer.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
}
/**
* @see org.olat.core.gui.components.ComponentRenderer#renderBodyOnLoadJSFunctionCall(org.olat.core.gui.render.Renderer,
* org.olat.core.gui.render.StringOutput,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.render.RenderingState)
*/
@Override
public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
originalRenderer.renderBodyOnLoadJSFunctionCall(renderer, sb, source, rstate);
}
};
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class MailHelper method getMailFooter.
/**
* Create a mail footer for the given locale and sender.
*
* @param locale Defines language of footer text. If null, the systems default
* locale is used
* @param sender Details about sender embedded in mail footer. If null no such
* details are attached to the footer
* @return The mail footer as string
*/
public static String getMailFooter(Locale locale, Identity sender) {
if (locale == null) {
locale = I18nModule.getDefaultLocale();
}
Translator trans = getTranslator(locale);
if (sender == null) {
// mail sent by plattform configured sender address
return trans.translate("footer.no.userdata", new String[] { Settings.getServerContextPathURI() });
}
// mail sent by a system user
User user = sender.getUser();
// FXOLAT-356: separate context for mail footer
// username / server-url are always first [0], [1].
UserManager um = UserManager.getInstance();
List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(MailHelper.class.getCanonicalName(), false);
List<String> userPropList = new ArrayList<String>(userPropertyHandlers.size() + 2);
String email = UserManager.getInstance().getUserDisplayEmail(sender, locale);
userPropList.add(email);
userPropList.add(Settings.getServerContextPathURI());
for (Iterator<UserPropertyHandler> iterator = userPropertyHandlers.iterator(); iterator.hasNext(); ) {
userPropList.add(iterator.next().getUserProperty(user, locale));
}
// add empty strings to prevent non-replaced wildcards like "{5}" etc. in emails.
while (userPropList.size() < 15) {
userPropList.add("");
}
String[] userPropArr = userPropList.toArray(new String[userPropList.size()]);
for (int i = userPropArr.length; i-- > 0; ) {
if (userPropArr[i] == null) {
userPropArr[i] = "";
}
}
return trans.translate("footer.with.userdata", userPropArr);
}
Aggregations