<commit_before>package edu.one.core.infra;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.vertx.java.core.Vertx;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.platform.Container;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;


/*
 * Dummy implementation
 */
public class I18n {

	private Logger log;
	private final static String messagesDir = "./i18n";
	private final static Locale defaultLocale = Locale.FRENCH;
	private Map<Locale, JsonObject> messages = new HashMap<>();

	private I18n(){}

	private static class I18nHolder {
		private static final I18n instance = new I18n();
	}

	public static I18n getInstance() {
		return I18nHolder.instance;
	}

	public void init(Container container, Vertx vertx) {
		try {
			log = container.logger();
			for(String path : vertx.fileSystem().readDirSync(messagesDir)) {
				Locale l = Locale.forLanguageTag(new File(path).getName().split("\\.")[0]);
				JsonObject jo = new JsonObject(vertx.fileSystem().readFileSync(path).toString());
				messages.put(l,jo);
			}

			for (Locale l : messages.keySet()) {
				InputStream in = this.getClass().
						getResourceAsStream("/i18n/" + l.getLanguage() + ".utils.json");
				if (in != null) {
					String i18n = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8));
					JsonObject jo = new JsonObject(i18n);
					JsonObject j = messages.get(l);
					if (j == null) {
						messages.put(l,jo);
					} else {
						messages.put(l, jo.mergeIn(j));
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
	}

	public String translate(String key, String acceptLanguage) {
		return translate(key, getLocale(acceptLanguage));
	}
	public String translate(String key, Locale locale) {<commit_msg>prevent fileNotFoundException in I18n initialization<commit_after>package edu.one.core.infra;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.vertx.java.core.Vertx;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.platform.Container;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;


/*
 * Dummy implementation
 */
public class I18n {

	private Logger log;
	private final static String messagesDir = "./i18n";
	private final static Locale defaultLocale = Locale.FRENCH;
	private Map<Locale, JsonObject> messages = new HashMap<>();

	private I18n(){}

	private static class I18nHolder {
		private static final I18n instance = new I18n();
	}

	public static I18n getInstance() {
		return I18nHolder.instance;
	}

	public void init(Container container, Vertx vertx) {
		try {
			log = container.logger();
			if (vertx.fileSystem().existsSync(messagesDir)) {
				for(String path : vertx.fileSystem().readDirSync(messagesDir)) {
					Locale l = Locale.forLanguageTag(new File(path).getName().split("\\.")[0]);
					JsonObject jo = new JsonObject(vertx.fileSystem().readFileSync(path).toString());
					messages.put(l,jo);
				}
			} else {
				log.warn("I18n directory " + messagesDir + " doesn't exist.");
			}

			for (Locale l : messages.keySet()) {
				InputStream in = this.getClass().
						getResourceAsStream("/i18n/" + l.getLanguage() + ".utils.json");
				if (in != null) {
					String i18n = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8));
					JsonObject jo = new JsonObject(i18n);
					JsonObject j = messages.get(l);
					if (j == null) {
						messages.put(l,jo);
					} else {
						messages.put(l, jo.mergeIn(j));
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
	}

	public String translate(String key, String acceptLanguage) {
		return translate(key, getLocale(acceptLanguage));
	}
	public String translate(String key, Locale locale) {
{'fraction_non_alphanumeric': 0.13457303645705898, 'fraction_numerical': 0.012723268901394667, 'mean_word_length': 3.884109916367981, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '401878', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1311, 'n_words': 300}