com.mitchellbosecke.pebble.extension.i18n.i18nFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pebble Show documentation
Show all versions of pebble Show documentation
Templating engine for Java.
/*******************************************************************************
* This file is part of Pebble.
*
* Copyright (c) 2014 by Mitchell Bösecke
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
******************************************************************************/
package com.mitchellbosecke.pebble.extension.i18n;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import com.mitchellbosecke.pebble.extension.Function;
import com.mitchellbosecke.pebble.template.EvaluationContext;
public class i18nFunction implements Function {
@Override
public List getArgumentNames() {
List names = new ArrayList<>();
names.add("bundle");
names.add("key");
return names;
}
@Override
public Object execute(Map args) {
String basename = (String) args.get("bundle");
String key = (String) args.get("key");
EvaluationContext context = (EvaluationContext) args.get("_context");
Locale locale = context.getLocale();
ResourceBundle bundle = ResourceBundle.getBundle(basename, locale);
return bundle.getObject(key);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy