All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickntap.developers.MessageSource Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package com.clickntap.developers;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.io.FileUtils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class MessageSource {
	private Map> languages;

	public Map> getLanguages() {
		return languages;
	}

	public void setLanguages(Map> languages) {
		this.languages = languages;
	}

	public MessageSource() {

	}

	public MessageSource(String messageProperties, String locale) throws Exception {
		Properties p = new Properties();
		InputStream in = new FileInputStream(messageProperties);
		p.load(in);
		in.close();
		HashMap values = new HashMap();
		for (Object key : p.keySet()) {
			values.put(key.toString(), p.getProperty(key.toString()));
		}
		languages = new HashMap>();
		languages.put(locale, values);
	}

	public void export(String messagesJson) throws IOException {
		GsonBuilder builder = new GsonBuilder();
		builder.setPrettyPrinting();
		Gson gson = builder.create();
		String json = gson.toJson(this);
		FileUtils.writeStringToFile(new File(messagesJson), json);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy