summaryrefslogtreecommitdiff
path: root/internal/batch/processor.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-01-21 21:43:40 +0200
committerPaul Buetow <paul@buetow.org>2026-01-21 21:43:40 +0200
commit8a4b935792c50101cf65b36e44f376c90c2d08c1 (patch)
tree2a8288e935fe89738fbc1243253bb638dc2620a8 /internal/batch/processor.go
parent2bd22f79f739136a7d30cf156979e2f2b23b7c65 (diff)
improve: better audio player UI and debugging for bg-bg cards
- Add debug logging to navigation.go to diagnose audio file loading issues Prints paths being checked and whether files are found - Improve AudioPlayer UI for Bulgarian-Bulgarian cards: - Add labels showing 'Front' and 'Back' for bg-bg audio buttons - Labels only show when audio files are actually loaded - Better visual distinction between the two playable audios - Reorganized button layout with VBox for cleaner appearance - Track bg-bg state in AudioPlayer (isBgBg field) - Automatically set when back audio file is loaded - Used to determine when to show labels This makes it clearer that Bulgarian-Bulgarian cards have two independently playable audio outputs, and helps debug why audio isn't being loaded.
Diffstat (limited to 'internal/batch/processor.go')
-rw-r--r--internal/batch/processor.go95
1 files changed, 65 insertions, 30 deletions
diff --git a/internal/batch/processor.go b/internal/batch/processor.go
index 0b20179..6867c3c 100644
--- a/internal/batch/processor.go
+++ b/internal/batch/processor.go
@@ -4,6 +4,8 @@ import (
"fmt"
"os"
"strings"
+
+ "codeberg.org/snonux/totalrecall/internal"
)
// WordEntry represents a word with optional translation
@@ -12,6 +14,8 @@ type WordEntry struct {
Translation string
// NeedsTranslation indicates if translation from English to Bulgarian is needed
NeedsTranslation bool
+ // CardType indicates whether this is en-bg or bg-bg card
+ CardType internal.CardType
}
// ReadBatchFile reads words from a file and returns WordEntry slice
@@ -19,6 +23,7 @@ type WordEntry struct {
// - Bulgarian word only: "ябълка" (will be translated to English)
// - With translation: "ябълка = apple" (both provided, no translation needed)
// - English only: "= apple" (will be translated to Bulgarian)
+// - Bulgarian-Bulgarian: "word1 == definition" (bg-bg card, double equals)
func ReadBatchFile(filename string) ([]WordEntry, error) {
content, err := os.ReadFile(filename)
if err != nil {
@@ -30,42 +35,72 @@ func ReadBatchFile(filename string) ([]WordEntry, error) {
for _, line := range splitLines(lines) {
if line = trimSpace(line); line != "" {
- // Check if line contains '=' for translation format
- if strings.Contains(line, "=") {
- parts := strings.SplitN(line, "=", 2)
- if len(parts) == 2 {
- bulgarian := strings.TrimSpace(parts[0])
- english := strings.TrimSpace(parts[1])
-
- if bulgarian == "" && english != "" {
- // Format: "= ENGLISH" - need to translate English to Bulgarian
- entries = append(entries, WordEntry{
- Bulgarian: "", // Will be filled by translation
- Translation: english,
- NeedsTranslation: true,
- })
- } else if bulgarian != "" && english != "" {
- // Format: "BULGARIAN = ENGLISH" - both provided
- entries = append(entries, WordEntry{
- Bulgarian: bulgarian,
- Translation: english,
- NeedsTranslation: false,
- })
- }
- // Ignore lines with empty English part
+ entry := parseBatchLine(line)
+ if entry != nil {
+ entries = append(entries, *entry)
+ }
+ }
+ }
+
+ return entries, nil
+}
+
+// parseBatchLine parses a single batch file line and returns the appropriate WordEntry
+func parseBatchLine(line string) *WordEntry {
+ // Check for Bulgarian-Bulgarian format first (double equals ==)
+ if strings.Contains(line, "==") {
+ parts := strings.SplitN(line, "==", 2)
+ if len(parts) == 2 {
+ bulgarian1 := strings.TrimSpace(parts[0])
+ bulgarian2 := strings.TrimSpace(parts[1])
+
+ if bulgarian1 != "" && bulgarian2 != "" {
+ return &WordEntry{
+ Bulgarian: bulgarian1,
+ Translation: bulgarian2,
+ NeedsTranslation: false,
+ CardType: internal.CardTypeBgBg,
}
- } else {
- // Just a Bulgarian word - needs translation to English
- entries = append(entries, WordEntry{
- Bulgarian: line,
- Translation: "",
+ }
+ }
+ return nil
+ }
+
+ // Check for English-Bulgarian format (single equals =)
+ if strings.Contains(line, "=") {
+ parts := strings.SplitN(line, "=", 2)
+ if len(parts) == 2 {
+ bulgarian := strings.TrimSpace(parts[0])
+ english := strings.TrimSpace(parts[1])
+
+ if bulgarian == "" && english != "" {
+ // Format: "= ENGLISH" - need to translate English to Bulgarian
+ return &WordEntry{
+ Bulgarian: "",
+ Translation: english,
+ NeedsTranslation: true,
+ CardType: internal.CardTypeEnBg,
+ }
+ } else if bulgarian != "" && english != "" {
+ // Format: "BULGARIAN = ENGLISH" - both provided
+ return &WordEntry{
+ Bulgarian: bulgarian,
+ Translation: english,
NeedsTranslation: false,
- })
+ CardType: internal.CardTypeEnBg,
+ }
}
}
+ return nil
}
- return entries, nil
+ // Just a Bulgarian word - needs translation to English
+ return &WordEntry{
+ Bulgarian: line,
+ Translation: "",
+ NeedsTranslation: false,
+ CardType: internal.CardTypeEnBg,
+ }
}
// splitLines splits a string by newlines