java - How to store data from ResourceBundle's and switch fast between them? -
my server program supports several languages. know user language, needed phrase through map, initialized on starting hardcoded data. source sample:
public class dictionary { private static map<string, map<string, string>> map = new hashmap<>(); static { map.put("stats", new hashmap<>()); map<string, string> stats = map.get("stats"); stats.put("en", "stats"); stats.put("ru", "Статистика"); stats.put("hi", "आँकड़े दिखाएँ"); stats.put("ar", "احصاء"); stats.put("zh", "游戏统计"); stats.put("es", "estadística"); stats.put("pt", "estatísticas"); stats.put("it", "statistiche"); } public static string getstats(string lang) { return map.get("stats").get(lang); } }
i found out java provides resourcebundle. how can rewrite code technology considering must fast current way, i.e. store data in memory, not access everytime?
update: i've tried same way resourcebundle:
public class superdictionary { private static map<string, resourcebundle> dictionary = new hashmap<>(); static { dictionary.put("en", resourcebundle.getbundle("dictionary", new locale("en"))); dictionary.put("es", resourcebundle.getbundle("dictionary", new locale("es"))); } public static string getstats(string language) { return dictionary.get(language).getstring("stats"); } }
is best solution?
Comments
Post a Comment