diff --git a/src/cli/strings.ml b/src/cli/strings.ml index 1f2ba3d..4b62c4e 100644 --- a/src/cli/strings.ml +++ b/src/cli/strings.ml @@ -1,7 +1,7 @@ open Core open Lwt.Infix -let version = "1.1.0" +let version = "1.1.1" let header = sprintf "/* Generated by okTurtles/strings v%s */\n\n" version let () = Lwt.async_exception_hook := (fun ex -> @@ -86,15 +86,9 @@ let write_english english = let write_other ~language english other = let path_strings = sprintf "strings/%s.strings" language in let path_json = sprintf "strings/%s.json" language in - let first = ref true in let%lwt n_left, n_right, n_both = Lwt_io.with_file ~flags:write_flags ~mode:Output path_strings (fun oc_strings -> Lwt_io.with_file ~flags:write_flags ~mode:Output path_json (fun oc_json -> - let%lwt () = Lwt.join [ - Lwt_io.write oc_strings header; - Lwt_io.write_char oc_json '{'; - ] - in let english_only = ref String.Map.empty in let other_only = ref String.Map.empty in let both = ref String.Map.empty in @@ -105,8 +99,7 @@ let write_other ~language english other = let missing_translation key x = let fmt_key = fmt key in let line_strings = sprintf "/* MISSING TRANSLATION - %s */\n%s = %s;\n\n" x fmt_key fmt_key in - let line_json = json_pair fmt_key fmt_key first in - add_entry english_only ~line_strings ~line_json + add_entry english_only ~line_strings ~line_json:(fmt_key, fmt_key) in let _table = String.Table.merge english other ~f:(fun ~key -> function | `Left x -> missing_translation key x @@ -115,8 +108,7 @@ let write_other ~language english other = let fmt_key = fmt key in let fmt_y = fmt y in let line_strings = sprintf "/* %s */\n%s = %s;\n\n" x fmt_key fmt_y in - let line_json = json_pair fmt_key fmt_y first in - add_entry both ~line_strings ~line_json + add_entry both ~line_strings ~line_json:(fmt_key, fmt_y) | `Right y when String.(key = y) -> None | `Right y -> (* No need to write "deprecated translations" to JSON *) @@ -124,8 +116,14 @@ let write_other ~language english other = add_entry other_only ~line_strings ~line_json:() ) in - let write_pairs map = String.Map.fold map ~init:(Lwt.return 0) ~f:(fun ~key:line_strings ~data:line_json acc -> - let%lwt () = Lwt_io.write oc_strings line_strings <&> Lwt_io.write oc_json line_json in + let first = ref true in + let%lwt () = Lwt.join [ + Lwt_io.write oc_strings header; + Lwt_io.write_char oc_json '{'; + ] + in + let write_pairs map = String.Map.fold map ~init:(Lwt.return 0) ~f:(fun ~key:line_strings ~data:(x, y) acc -> + let%lwt () = Lwt_io.write oc_strings line_strings <&> Lwt_io.write oc_json (json_pair x y first) in acc >|= succ ) in