blob: eab37c193a19ee9a26f5adf0b6301852974ac61d [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.wizard.ui.basic;
import java.util.ResourceBundle;
import org.eclipse.osbp.xtext.basic.ui.BasicDSLDocumentationTranslator;
/**
* Documentation Translator for Wizard
*/
public class CommonProjectWizardTranslator extends BasicDSLDocumentationTranslator {
private static CommonProjectWizardTranslator INSTANCE = new CommonProjectWizardTranslator();
/**
* @return the one and only translator instance
*/
public static CommonProjectWizardTranslator instance() {
return INSTANCE;
}
private String getDocumentation(String key) {
String documentation;
documentation = getDocumentation(key, false);
if (documentation == null) {
String[] tokens = key.split("\\.");
String lastToken = tokens[tokens.length-1];
if ((tokens.length > 1) && (lastToken.equals(lastToken.toUpperCase()))) {
try {
documentation = getResourceBundle(lastToken).getString(key);
}
catch (Exception e) {}
}
}
if (documentation == null) {
documentation = key+" - missing translation or documentation";
}
return documentation;
}
public String getDocumentation(Class<?> clazz, String item) {
return getDocumentation(getTranslatorKey(clazz, item));
}
public String getDocumentation(Object object, String item) {
return getDocumentation(getTranslatorKey(object, item));
}
private ResourceBundle getResourceBundle(String key) {
return java.util.ResourceBundle.getBundle("i18n.I18N_"+key, getLocale(), getClass().getClassLoader());
}
@Override
protected ResourceBundle getResourceBundle() {
return java.util.ResourceBundle.getBundle("i18n.I18N", getLocale(), getClass().getClassLoader());
}
}