+package net.frustratedfunctor;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import org.jsoup.Jsoup;
+
+import java.net.URI;
+import java.util.ArrayList;
+
+@ApplicationScoped
+public class WordTranslationService {
+
+ public WordDefinition translate(String word) throws Exception {
+ if (word == null || word.isEmpty()) {
+ throw new InvalidWordException("The word cannot be empty");
+ }
+
+ final var larousseUrl = URI.create("https://www.larousse.fr/dictionnaires/francais-anglais/" + word).toURL();
+ final var doc = Jsoup.parse(larousseUrl, 10_000);
+
+ final var defs = doc.select("li.itemZONESEM");
+ final var wordDefs = new ArrayList<String>();
+
+ for (final var def : defs) {
+ final var translation = def.selectFirst("span.Traduction");
+ if (translation != null) {
+ wordDefs.add(translation.text());
+ }
+ }
+
+ return new WordDefinition(
+ word,
+ wordDefs
+ );
+ }
+
+}