Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: t macro and docs #7821

Merged
merged 20 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions core/wiki/macros/lingo.tid
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
title: $:/core/macros/lingo
tags: $:/tags/Macro
tags: $:/tags/Global

\define lingo-base()
<!-- Note that lingo-base should end with a trailing slash character -->
\procedure lingo-base()
$:/language/
\end
\end lingo-base

\define lingo(title)
{{$(lingo-base)$$title$}}
\end
\procedure lingo(title,override-lingo-base)
<!-- Lingo procedure -->
<!-- Get the parse mode used to invoke this procedure -->
<$parameters $parseMode="parseMode">
<!-- Compute the lingo-base-->
<$let active-lingo-base={{{ [<override-lingo-base>!match[]else<lingo-base>] }}}>
<!-- First try the old school <active-lingo-base><title> format -->
<$transclude $tiddler={{{ [<active-lingo-base>addsuffix<title>] }}} $mode=<<parseMode>>>
<!-- If that didn't work, try the new <lingo-base><langcode>/<title> format -->
<$let language-code={{{ [[$:/language]get[text]get[name]else[en-GB]] }}}>
<$transclude $tiddler={{{ [<active-lingo-base>addsuffix<language-code>addsuffix[/]addsuffix<title>] }}} $mode=<<parseMode>>/>
</$let>
</$transclude>
</$let>
</$parameters>
\end lingo
33 changes: 27 additions & 6 deletions editions/tw5.com/tiddlers/macros/LingoMacro.tid
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
caption: lingo
created: 20150221154907000
modified: 20150221155706000
title: lingo Macro
modified: 20231028123405895
tags: Macros [[Core Macros]]
caption: lingo
title: lingo Macro
type: text/vnd.tiddlywiki

The <<.def lingo>> [[macro|Macros]] relates to the translation of ~TiddlyWiki's user interface into other languages. It returns a piece of text in the user's currently selected language.

Translatable text is supplied by language plugins containing tiddlers with specific titles that start with `$:/language/`.
Translatable text is supplied by:

# Language plugins
# Any l10n (localization) strings outside of the language plugins

!! Language plugins

!! Parameters
You can directly pass title to `lingo` macro, when there is a language plugin containing a tiddler with such title that start with `$:/language/`.

;title
: The title of the shadow tiddler that contains the text. The prefix `$:/language/` is added automatically

<<.macro-examples "lingo">>
<<.macro-examples "lingo (for language plugin)">>

!! Any l10n strings

To translate any text that directly placed in user's wiki, instead of in a language plugin, you can set the `lingo-base` variable to teach <<.def lingo>> macro the place to look for.

!!! 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

<<.macro-examples "lingo (for custom base)">>

