play.i18n.MessagesPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of framework Show documentation
Show all versions of framework Show documentation
RePlay is a fork of the Play1 framework, created by Codeborne.
package play.i18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.Play;
import play.PlayPlugin;
import play.libs.IO;
import play.vfs.VirtualFile;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
public class MessagesPlugin extends PlayPlugin {
private static final Logger logger = LoggerFactory.getLogger(MessagesPlugin.class);
private static Long lastLoading = 0L;
private static final List includeMessageFilenames = new ArrayList<>();
@Override
public void onApplicationStart() {
includeMessageFilenames.clear();
Messages.defaults = new Properties();
for (VirtualFile module : Play.modules.values()) {
VirtualFile messages = module.child("conf/messages");
if (messages != null && messages.exists()
&& !messages.isDirectory()) {
Messages.defaults.putAll(read(messages));
}
}
VirtualFile appDM = Play.getVirtualFile("conf/messages");
if (appDM != null && appDM.exists() && !appDM.isDirectory()) {
Messages.defaults.putAll(read(appDM));
}
for (String locale : Play.langs) {
Properties properties = new Properties();
for (VirtualFile module : Play.modules.values()) {
VirtualFile messages = module.child("conf/messages." + locale);
if (messages != null && messages.exists()
&& !messages.isDirectory()) {
properties.putAll(read(messages));
}
}
VirtualFile appM = Play.getVirtualFile("conf/messages." + locale);
if (appM != null && appM.exists() && !appM.isDirectory()) {
properties.putAll(read(appM));
} else {
logger.warn("Messages file missing for locale {}", locale);
}
Messages.locales.put(locale, properties);
}
lastLoading = System.currentTimeMillis();
}
Properties read(VirtualFile vf) {
if (vf != null) {
return read(vf.getRealFile());
}
return null;
}
Properties read(File file) {
Properties propsFromFile = null;
if (file != null && !file.isDirectory()) {
propsFromFile = IO.readUtf8Properties(file);
// Include
Map