001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.forms.layout.io.plugins; 018 019import java.util.Map; 020 021import org.nuxeo.ecm.platform.forms.layout.api.WidgetDefinition; 022import org.nuxeo.ecm.platform.forms.layout.api.converters.AbstractWidgetDefinitionConverter; 023import org.nuxeo.ecm.platform.forms.layout.api.converters.LayoutConversionContext; 024import org.nuxeo.ecm.platform.forms.layout.io.plugins.helpers.TranslationHelper; 025 026/** 027 * Converter that replaces labels to translate by their translation in a given language. 028 * 029 * @since 5.5 030 */ 031public class WidgetLabeli18nConverter extends AbstractWidgetDefinitionConverter { 032 033 @Override 034 public WidgetDefinition getWidgetDefinition(WidgetDefinition orig, LayoutConversionContext ctx) { 035 String lang = ctx.getLanguage(); 036 if (orig.isTranslated() && lang != null) { 037 // translate widget labels 038 WidgetDefinition clone = getClonedWidget(orig); 039 Map<String, String> labels = TranslationHelper.getTranslatedLabels(clone.getLabels(), lang); 040 Map<String, String> helpLabels = TranslationHelper.getTranslatedLabels(clone.getHelpLabels(), lang); 041 clone.setLabels(labels); 042 clone.setHelpLabels(helpLabels); 043 return clone; 044 } 045 return orig; 046 } 047}