Règles des systèmes en deux langues ; import de campagne dans la langue de l'UI
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 35s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 50s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m26s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 35s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 50s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m26s
- Règles d'un système de jeu stockées en français et en anglais (migration V28, rules_markdown_en). L'import d'un PDF garde l'extraction fidèle dans la langue du livre (détectée) et traduit section par section vers l'autre langue, noms propres conservés ; la progression de la traduction s'affiche. Un échec de traduction n'annule pas l'import. - Éditeur du système : onglets Français / English ; l'import remplit les deux. Règles en séance et contexte de l'IA : version de la langue de l'interface, avec repli sur l'autre si elle est vide. - Import de campagne : textes rédigés (ou traduits) dans la langue de l'interface ; titres et noms propres conservés tels quels ; arc par défaut nommé dans la bonne langue. - Les règles anglaises suivent l'export/import de sauvegarde. Vérifié : brain (détection, découpe, traduction, flux d'import, langue de l'import de campagne), core clean verify (1299 tests), web build + vitest + lint. Traduction non essayée avec un vrai modèle.
This commit is contained in:
+6
-2
@@ -1,6 +1,7 @@
|
||||
package com.loremind.application.gamesystemcontext;
|
||||
|
||||
import com.loremind.domain.gamesystemcontext.GameSystem;
|
||||
import com.loremind.domain.shared.ports.CurrentLanguage;
|
||||
import com.loremind.domain.gamesystemcontext.GenerationIntent;
|
||||
import com.loremind.domain.gamesystemcontext.ports.GameSystemRepository;
|
||||
import com.loremind.domain.generationcontext.GameSystemContext;
|
||||
@@ -36,9 +37,11 @@ public class GameSystemContextBuilder {
|
||||
private static final Pattern H2_HEADER = Pattern.compile("(?m)^##\\s+(\\S.*)$");
|
||||
|
||||
private final GameSystemRepository gameSystemRepository;
|
||||
private final CurrentLanguage currentLanguage;
|
||||
|
||||
public GameSystemContextBuilder(GameSystemRepository gameSystemRepository) {
|
||||
public GameSystemContextBuilder(GameSystemRepository gameSystemRepository, CurrentLanguage currentLanguage) {
|
||||
this.gameSystemRepository = gameSystemRepository;
|
||||
this.currentLanguage = currentLanguage;
|
||||
}
|
||||
|
||||
public Optional<GameSystemContext> buildOptional(String gameSystemId, GenerationIntent intent) {
|
||||
@@ -48,7 +51,8 @@ public class GameSystemContextBuilder {
|
||||
}
|
||||
|
||||
private GameSystemContext build(GameSystem gs, GenerationIntent intent) {
|
||||
Map<String, String> allSections = parseH2Sections(gs.getRulesMarkdown());
|
||||
// Règles dans la langue de l'interface (repli sur l'autre version si celle-ci est vide).
|
||||
Map<String, String> allSections = parseH2Sections(gs.rulesFor(currentLanguage.get()));
|
||||
Map<String, String> filtered = filterByIntent(allSections, intent);
|
||||
return new GameSystemContext(gs.getName(), gs.getDescription(), filtered);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class GameSystemService {
|
||||
String name,
|
||||
String description,
|
||||
String rulesMarkdown,
|
||||
String rulesMarkdownEn,
|
||||
List<TemplateField> characterTemplate,
|
||||
List<TemplateField> npcTemplate,
|
||||
List<TemplateField> enemyTemplate,
|
||||
@@ -72,6 +73,7 @@ public class GameSystemService {
|
||||
.name(data.name())
|
||||
.description(data.description())
|
||||
.rulesMarkdown(data.rulesMarkdown())
|
||||
.rulesMarkdownEn(data.rulesMarkdownEn())
|
||||
.foundryActorType(normalize(data.foundryActorType()))
|
||||
.author(normalize(data.author()))
|
||||
.isPublic(data.isPublic())
|
||||
@@ -96,6 +98,7 @@ public class GameSystemService {
|
||||
existing.setName(data.name());
|
||||
existing.setDescription(data.description());
|
||||
existing.setRulesMarkdown(data.rulesMarkdown());
|
||||
existing.setRulesMarkdownEn(data.rulesMarkdownEn());
|
||||
existing.replaceCharacterTemplate(data.characterTemplate());
|
||||
existing.replaceNpcTemplate(data.npcTemplate());
|
||||
existing.replaceEnemyTemplate(data.enemyTemplate());
|
||||
|
||||
@@ -35,6 +35,9 @@ public class GameSystem {
|
||||
/** Markdown monolithique. Sections découpées par titres H2 (## Combat, ## Classes, etc.). */
|
||||
private String rulesMarkdown;
|
||||
|
||||
/** Version anglaise des règles ({@code rulesMarkdown} = version française). Nullable. */
|
||||
private String rulesMarkdownEn;
|
||||
|
||||
/**
|
||||
* Template de fiche PJ : champs typés affichés pour chaque personnage joueur.
|
||||
* Hors champs universels hard-codés (nom, portrait, header). Jamais null après
|
||||
@@ -161,4 +164,15 @@ public class GameSystem {
|
||||
if (a == null || b == null) return a == null && b == null;
|
||||
return a.toLowerCase(Locale.ROOT).equals(b.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Règles dans la langue demandée ({@code en} → anglais, sinon français), avec repli sur
|
||||
* l'autre version si celle-ci est vide : un système importé dans une seule langue reste lisible.
|
||||
*/
|
||||
public String rulesFor(String language) {
|
||||
boolean english = "en".equalsIgnoreCase(language);
|
||||
String preferred = english ? rulesMarkdownEn : rulesMarkdown;
|
||||
String fallback = english ? rulesMarkdown : rulesMarkdownEn;
|
||||
return preferred != null && !preferred.isBlank() ? preferred : fallback;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,14 @@ import java.util.Map;
|
||||
public record RulesImportResult(
|
||||
Map<String, String> sections,
|
||||
int pageCount,
|
||||
int ocrPageCount) {
|
||||
int ocrPageCount,
|
||||
/** Règles en deux langues : {code langue → sections} (« fr », « en »). */
|
||||
Map<String, Map<String, String>> sectionsByLanguage,
|
||||
/** Langue d'origine du livre (extraction fidèle) ; l'autre version est traduite. */
|
||||
String sourceLanguage) {
|
||||
|
||||
/** Résultat dans une seule langue (Brain antérieur, ou traduction indisponible). */
|
||||
public RulesImportResult(Map<String, String> sections, int pageCount, int ocrPageCount) {
|
||||
this(sections, pageCount, ocrPageCount, Map.of(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.loremind.domain.shared.ports;
|
||||
|
||||
/**
|
||||
* Port : langue de l'interface de l'utilisateur courant ({@code fr} ou {@code en}), pour les
|
||||
* contenus qui existent en deux langues (règles d'un système de jeu). Implémenté côté web.
|
||||
*/
|
||||
public interface CurrentLanguage {
|
||||
|
||||
/** Code court de la langue courante ({@code fr} par défaut). */
|
||||
String get();
|
||||
}
|
||||
@@ -106,7 +106,9 @@ public class BrainRulesImportClient implements RulesPdfImporter {
|
||||
return new RulesImportResult(
|
||||
Map.copyOf(response.getSections()),
|
||||
response.getPageCount(),
|
||||
response.getOcrPageCount());
|
||||
response.getOcrPageCount(),
|
||||
response.getSectionsByLanguage() != null ? response.getSectionsByLanguage() : Map.of(),
|
||||
response.getSourceLanguage());
|
||||
} catch (ResourceAccessException e) {
|
||||
throw new RulesImportException(
|
||||
"Le Brain est injoignable (timeout ou service arrêté).", e);
|
||||
@@ -218,12 +220,23 @@ public class BrainRulesImportClient implements RulesPdfImporter {
|
||||
callbacks.onDone().accept(new RulesImportResult(
|
||||
toStringMap(node.path("sections")),
|
||||
node.path("page_count").asInt(),
|
||||
node.path("ocr_page_count").asInt()));
|
||||
node.path("ocr_page_count").asInt(),
|
||||
toLanguageMap(node.path("sections_by_language")),
|
||||
node.path("source_language").asText(null)));
|
||||
}
|
||||
}
|
||||
|
||||
// --- Helpers -------------------------------------------------------------
|
||||
|
||||
/** {code langue → sections} : règles en deux langues (vide si le Brain ne les fournit pas). */
|
||||
private Map<String, Map<String, String>> toLanguageMap(JsonNode node) {
|
||||
Map<String, Map<String, String>> out = new java.util.LinkedHashMap<>();
|
||||
if (node != null && node.isObject()) {
|
||||
node.fields().forEachRemaining(e -> out.put(e.getKey(), toStringMap(e.getValue())));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private List<String> toStringList(JsonNode array) {
|
||||
List<String> out = new ArrayList<>();
|
||||
if (array != null && array.isArray()) {
|
||||
|
||||
@@ -23,4 +23,11 @@ class BrainRulesImportResponse {
|
||||
|
||||
@JsonProperty("ocr_page_count")
|
||||
private int ocrPageCount;
|
||||
|
||||
/** Règles en deux langues : {code langue → sections} (absent d'un Brain antérieur). */
|
||||
@JsonProperty("sections_by_language")
|
||||
private Map<String, Map<String, String>> sectionsByLanguage;
|
||||
|
||||
@JsonProperty("source_language")
|
||||
private String sourceLanguage;
|
||||
}
|
||||
|
||||
+3
@@ -37,6 +37,9 @@ public class GameSystemJpaEntity {
|
||||
@Column(name = "rules_markdown", columnDefinition = "TEXT")
|
||||
private String rulesMarkdown;
|
||||
|
||||
@Column(name = "rules_markdown_en", columnDefinition = "TEXT")
|
||||
private String rulesMarkdownEn;
|
||||
|
||||
/** Template PJ serialise en JSON via {@link TemplateFieldListJsonConverter}. */
|
||||
@Convert(converter = TemplateFieldListJsonConverter.class)
|
||||
@Column(name = "character_template", columnDefinition = "TEXT")
|
||||
|
||||
+2
@@ -60,6 +60,7 @@ public class PostgresGameSystemRepository implements GameSystemRepository {
|
||||
.name(e.getName())
|
||||
.description(e.getDescription())
|
||||
.rulesMarkdown(e.getRulesMarkdown())
|
||||
.rulesMarkdownEn(e.getRulesMarkdownEn())
|
||||
.characterTemplate(e.getCharacterTemplate() != null
|
||||
? new java.util.ArrayList<>(e.getCharacterTemplate())
|
||||
: new java.util.ArrayList<>())
|
||||
@@ -84,6 +85,7 @@ public class PostgresGameSystemRepository implements GameSystemRepository {
|
||||
.name(g.getName())
|
||||
.description(g.getDescription())
|
||||
.rulesMarkdown(g.getRulesMarkdown())
|
||||
.rulesMarkdownEn(g.getRulesMarkdownEn())
|
||||
.characterTemplate(g.getCharacterTemplate() != null
|
||||
? new java.util.ArrayList<>(g.getCharacterTemplate())
|
||||
: new java.util.ArrayList<>())
|
||||
|
||||
@@ -577,7 +577,8 @@ public class ExportService {
|
||||
private ContentExport.GameSystemDto toGameSystemDto(GameSystemJpaEntity e) {
|
||||
return new ContentExport.GameSystemDto(e.getId(), e.getName(), e.getDescription(),
|
||||
e.getRulesMarkdown(), e.getCharacterTemplate(), e.getNpcTemplate(),
|
||||
e.getEnemyTemplate(), e.getFoundryActorType(), e.getAuthor(), e.isPublic());
|
||||
e.getEnemyTemplate(), e.getFoundryActorType(), e.getAuthor(), e.isPublic(),
|
||||
e.getRulesMarkdownEn());
|
||||
}
|
||||
|
||||
private ContentExport.LoreDto toLoreDto(LoreJpaEntity e) {
|
||||
|
||||
@@ -49,6 +49,7 @@ class LoreContentInserter {
|
||||
e.setName(d.name());
|
||||
e.setDescription(d.description());
|
||||
e.setRulesMarkdown(d.rulesMarkdown());
|
||||
e.setRulesMarkdownEn(d.rulesMarkdownEn());
|
||||
e.setCharacterTemplate(d.characterTemplate());
|
||||
e.setNpcTemplate(d.npcTemplate());
|
||||
e.setEnemyTemplate(d.enemyTemplate());
|
||||
|
||||
@@ -77,7 +77,9 @@ public record ContentExport(
|
||||
List<TemplateField> enemyTemplate,
|
||||
String foundryActorType,
|
||||
String author,
|
||||
boolean isPublic
|
||||
boolean isPublic,
|
||||
/** Version anglaise des règles ; absente des bundles antérieurs (null). */
|
||||
String rulesMarkdownEn
|
||||
) {}
|
||||
|
||||
public record LoreDto(
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.loremind.infrastructure.web.config;
|
||||
|
||||
import com.loremind.domain.shared.ports.CurrentLanguage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** Langue courante lue dans {@link UserLanguageHolder} (requête HTTP, ou tâche de fond décorée). */
|
||||
@Component
|
||||
public class UserLanguageCurrentLanguage implements CurrentLanguage {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return UserLanguageHolder.get();
|
||||
}
|
||||
}
|
||||
+1
@@ -257,6 +257,7 @@ public class GameSystemController {
|
||||
dto.getName(),
|
||||
dto.getDescription(),
|
||||
dto.getRulesMarkdown(),
|
||||
dto.getRulesMarkdownEn(),
|
||||
templateFieldMapper.toDomainList(dto.getCharacterTemplate()),
|
||||
templateFieldMapper.toDomainList(dto.getNpcTemplate()),
|
||||
templateFieldMapper.toDomainList(dto.getEnemyTemplate()),
|
||||
|
||||
+2
@@ -17,6 +17,8 @@ public class GameSystemDTO {
|
||||
private String name;
|
||||
private String description;
|
||||
private String rulesMarkdown;
|
||||
/** Version anglaise des règles (rulesMarkdown = version française). */
|
||||
private String rulesMarkdownEn;
|
||||
private List<TemplateFieldDTO> characterTemplate = new ArrayList<>();
|
||||
private List<TemplateFieldDTO> npcTemplate = new ArrayList<>();
|
||||
private List<TemplateFieldDTO> enemyTemplate = new ArrayList<>();
|
||||
|
||||
@@ -20,6 +20,7 @@ public class GameSystemMapper {
|
||||
dto.setName(g.getName());
|
||||
dto.setDescription(g.getDescription());
|
||||
dto.setRulesMarkdown(g.getRulesMarkdown());
|
||||
dto.setRulesMarkdownEn(g.getRulesMarkdownEn());
|
||||
dto.setCharacterTemplate(fieldMapper.toDTOList(g.getCharacterTemplate()));
|
||||
dto.setNpcTemplate(fieldMapper.toDTOList(g.getNpcTemplate()));
|
||||
dto.setEnemyTemplate(fieldMapper.toDTOList(g.getEnemyTemplate()));
|
||||
@@ -36,6 +37,7 @@ public class GameSystemMapper {
|
||||
.name(dto.getName())
|
||||
.description(dto.getDescription())
|
||||
.rulesMarkdown(dto.getRulesMarkdown())
|
||||
.rulesMarkdownEn(dto.getRulesMarkdownEn())
|
||||
.characterTemplate(fieldMapper.toDomainList(dto.getCharacterTemplate()))
|
||||
.npcTemplate(fieldMapper.toDomainList(dto.getNpcTemplate()))
|
||||
.enemyTemplate(fieldMapper.toDomainList(dto.getEnemyTemplate()))
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- Règles d'un système de jeu en deux langues : rules_markdown = version française,
|
||||
-- rules_markdown_en = version anglaise (remplie à l'import d'un PDF par traduction).
|
||||
ALTER TABLE game_systems ADD COLUMN rules_markdown_en TEXT;
|
||||
+23
@@ -23,6 +23,9 @@ class GameSystemContextBuilderTest {
|
||||
@Mock
|
||||
private GameSystemRepository gameSystemRepository;
|
||||
|
||||
@Mock
|
||||
private com.loremind.domain.shared.ports.CurrentLanguage currentLanguage;
|
||||
|
||||
@InjectMocks
|
||||
private GameSystemContextBuilder builder;
|
||||
|
||||
@@ -71,4 +74,24 @@ class GameSystemContextBuilderTest {
|
||||
|
||||
assertEquals("Règles de combat.", sections.get("Combat"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void build_usesTheRulesOfTheInterfaceLanguage_withFallback() {
|
||||
com.loremind.domain.gamesystemcontext.GameSystem gs = com.loremind.domain.gamesystemcontext.GameSystem.builder()
|
||||
.id("gs").name("Nimble").rulesMarkdown("## Combat\nJet de d20").rulesMarkdownEn("## Fighting\nRoll a d20").build();
|
||||
org.mockito.Mockito.when(gameSystemRepository.findById("gs")).thenReturn(java.util.Optional.of(gs));
|
||||
|
||||
org.mockito.Mockito.when(currentLanguage.get()).thenReturn("en");
|
||||
assertTrue(builder.buildOptional("gs", com.loremind.domain.gamesystemcontext.GenerationIntent.GENERIC)
|
||||
.orElseThrow().toString().contains("Roll a d20"));
|
||||
|
||||
org.mockito.Mockito.when(currentLanguage.get()).thenReturn("fr");
|
||||
assertTrue(builder.buildOptional("gs", com.loremind.domain.gamesystemcontext.GenerationIntent.GENERIC)
|
||||
.orElseThrow().toString().contains("Jet de d20"));
|
||||
|
||||
gs.setRulesMarkdownEn(null); // pas de version anglaise : repli sur le français
|
||||
org.mockito.Mockito.when(currentLanguage.get()).thenReturn("en");
|
||||
assertTrue(builder.buildOptional("gs", com.loremind.domain.gamesystemcontext.GenerationIntent.GENERIC)
|
||||
.orElseThrow().toString().contains("Jet de d20"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,4 +347,26 @@ class BrainRulesImportClientTest {
|
||||
assertTrue(c.done.get().sections().isEmpty());
|
||||
assertNull(c.error.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void streaming_done_carriesBothLanguages() {
|
||||
String sse = "event:done\ndata:{\"sections\":{\"Combat\":\"d20\"},\"page_count\":2,\"ocr_page_count\":0,"
|
||||
+ "\"source_language\":\"fr\",\"sections_by_language\":{\"fr\":{\"Combat\":\"d20\"},"
|
||||
+ "\"en\":{\"Fighting\":\"d20 roll\"}}}\n\n";
|
||||
Collector c = new Collector();
|
||||
ExchangeFunction ef = req -> Mono.just(
|
||||
ClientResponse.create(HttpStatus.OK)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
.body(sse)
|
||||
.build());
|
||||
client(ef).importRulesStreaming(
|
||||
new byte[]{1}, "r.pdf",
|
||||
c.progress::add, c.heartbeats::incrementAndGet, c.statuses::add,
|
||||
c.done::set, c.error::set);
|
||||
|
||||
assertNotNull(c.done.get());
|
||||
assertEquals("fr", c.done.get().sourceLanguage());
|
||||
assertEquals(java.util.Map.of("Fighting", "d20 roll"), c.done.get().sectionsByLanguage().get("en"));
|
||||
assertEquals(java.util.Map.of("Combat", "d20"), c.done.get().sectionsByLanguage().get("fr"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user