Skip to content

Commit

Permalink
fix po-creation without translation
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Mar 1, 2024
1 parent 663c764 commit d54c5cb
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions I18n/Translate.lean
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,28 @@ elab "Language" lang:ident : command => do
-- Load in the translation for that language
Elab.Command.liftCoreM <| loadTranslations

/--
Add a string to the set of untranslated strings
-/
def _root_.String.markForTranslation [Monad m] [MonadEnv m] [MonadLog m] [AddMessageContext m]
[MonadOptions m] (s : String) : m Unit := do
let env ← getEnv
let entry : POEntry := {
msgId := s
ref := some [(env.mainModule.toString, none)] }
modifyEnv (untranslatedKeysExt.addEntry · entry)


/--
Add the string as untranslated, look up a translation
and return the translated string.
Returns the original string on failure.
-/
def _root_.String.translate [Monad m] [MonadEnv m] [MonadLog m] [AddMessageContext m]
[MonadOptions m] (s : String) : m String := do
let env ← getEnv
s.markForTranslation

let langConfig : LanguageState ← getLanguageState
let entry : POEntry := {
msgId := s
ref := some [(env.mainModule.toString, none)] }
modifyEnv (untranslatedKeysExt.addEntry · entry)
let sTranslated ← if langConfig.lang == langConfig.sourceLang then
pure s
else
Expand All @@ -74,6 +83,9 @@ def interpolatedStrKind.translate (interpStr : TSyntax `interpolatedStrKind)
let langState ← getLanguageState
let key ← interpolatedStrKind.toString interpStr
let newInterpStr ← if langState.lang == langState.sourceLang then
-- We need to add the string as untranslated,
-- but we can just return the existing string.
key.markForTranslation
pure interpStr
else
-- Search for a translation
Expand Down

0 comments on commit d54c5cb

Please sign in to comment.