Skip to content

Commit

Permalink
Fix JSON formatting in translated languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin committed Sep 6, 2020
1 parent c578755 commit 1872c8c
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/cli/strings.ml
Original file line number Diff line number Diff line change
@@ -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 ->
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -115,17 +108,22 @@ 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 *)
let line_strings = sprintf "/* Not currently used */\n%s = %s;\n\n" (fmt key) (fmt y) in
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
Expand Down

0 comments on commit 1872c8c

Please sign in to comment.