From 1548de4bdf038bddcfc3a65241b1fb49fdce4ab1 Mon Sep 17 00:00:00 2001 From: Renatillas Date: Fri, 12 Sep 2025 01:20:24 +0200 Subject: [PATCH] Fix another bug --- gleam.toml | 2 +- src/g18n/dev.gleam | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gleam.toml b/gleam.toml index adf49a6..e379713 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "g18n_dev" -version = "1.1.0" +version = "1.1.1" description = "Development tools and CLI for the g18n internationalization library" licences = ["MIT"] diff --git a/src/g18n/dev.gleam b/src/g18n/dev.gleam index 31f1856..f9dce23 100644 --- a/src/g18n/dev.gleam +++ b/src/g18n/dev.gleam @@ -212,23 +212,25 @@ fn generate_translation_report(primary_locale: String) -> SnagResult(Nil) { fn try_load_translations( project_name: String, ) -> SnagResult(List(#(String, g18n.Translations))) { - // Try flat JSON first + // Try to find JSON files first case find_locale_files(project_name) { Ok(files) -> { + // Try flat JSON first case load_all_locales(files) { Ok(data) -> { io.println("📁 Detected format: Flat JSON") Ok(data) } - Error(_) -> { + Error(_flat_error) -> { // Try nested JSON - case load_all_locales_from_nested(files) { + let nested_result = load_all_locales_from_nested(files) + case nested_result { Ok(data) -> { io.println("📁 Detected format: Nested JSON") Ok(data) } - Error(_) -> { - // Try PO files + Error(_nested_error) -> { + // Both JSON formats failed, try PO files case find_po_files(project_name) { Ok(po_files) -> { case load_all_locales_from_po(po_files) { @@ -236,13 +238,13 @@ fn try_load_translations( io.println("📁 Detected format: PO files") Ok(data) } - Error(e) -> Error(e) + Error(po_error) -> Error(po_error) } } - Error(_) -> - snag.error( - "No valid translation files found. Tried flat JSON, nested JSON, and PO formats.", - ) + Error(_) -> { + // No PO files found, return the nested JSON error as it's more likely to be helpful + nested_result + } } } } @@ -250,7 +252,7 @@ fn try_load_translations( } } Error(_) -> { - // Try PO files directly if no JSON files found + // No JSON files found, try PO files directly case find_po_files(project_name) { Ok(po_files) -> { case load_all_locales_from_po(po_files) { -- 2.51.2