Search in sources :

Example 1 with TemplateEngine

use of org.terasology.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);
        SimpleUri projectUri = new SimpleUri(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.persistence.TemplateEngine) TemplateEngineImpl(org.terasology.persistence.TemplateEngineImpl) SimpleUri(org.terasology.engine.SimpleUri) ResourceUrn(org.terasology.assets.ResourceUrn)

Aggregations

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