jaxx.compiler.I18nHelper Maven / Gradle / Ivy
/*
* #%L
* JAXX :: Compiler
*
* $Id: I18nHelper.java 2634 2013-03-18 08:34:23Z tchemit $
* $HeadURL: http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.21/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java $
* %%
* Copyright (C) 2008 - 2010 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package jaxx.compiler;
import jaxx.runtime.SwingUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.i18n.I18n;
import java.util.Arrays;
import java.util.List;
/**
* I18n methods to add {@link I18n#_(String, Object...)} method on some attributes.
*
* Make sure to set an i18nable compiler to have his {@link CompilerConfiguration#isI18nable()} returning true.
*
* @author tchemit
*/
public class I18nHelper {
protected static final Log log = LogFactory.getLog(I18nHelper.class);
public static final List I18N_ATTRIBUTES = Arrays.asList("text", "title", "toolTipText");
/**
* Test if we have an active i18n attribute (says an i18n attribute on a i18neable compiler).
*
* @param attributeName name of attribute to test
* @param compiler current used compiler (contains options)
* @return true
if wa have an active i18n attribute, false
otherwise.
*/
public static boolean isI18nableAttribute(String attributeName, JAXXCompiler compiler) {
return compiler.getConfiguration().isI18nable() && isI18nAttribute(attributeName);
}
/**
* Test if we have an i18n attribute.
*
* @param attributeName name of attribute to test
* @return true
if wa have an active i18n attribute, false
otherwise.
*/
public static boolean isI18nAttribute(String attributeName) {
return I18N_ATTRIBUTES.contains(attributeName);
}
/**
* Add the i18n on a attribute.
*
* Note: Be ware : no test is done here to ensure we are on a i18neable attribute for an i18nable compiler.
*
* Make sure with the method {@link I18nHelper#isI18nableAttribute(String, JAXXCompiler)} returns
* true
* Note: Be ware : no test is done here to ensure we are on a
* i18neable attribute for an i18nable compiler.
*
* @param object the object to use
* @param attributeName the name of the attribute
* @param attributeValueCode the value code of the attribute value
* @param compiler the current used compile
* @return the surrender i18n call if attribute name is match the
* attributeValueCode otherwise
* @since 2.6.11
*/
public static String addI18nMnemonicInvocation(CompiledObject object,
String attributeName,
String attributeValueCode,
JAXXCompiler compiler) {
String stringValue = I18nHelper.addI18nInvocation(
object.getId(),
attributeName,
attributeValueCode,
compiler);
compiler.addImport(SwingUtil.class.getName());
String result = "{" + SwingUtil.class.getSimpleName() +
".getFirstCharAt(" + stringValue + ",'Z')}";
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy