1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-03-10 21:48:10 +00:00

refactor: use lingo and procedure

This commit is contained in:
lin onetwo 2023-12-16 00:26:55 +08:00
parent cacd236f71
commit 7d321feb1e
5 changed files with 37 additions and 37 deletions

View File

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

View File

@ -1,14 +0,0 @@
created: 20231028120432257
modified: 20231028122408606
tags: [[t Macro]] [[Macro Examples]]
title: t Macro (Examples)
\define lingo-base() t Macro (Examples)
Given the `\define lingo-base() t Macro (Examples)`, this example shows the localizaion key `ExampleKey` being translate to the text in [[t Macro (Examples)/en-GB/ExampleKey]]:
<$macrocall $name=".example" n="1" eg="""<<t ExampleKey>>"""/>
This example shows the `lingo-base` can be set inline as second parameter:
<$macrocall $name=".example" n="2" eg="""<<t ExampleKey "t Macro (Examples)">>"""/>

View File

@ -0,0 +1,14 @@
created: 20231028120432257
modified: 20231028122408606
tags: [[translate Macro]] [[Macro Examples]]
title: translate Macro (Examples)
\define lingo-base() translate Macro (Examples)
Given the `\define lingo-base() translate Macro (Examples)`, this example shows the localizaion key `ExampleKey` being translate to the text in [[translate Macro (Examples)/en-GB/ExampleKey]]:
<$macrocall $name=".example" n="1" eg="""<<translate ExampleKey>>"""/>
This example shows the `lingo-base` can be set inline as second parameter:
<$macrocall $name=".example" n="2" eg="""<<translate ExampleKey "translate Macro (Examples)">>"""/>

View File

@ -1,5 +1,5 @@
created: 20231028120526948
modified: 20231028123420761
title: t Macro (Examples)/en-GB/ExampleKey
title: translate Macro (Examples)/en-GB/ExampleKey
This is the translated text of key "~ExampleKey" under lingo-base `t Macro (Examples)`
This is the translated text of key "~ExampleKey" under lingo-base `translate Macro (Examples)`

View File

@ -1,10 +1,10 @@
caption: t (translation)
caption: translate
created: 20231028115714556
modified: 20231028123219684
modified: 20231216122319684
tags: Macros [[Core Macros]]
title: t Macro
title: translate Macro
The <<.def t>> [[macro|Macros]] relates to the translation of ~TiddlyWiki's user interface into other languages, just like [[lingo Macro]]. It returns a piece of text in the user's currently selected language. And `t` is the abbreviation of "translation".
The <<.def translate>> [[macro|Macros]] relates to the translation of ~TiddlyWiki's user interface into other languages, just like [[lingo Macro]]. It returns a piece of text in the user's currently selected language. And `t` is the abbreviation of "translation".
The difference to [[lingo Macro]] is that translatable text can be directly placed in user's wiki, instead of in a language plugin.
@ -17,16 +17,16 @@ The difference to [[lingo Macro]] is that translatable text can be directly plac
;mode
: Optional parameter like the "mode" parameter in [[TranscludeWidget]], default to "block".
<<.macro-examples "t">>
<<.macro-examples "translate">>
!! Example file structure in plugin
!!! Suggested file structure
When developing a plugin, you may want to organize your i18n (internationalization) files like this on the file system as [[MultiTiddlerFiles]]:
When developing a plugin, you may want to organize your language files like this on the file system as [[MultiTiddlerFiles]]:
```tree
├── i18n
├── language
│ ├── en-GB
│ │ ├── Translations.multids
│ │ └── SomeLongText.tid
@ -39,10 +39,10 @@ When developing a plugin, you may want to organize your i18n (internationalizati
!!! Define Multiple Translations in One Tiddler
And the content of `i18n/en-GB/Translations.multids` may looks like this:
And the content of `language/en-GB/Translations.multids` may looks like this:
```multids
title: $:/plugins/yourName/pluginName/languages/en-GB/
title: $:/plugins/yourName/pluginName/language/en-GB/
OpenInteractiveCard: Open Interactive Card
OpenStaticCard: Open Static Card
@ -52,20 +52,20 @@ Later you can use it like:
```tid
title: someTiddler
caption: <<t "OpenStaticCard" "$:/plugins/yourName/pluginName/languages/">>
caption: <<translate "OpenStaticCard" "$:/plugins/yourName/pluginName/language/">>
\define lingo-base() $:/plugins/yourName/pluginName/languages/
\define lingo-base() $:/plugins/yourName/pluginName/language/
\whitespace trim
<<t "OpenInteractiveCard">>
<<translate "OpenInteractiveCard">>
```
!!! Define Long Text in regular Tiddler
!!! Define Long Text in a regular Tiddler
You can also use a regular tiddler for long text, like `SomeLongText.tid` in the example above, to store a multi-paragraph long text:
```tid
title: $:/plugins/yourName/pluginName/languages/en-GB/SomeLongText
title: $:/plugins/yourName/pluginName/language/en-GB/SomeLongText
!!! SubTitle
@ -77,9 +77,9 @@ Later you can use it like:
```tid
title: someTiddler
\define lingo-base() $:/plugins/yourName/pluginName/languages/
\define lingo-base() $:/plugins/yourName/pluginName/language/
!! <<t "OpenInteractiveCard">>
!! <<translate "OpenInteractiveCard">>
<<t "SomeLongText">>
<<translate "SomeLongText">>
```