Search in sources :

Example 1 with TemplateEngine

use of org.terasology.engine.persistence.TemplateEngine in project Terasology by MovingBlocks.

the class TranslationSystemImpl method translate.

@Override
public String translate(String text, Locale otherLocale) {
    TemplateEngine templateEngine = new TemplateEngineImpl(id -> {
        ResourceUrn uri = new ResourceUrn(id);
        ResourceUrn projectUri = new ResourceUrn(uri.getModuleName(), uri.getResourceName());
        TranslationProject project = getProject(projectUri);
        if (project != null) {
            Optional<String> opt = project.translate(uri.getFragmentName(), otherLocale);
            if (opt.isPresent()) {
                return opt.get();
            } else {
                logger.warn("No translation for '{}'", id);
                return "?" + uri.getFragmentName() + "?";
            }
        } else {
            logger.warn("Invalid project id '{}'", id);
            return "?" + uri.getFragmentName() + "?";
        }
    });
    return templateEngine.transform(text);
}
Also used : TemplateEngine(org.terasology.engine.persistence.TemplateEngine) TemplateEngineImpl(org.terasology.engine.persistence.TemplateEngineImpl) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Aggregations

TemplateEngine (org.terasology.engine.persistence.TemplateEngine)1 TemplateEngineImpl (org.terasology.engine.persistence.TemplateEngineImpl)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1