add i18n dependency (#179)

pull/204/head
Jon Eugster 2 years ago
parent 45d84103c1
commit a75a4a81ac

@ -3,6 +3,7 @@ import GameServer.Inventory
import GameServer.Options
import GameServer.SaveData
import GameServer.Hints
import I18n
open Lean Meta Elab Command
@ -33,16 +34,17 @@ elab "Level" level:num : command => do
/-- Define the title of the current game/world/level. -/
elab "Title" t:str : command => do
let title ← t.getString.translate
match ← getCurLayer with
| .Level => modifyCurLevel fun level => pure {level with title := t.getString}
| .World => modifyCurWorld fun world => pure {world with title := t.getString}
| .Level => modifyCurLevel fun level => pure {level with title := title}
| .World => modifyCurWorld fun world => pure {world with title := title}
| .Game => modifyCurGame fun game => pure {game with
title := t.getString
tile := {game.tile with title := t.getString}}
tile := {game.tile with title := title}}
/-- Define the introduction of the current game/world/level. -/
elab "Introduction" t:str : command => do
let intro := t.getString
let intro ← t.getString.translate
match ← getCurLayer with
| .Level => modifyCurLevel fun level => pure {level with introduction := intro}
| .World => modifyCurWorld fun world => pure {world with introduction := intro}
@ -50,7 +52,7 @@ elab "Introduction" t:str : command => do
/-- Define the info of the current game. Used for e.g. credits -/
elab "Info" t:str : command => do
let info:= t.getString
let info ← t.getString.translate
match ← getCurLayer with
| .Level =>
logError "Can't use `Info` in a level!"
@ -82,7 +84,7 @@ elab "Image" t:str : command => do
/-- Define the conclusion of the current game or current level if some
building a level. -/
elab "Conclusion" t:str : command => do
let conclusion := t.getString
let conclusion ← t.getString.translate
match ← getCurLayer with
| .Level => modifyCurLevel fun level => pure {level with conclusion := conclusion}
| .World => modifyCurWorld fun world => pure {world with conclusion := conclusion}
@ -95,13 +97,13 @@ elab "Prerequisites" t:str* : command => do
/-- Short caption for the game (1 sentence) -/
elab "CaptionShort" t:str : command => do
let caption := t.getString
let caption ← t.getString.translate
modifyCurGame fun game => pure {game with
tile := {game.tile with short := caption}}
/-- More detailed description what the game is about (2-4 sentences). -/
elab "CaptionLong" t:str : command => do
let caption := t.getString
let caption ← t.getString.translate
modifyCurGame fun game => pure {game with
tile := {game.tile with long := caption}}
@ -142,6 +144,7 @@ TacticDoc rw "`rw` stands for rewrite, etc. "
-/
elab doc:docComment ? "TacticDoc" name:ident content:str ? : command => do
let doc ← parseDocCommentLegacy doc content
let doc ← doc.translate
modifyEnv (inventoryTemplateExt.addEntry · {
type := .Tactic
name := name.getId
@ -166,6 +169,7 @@ The theorem/definition to have the same fully qualified name as in mathlib.
elab doc:docComment ? "TheoremDoc" name:ident "as" displayName:str "in" category:str content:str ? :
command => do
let doc ← parseDocCommentLegacy doc content
let doc ← doc.translate
modifyEnv (inventoryTemplateExt.addEntry · {
type := .Lemma
name := name.getId
@ -195,6 +199,7 @@ The theorem/definition to have the same fully qualified name as in mathlib.
-/
elab doc:docComment ? "DefinitionDoc" name:ident "as" displayName:str template:str ? : command => do
let doc ← parseDocCommentLegacy doc template
let doc ← doc.translate
modifyEnv (inventoryTemplateExt.addEntry · {
type := .Definition
name := name.getId,
@ -341,6 +346,9 @@ elab doc:docComment ? attrs:Parser.Term.attributes ?
let lvlIdx ← getCurLevelIdx
let docContent ← parseDocComment doc
let docContent ← match docContent with
| none => pure none
| some d => d.translate
-- Save the messages before evaluation of the proof.
let initMsgs ← modifyGet fun st => (st.messages, { st with messages := {} })
@ -426,6 +434,12 @@ elab doc:docComment ? attrs:Parser.Term.attributes ?
strict := strict == 1
hidden := hidden == 1
}
-- Note: The current setup for hints is a bit convoluted, but for now we need to
-- send the text once through i18n to register it in the env extension.
-- This could probably be rewritten once i18n works fully.
let _ ← hint.rawText.translate
hints := hints.push hint
else
nonHintMsgs := nonHintMsgs.push msg

@ -1,8 +1,8 @@
import GameServer.EnvExtensions
import I18n
open Lean Meta Elab Command
/-! ## Copy images -/
open IO.FS System FilePath in
@ -59,6 +59,9 @@ def saveGameData (allItemsByType : HashMap InventoryType (HashSet Name))
IO.FS.writeFile (path / inventoryFileName) (toString (toJson inventory))
-- write PO file for translation
I18n.createPOTemplate
open GameData
def loadData (f : System.FilePath) (α : Type) [FromJson α] : IO α := do

@ -9,6 +9,21 @@
"manifestFile": "lake-manifest.json",
"inputRev": "v4.5.0",
"inherited": false,
"configFile": "lakefile.lean"},
{"type": "path",
"name": "time",
"manifestFile": "lake-manifest.json",
"inherited": true,
"dir": ".lake/packages/i18n/./time",
"configFile": "lakefile.lean"},
{"url": "https://github.com/hhu-adam/lean-i18n.git",
"type": "git",
"subDir": null,
"rev": "cd22ffcb59cb8e01bb6d17e997389233e9a11177",
"name": "i18n",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": false,
"configFile": "lakefile.lean"}],
"name": "GameServer",
"lakeDir": ".lake"}

@ -7,8 +7,7 @@ package GameServer
def leanVersion : String := s!"v{Lean.versionString}"
require std from git "https://github.com/leanprover/std4.git" @ leanVersion
-- require importGraph from git "https://github.com/leanprover-community/import-graph" @ leanVersion
require i18n from git "https://github.com/hhu-adam/lean-i18n.git" @ "main"
lean_lib GameServer

Loading…
Cancel
Save