1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-03 14:59:57 +00:00

refactor: use function instead of set variable

This commit is contained in:
lin onetwo 2023-12-16 01:27:40 +08:00
parent 7d321feb1e
commit 2055f36689

View File

@ -9,14 +9,24 @@ $:/language/
{{$(lingo-base)$$title$}} {{$(lingo-base)$$title$}}
\end \end
\procedure translate(key, lingoBaseFallback:"", mode:block) \procedure translate(key, lingo-base-fallback, mode:block)
<!-- Allow assign lingo-base in caption field by accepting the lingo-base-fallback param. --> <!-- Allow assign lingo-base in caption field by accepting the lingo-base-fallback param. -->
<$set name="lingoBaseWithFallback" value=<<lingo-base-fallback>> emptyValue=<<lingo-base>>> \function target-lingo-base()
<$set name="lang" filter="[[$:/language]get[text]get[name]else[en-GB]]" select="0"> [<lingo-base-fallback>!is[blank]else<lingo-base>]
<!-- Allow lingo-base to have or not have / ending slash, for better dev experience. Then add, e.g. `en-GB/Key` after it. --> \end target-lingo-base
<$set name="lingoTarget" filter="[<lingoBaseWithFallback>suffix[/]then<lingoBaseWithFallback>] ~[<lingoBaseWithFallback>addsuffix[/]] +[addsuffix<lang>addsuffix[/]addsuffix<key>]" select="0">
<$transclude $tiddler=<<lingoTarget>> $mode=<<mode>> /> \function add-lang-suffix(base)
</$set> [[$:/language]get[text]get[name]else[en-GB]]
</$set> +[addprefix<base>]
</$set> \end add-lang-suffix
<!-- Allow lingo-base to have or not have / ending slash, for better dev experience. Then add, e.g. `en-GB/Key` after it. -->
\function lingo-target()
[function[target-lingo-base]suffix[/]]
:then[function[target-lingo-base]]
~[function[target-lingo-base]addsuffix[/]]
:map[function[add-lang-suffix],<currentTiddler>addsuffix[/]addsuffix<key>]
\end lingo-target
<$transclude $tiddler=<<lingo-target>> $mode=<<mode>> />
\end \end