{{lingo Macro (file structure)}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
created: 20231028120432257
modified: 20240206113509050
tags: [[lingo Macro]] [[Macro Examples]]
title: lingo (for custom base) Macro (Examples)
type: text/vnd.tiddlywiki

\define lingo-base() lingo Macro (custom base examples)/

Given the `\define lingo-base() lingo Macro (custom base examples)/`, this example shows the localizaion key `ExampleKey` being translate to the text in [[lingo Macro (custom base examples)/en-GB/ExampleKey]]:

<$macrocall $name=".example" n="1" eg="""<<lingo ExampleKey>>"""/>

This example shows the `lingo-base` can be set as second parameter:

<$macrocall $name=".example" n="2" eg="""<<lingo ExampleKey "lingo Macro (custom base examples)/">>"""/>

When use lingo macro in a [[Inline Mode WikiText]] like [[list|Lists in WikiText]] or [[title|Headings in WikiText]], the parse mode will be inline, so translated text will be inlined too.

<$macrocall $name=".example" n="3" eg="""# <<lingo ExampleKey>>"""/>

<$macrocall $name=".example" n="4" eg="""!! <<lingo ExampleKey>>"""/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
created: 20231028120526948
modified: 20240206113155142
title: lingo Macro (custom base examples)/en-GB/ExampleKey
type: text/vnd.tiddlywiki

This is the translated text of key "~ExampleKey" under lingo-base `lingo Macro (custom base examples)/` (don't forget the tailing slash `/`)

And is multi-line, if it is translated in the block mode by default. (Become single line if set to inline mode.)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
created: 20231028120432257
modified: 20240206122408606
tags: [[lingo Macro]] [[Macro Examples]]
title: lingo Macro (file structure)

!! Example file structure for [[TiddlyWiki on Node.js]]

!!! Suggested file structure

When developing a plugin, you may want to organize your language files like this on the file system as [[MultiTiddlerFiles]]:

```tree
├── language
│ ├── en-GB
│ │ ├── Translations.multids
│ │ └── SomeLongText.tid
│ └── zh-Hans
│ ├── Translations.multids
│ └── SomeLongText.tid
├── other files
└── plugin.info
```

See [[$:/plugins/tiddlywiki/menubar/tree]] for an example.

!!! Define Multiple Translations in One Tiddler

And the content of `language/en-GB/Translations.multids` may looks like this:

```multids
title: $:/plugins/yourName/pluginName/language/en-GB/

OpenInteractiveCard: Open Interactive Card
OpenStaticCard: Open Static Card
```

Later you can use it like:

```tid
title: someTiddler
caption: <<lingo OpenStaticCard "$:/plugins/yourName/pluginName/language/">>

\define lingo-base() $:/plugins/yourName/pluginName/language/
\whitespace trim

<<lingo OpenInteractiveCard>>
```

!!! 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/language/en-GB/SomeLongText

!!! SubTitle

This is a long text.
```

Later you can use it like:

```tid
title: someTiddler

\define lingo-base() $:/plugins/yourName/pluginName/language/

!! <<lingo "OpenInteractiveCard">>

<<lingo SomeLongText>>
```

Note that lingo macro will use the [[parse mode|WikiText Parser Modes]] in the current position where this procedure is invoked.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
created: 20150221151358000
modified: 20150221160113000
tags: [[lingo Macro]] [[Macro Examples]]
title: lingo Macro (Examples)
title: lingo (for language plugin) Macro (Examples)
type: text/vnd.tiddlywiki

This example shows the text used as the basis for the title of a newly created tiddler:
Expand Down
19 changes: 10 additions & 9 deletions plugins/tiddlywiki/menubar/config.tid
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ tags: $:/tags/ControlPanel/Toolbars
caption: Menu Bar

\define config-base() $:/config/plugins/menubar/MenuItems/Visibility/
\define lingo-base() $:/plugins/tiddlywiki/menubar/language/

! Menu Bar Configuration
! <<lingo Config/Heading1>>

!! Menu Items
!! <<lingo Config/MenuItems/Heading>>

Select which menu items will be shown. You can also drag items to reorder them.
<<lingo Config/MenuItems/Description>>

<$set name="tv-config-toolbar-icons" value="yes">

Expand All @@ -20,18 +21,18 @@ Select which menu items will be shown. You can also drag items to reorder them.

</$set>

!! Breakpoint Position
!! <<lingo Config/BreakpointPosition/Heading>>

The breakpoint position between narrow and wide screens. Should include CSS units (eg. `400px`).
<<lingo Config/BreakpointPosition/Description>>

<$edit-text tiddler="$:/config/plugins/menubar/breakpoint" default="" tag="input"/>

!! Contents Tag
!! <<lingo Config/ContentsTag/Heading>>

The tag for the ~TableOfContents used in the Contents dropdown
<<lingo Config/ContentsTag/Description>>

<$edit-text tiddler="$:/config/plugins/menubar/TableOfContents/Tag" default="" tag="input"/>

!! Menu Bar Colours
!! <<lingo Config/MenuBarColours/Heading>>

To change the colour of the menu bar, define the colours `menubar-foreground` and `menubar-background` in the currently selected palette
<<lingo Config/MenuBarColours/Description>>
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/contents.tid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: $:/plugins/tiddlywiki/menubar/items/contents
caption: Contents
description: Table of Contents
caption: <<lingo Items/TOC/Name $:/plugins/tiddlywiki/menubar/language/>>
description: <<lingo Items/TOC/Description $:/plugins/tiddlywiki/menubar/language/>>
is-dropdown: yes
tags: $:/tags/MenuBar

Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/hamburger.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: $:/plugins/tiddlywiki/menubar/items/hamburger
tags: $:/tags/MenuBar
caption: Hamburger
description: Show the full menu bar on a narrow screen
caption: <<lingo Items/Hamburger/Name $:/plugins/tiddlywiki/menubar/language/>>
description: <<lingo Items/Hamburger/Description $:/plugins/tiddlywiki/menubar/language/>>
custom-menu-content: {{$:/plugins/tiddlywiki/menubar/items/hamburger}}
show-when: narrow

Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/pagecontrols.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: $:/plugins/tiddlywiki/menubar/items/pagecontrols
tags: $:/tags/MenuBar
description: Page controls from the sidebar
caption: Page controls
description: <<lingo Items/PageControls/Name $:/plugins/tiddlywiki/menubar/language/>>
caption: <<lingo Items/PageControls/Name $:/plugins/tiddlywiki/menubar/language/>>
custom-menu-content: <$transclude tiddler="$:/plugins/tiddlywiki/menubar/items/pagecontrols" mode="inline"/>

\whitespace trim
Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/search.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: $:/plugins/tiddlywiki/menubar/items/search
custom-menu-content: {{$:/plugins/tiddlywiki/menubar/items/search}}
description: Search
caption: Search
description: <<lingo Items/Search/Name $:/plugins/tiddlywiki/menubar/language/>>
caption: <<lingo Items/Search/Name $:/plugins/tiddlywiki/menubar/language/>>
tags: $:/tags/MenuBar

\define cancel-search-actions()
Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/server.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: $:/plugins/tiddlywiki/menubar/items/server
tags: $:/tags/MenuBar
description: Server options
caption: Server
description: <<lingo Items/Server/Description $:/plugins/tiddlywiki/menubar/language/>>
caption: <<lingo Items/Server/Name $:/plugins/tiddlywiki/menubar/language/>>
custom-menu-content: <$transclude tiddler="$:/plugins/tiddlywiki/menubar/items/server" mode="inline"/>

<$list filter="[[$:/status/IsLoggedIn]get[text]else[no]match[yes]]" variable="ignore">
Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/sidebar.tid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: $:/plugins/tiddlywiki/menubar/items/sidebar
caption: Sidebar
description: Sidebar
caption: <<lingo Items/Sidebar/Name $:/plugins/tiddlywiki/menubar/language/>>
description: <<lingo Items/Sidebar/Name $:/plugins/tiddlywiki/menubar/language/>>
is-dropdown: yes
tags: $:/tags/MenuBar

Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/topleftbar.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: $:/plugins/tiddlywiki/menubar/items/topleftbar
tags: $:/tags/MenuBar
description: Items from $:/tags/TopLeftBar
caption: Legacy Top Left Bar
description: <<lingo Items/TopLeftBar/Description $:/plugins/tiddlywiki/menubar/language/>>
caption: <<lingo Items/TopLeftBar/Name $:/plugins/tiddlywiki/menubar/language/>>
custom-menu-content: <$transclude tiddler="$:/plugins/tiddlywiki/menubar/items/topleftbar" mode="inline"/>

<$list filter="[all[shadows+tiddlers]tag[$:/tags/TopLeftBar]!has[draft.of]]" variable="listItem" storyview="pop">
Expand Down
4 changes: 2 additions & 2 deletions plugins/tiddlywiki/menubar/items/toprightbar.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: $:/plugins/tiddlywiki/menubar/items/toprightbar
tags: $:/tags/MenuBar
description: Items from $:/tags/TopRightBar
caption: Legacy Top Right Bar
description: <<lingo Items/TopRightBar/Description $:/plugins/tiddlywiki/menubar/language/>>
caption: <<lingo Items/TopRightBar/Name $:/plugins/tiddlywiki/menubar/language/>>
custom-menu-content: <$transclude tiddler="$:/plugins/tiddlywiki/menubar/items/toprightbar" mode="inline"/>
custom-menu-styles-wide: float: right;

Expand Down
25 changes: 25 additions & 0 deletions plugins/tiddlywiki/menubar/language/en-GB/Translations.multids
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
title: $:/plugins/tiddlywiki/menubar/language/en-GB/

Config/Heading1: Menu Bar Configuration
Config/MenuItems/Heading: Menu Items
Config/MenuItems/Description: Select which menu items will be shown. You can also drag items to reorder them.
Config/BreakpointPosition/Heading: Breakpoint Position
Config/BreakpointPosition/Description: The breakpoint position between narrow and wide screens. Should include CSS units (eg. `400px`).
Config/ContentsTag/Heading: Contents Tag
Config/ContentsTag/Description: The tag for the ~TableOfContents used in the Contents dropdown
Config/MenuBarColours/Heading: Menu Bar Colours
Config/MenuBarColours/Description: To change the colour of the menu bar, define the colours `menubar-foreground` and `menubar-background` in the currently selected palette
Items/TOC/Name: Contents
Items/TOC/Description: Table of Contents
Items/Hamburger/Name: Hamburger
Items/Hamburger/Description: Show the full menu bar on a narrow screen
Items/PageControls/Name: Page controls
Items/PageControls/Description: Page controls from the sidebar
Items/Search/Name: Search
Items/Server/Name: Server
Items/Server/Description: Server options
Items/Sidebar/Name: Sidebar
Items/TopLeftBar/Name: Legacy Top Left Bar
Items/TopLeftBar/Description: Items from $:/tags/TopLeftBar
Items/TopRightBar/Name: Legacy Top Right Bar
Items/TopRightBar/Description: Items from $:/tags/TopRightBar
30 changes: 30 additions & 0 deletions plugins/tiddlywiki/menubar/language/en-GB/readme.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
title: $:/plugins/tiddlywiki/menubar/language/en-GB/readme

!! Introduction

This plugin provides a menu bar with the following features:

* Menu items take the form of simple text links, dropdowns, or entirely custom content
* Menu items can be individually enabled via the control panel
* Responds to reduced screen width by abbreviating the menu items to a "hamburger" dropdown

!! Menu Item Tiddlers

Menu items are tagged <<tag $:/tags/MenuBar>>. The following fields are used by this plugin:

|!Field Name |!Purpose |
|title |Each menu item must have a unique title (not shown to the user) |
|description |Description for use in listings |
|tags |Must contain `$:/tags/MenuBar` |
|caption |The text that is displayed for the menu item. Avoid links, using `~` to suppress CamelCase links if required |
|target |For simple link menu items specifies a tiddler title as the target of the link |
|is-dropdown |Set to `yes` to indicate a dropdown menu item |
|dropdown-position |Optional position for the dropdown (can be ''left'', ''above'', ''aboveleft'', ''aboveright'', ''right'', ''belowleft'', ''belowright'' or ''below'') |
|text |For dropdown menu items, specifies the body of the dropdown |
|custom-menu-content |Optional wikitext to be displayed in place of the caption |
|custom-menu-styles-wide |Optional string of styles to be applied to menu item when the menubar is wide |
|custom-menu-styles-narrow |Optional string of styles to be applied to menu item when the menubar is narrow |

Custom menu items should make sure that the clickable link or button is an immediate child, and not wrapped in another element.

Note that menu items can be pushed to the right of the menu bar setting the ''custom-menu-styles'' field to `float: right;`.
25 changes: 25 additions & 0 deletions plugins/tiddlywiki/menubar/language/zh-Hans/Translations.multids
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
title: $:/plugins/tiddlywiki/menubar/language/zh-Hans/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@linonetwo .. It seems the translations are part of the plugin here. That's not what users want. I personally do not want to carry 32 translations with every core plugin, since I do only need 2 or 3 at most.

As a user I do expect them to be added individually

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move them to a new sub-plugin, like codemirror's, and sub-plugin add tiddlers to parent plugin's path.

I can move zh-Hans translations to a sub-plugin, only leave en-GB here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not that big. If this is not very necessary, I can leave it to next PR. I may be busy on https://github.com/tiddly-gittly/TidGi-Mobile these days.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmario while I understand your position on this, I do not think that it is the way that we should go.

The architecture developed here will work with translations that are integral or are packaged as a separate plugin. For the core plugins, I do not think it is acceptable to expose a separate plugin for each translation of the menu bar. I think there are two viable options:

  • Place the translations for the core plugins in the associated language plugin. So the fr-FR plugin would contain the French core translations, and those for the menu bar plugin etc.
  • Place the translations for the core plugins within the plugin itself

The key point here is that the usability of keeping translations together absolutely trumps any phantom concerns about saving a few hundred bytes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key point here is that the usability of keeping translations together absolutely trumps any phantom concerns about saving a few hundred bytes.

It's not a view hundred bytes.

menubar has about 1400Byte of text x 32 languages atm is about 45kByte of language related text.
The plugin itself is exported as JSON has 25kByte. So the plugin-size will be almost tripled.
Since the goal may be to have more translations, it will be worse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmario I think Jeremy means if it is big enough, we can still move them out, but not placed in sub-plugin -- place them in core language plugin instead -- for core plugins. I can try this later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

menubar has about 1400Byte of text x 32 languages atm is about 45kByte of language related text.
The plugin itself is exported as JSON has 25kByte. So the plugin-size will be almost tripled.
Since the goal may be to have more translations, it will be worse.

I do not see that as a problem. It's very hard to put together a plausible argument that that extra 25KB has any meaningful impact on anything. We have to make things easier for the majority, and not burden all users with an additional cognitive burden for the benefit of a small group.


Config/Heading1: 菜单栏配置
Config/MenuItems/Heading: 菜单项
Config/MenuItems/Description: 选择要显示的菜单项。您还可以通过拖动项目来重新排序。
Config/BreakpointPosition/Heading: 响应式断点位置
Config/BreakpointPosition/Description: 窄屏和宽屏之间的分界点位置。应包含 CSS 单位(如 `400px`)。
Config/ContentsTag/Heading: 内容标签
Config/ContentsTag/Description: 内容下拉菜单中使用的 TOC 目录标签
Config/MenuBarColours/Heading: 菜单栏颜色
Config/MenuBarColours/Description: 要更改菜单栏的颜色,请在当前选定的调色板中定义颜色 `menubar-foreground` 和 `menubar-background`。
Items/TOC/Name: 内容
Items/TOC/Description: 目录
Items/Hamburger/Name: 抽屉
Items/Hamburger/Description: 在窄屏幕上显示完整的菜单栏
Items/PageControls/Name: 页面控件
Items/PageControls/Description: 来自侧边栏的页面控件
Items/Search/Name: 搜索
Items/Server/Name: 服务器
Items/Server/Description: 服务器选项
Items/Sidebar/Name: 侧边栏
Items/TopLeftBar/Name: 旧版左上角栏
Items/TopLeftBar/Description: 来自 $:/tags/TopLeftBar 的项目
Items/TopRightBar/Name: 旧版右上角栏
Items/TopRightBar/Description: 来自 $:/tags/TopRightBar 的项目
Loading
Loading