-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60ecee3
commit 6ba4471
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import I18n.EnvExtension | ||
-- import DateTime | ||
|
||
|
||
open Lean System | ||
namespace I18n | ||
|
||
open Elab.Command in | ||
|
||
def POFile.ofJson (json : Json) : Except String POFile := | ||
match json with | ||
| .obj <| x => | ||
let entries : Array POEntry := x.toArray.filterMap (fun ⟨key, val⟩ => | ||
match val with | ||
| .str val => | ||
some {msgId := key, msgStr := val} | ||
| _ => | ||
-- TODO: This silently drops anything that is not a string. | ||
none) | ||
.ok { | ||
header := { | ||
-- Todo: is the header used for anything? | ||
projectIdVersion := "", | ||
reportMsgidBugsTo := "", | ||
potCreationDate := "", | ||
language := "" }, | ||
entries := entries } | ||
| _ => throw "Invalid Json!" | ||
|
||
def POFile.readFromJson (path : FilePath) : IO POFile := do | ||
if ¬ (← FilePath.pathExists path) then | ||
panic "File does not exist!" | ||
let content ← IO.FS.readFile path | ||
match Json.parse content with | ||
| .ok f => | ||
match POFile.ofJson f with | ||
| .ok f => return f | ||
| .error err => | ||
panic! s!"Failed to turn Json into PO file: {err}" | ||
| .error err => | ||
panic! s!"Failed to parse Json file: {err}" |