1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-03 12:49:09 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/macros/translateMacro.tid

86 lines
2.6 KiB
Plaintext
Raw Normal View History

2023-12-15 16:26:55 +00:00
caption: translate
2023-10-28 12:38:26 +00:00
created: 20231028115714556
2023-12-15 16:26:55 +00:00
modified: 20231216122319684
2023-10-28 12:38:26 +00:00
tags: Macros [[Core Macros]]
2023-12-15 16:26:55 +00:00
title: translate Macro
2023-10-28 12:38:26 +00:00
2023-12-15 16:26:55 +00:00
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".
2023-10-28 12:38:26 +00:00
The difference to [[lingo Macro]] is that translatable text can be directly placed in user's wiki, instead of in a language plugin.
!! Parameters
;key
: The last part of title of the tiddler that contains the text. The `<<lingo-base>>` prefix and current language name prefix is added automatically
;lingo-base-fallback
: Optional lingo-base when it is not possible to define `lingo-base` variable (for example, when using this macro in the caption field), you can set the lingo base by passing this parameter
;mode
2023-12-15 17:33:47 +00:00
: Optional parameter like the "mode" parameter in [[TranscludeWidget]], default to "block". If you are using translation in a title, you can add `mode:"inline"` to it.
2023-10-28 12:38:26 +00:00
2023-12-15 16:26:55 +00:00
<<.macro-examples "translate">>
2023-10-28 12:38:26 +00:00
!! Example file structure in plugin
!!! Suggested file structure
2023-12-15 16:26:55 +00:00
When developing a plugin, you may want to organize your language files like this on the file system as [[MultiTiddlerFiles]]:
2023-10-28 12:38:26 +00:00
```tree
2023-12-15 16:26:55 +00:00
├── language
2023-10-28 12:38:26 +00:00
│ ├── en-GB
│ │ ├── Translations.multids
│ │ └── SomeLongText.tid
2023-10-28 12:38:26 +00:00
│ └── zh-Hans
│ ├── Translations.multids
│ └── SomeLongText.tid
2023-10-28 12:38:26 +00:00
├── other files
└── plugin.info
```
!!! Define Multiple Translations in One Tiddler
2023-12-15 16:26:55 +00:00
And the content of `language/en-GB/Translations.multids` may looks like this:
2023-10-28 12:38:26 +00:00
```multids
2023-12-15 16:26:55 +00:00
title: $:/plugins/yourName/pluginName/language/en-GB/
2023-10-28 12:38:26 +00:00
OpenInteractiveCard: Open Interactive Card
OpenStaticCard: Open Static Card
```
Later you can use it like:
```tid
title: someTiddler
2023-12-15 16:26:55 +00:00
caption: <<translate "OpenStaticCard" "$:/plugins/yourName/pluginName/language/">>
2023-10-28 12:38:26 +00:00
2023-12-15 16:26:55 +00:00
\define lingo-base() $:/plugins/yourName/pluginName/language/
2023-10-28 12:38:26 +00:00
\whitespace trim
2023-12-15 16:26:55 +00:00
<<translate "OpenInteractiveCard">>
```
2023-12-15 16:26:55 +00:00
!!! 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
2023-12-15 16:26:55 +00:00
title: $:/plugins/yourName/pluginName/language/en-GB/SomeLongText
!!! SubTitle
This is a long text.
```
Later you can use it like:
```tid
title: someTiddler
2023-12-15 16:26:55 +00:00
\define lingo-base() $:/plugins/yourName/pluginName/language/
2023-12-15 17:33:47 +00:00
!! <<translate "OpenInteractiveCard" mode:"inline">>
2023-12-15 16:26:55 +00:00
<<translate "SomeLongText">>
```