use of enums.Language in project KaellyBot by Kaysoro.
the class Translator method detectLanguage.
public static Language detectLanguage(IChannel channel) {
Language result = Constants.defaultLanguage;
Map<Language, Integer> languages = new HashMap<>();
for (Language lang : Language.values()) languages.put(lang, 0);
languages.put(null, 0);
List<String> sources = getReformatedMessages(channel);
for (String source : sources) {
Language lg = getLanguageFrom(source);
languages.put(lg, languages.get(lg) + 1);
}
Map.Entry<Language, Integer> better = null;
for (Map.Entry<Language, Integer> chosenLanguage : languages.entrySet()) {
if (better == null)
better = chosenLanguage;
if (better.getValue() < chosenLanguage.getValue())
better = chosenLanguage;
}
try {
if (better.getKey() != null)
return better.getKey();
} catch (NullPointerException e) {
LoggerFactory.getLogger(Translator.class).warn("Translator.detectLanguage", e);
}
return result;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class Translator method getLanguageFrom.
public static Language getLanguageFrom(IChannel channel) {
Language result = Constants.defaultLanguage;
if (!channel.isPrivate()) {
Guild guild = Guild.getGuild(channel.getGuild());
result = guild.getLanguage();
ChannelLanguage channelLanguage = ChannelLanguage.getChannelLanguages().get(channel.getLongID());
if (channelLanguage != null)
result = channelLanguage.getLang();
}
return result;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class Translator method getLanguageFrom.
public static Language getLanguageFrom(String source) {
TextObject textObject = CommonTextObjectFactories.forDetectingOnLargeText().forText(source);
Optional<LdLocale> lang = getLanguageDetector().detect(textObject);
if (lang.isPresent())
for (Language lg : Language.values()) if (lang.get().getLanguage().equals(lg.getAbrev().toLowerCase()))
return lg;
return null;
}
Aggregations