package eu.univento.commons.player.language; import com.zaxxer.sansorm.OrmElf; import com.zaxxer.sansorm.SqlClosure; import eu.univento.commons.Commons; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Locale; /** * @author joethei * @version 2.0 */ //TODO: optimize public class Language { private HashMap translations; public Language(Locale locale) { translations = new HashMap<>(); try { List translationList = new SqlClosure>() { public List execute(Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement("SELECT * FROM translations;"); return OrmElf.statementToList(statement, Translation.class); } }.execute(Commons.getCommons().getDatabaseManager().getMySQL().getConnection()); for(Translation translation : translationList) { translations.put(translation.getIdentifier(), translation.getTranslation(locale)); } } catch (SQLException e) { e.printStackTrace(); } } public String getWord(String keyword) { return translations.get(keyword); } public String getMessage(MessageConstant constant) { return translations.get(constant.getName()); } }