From 9c09841eda0e796a56fe855db5d628c242ba838c Mon Sep 17 00:00:00 2001 From: XLBilly Date: Wed, 4 Feb 2026 19:21:54 +0800 Subject: [PATCH] Make draft title translatable (#8891) * Make draft title translatable * Update change note * Improve number handling Now generates "Draft of '...' 2" instead of "Draft 2 of '...'" * Improve whitespace handling We no longer needs to add whitespace in languages. We now handle it in javascript. * Update language naming * Update zh-Hans translation * Update change note * Refactor logic to make it less complex Since we don't need to care about draft numbers, we can have two different templates for draft title with and without attribution. No need to trim the string now. Also, we can reuse the getSubstitutedText method * Update translators edition * fixup! Update translators edition * Switch to transclude and variable mechanism * Adapt translators to the new mechanism * Update change note * Further simplify the logic $tw.language.getString can already wikify translatable strings. No need for this.renderText --- core/language/en-GB/Draft.multids | 4 +++ core/modules/wiki.js | 12 ++++---- .../tiddlers/Instructions for Translators.tid | 1 + .../tiddlers/system/$__status_UserName.tid | 3 ++ editions/translators/tiddlywiki.info | 1 + .../releasenotes/5.4.0/draft-i18n.tid | 15 ++++++++++ languages/zh-Hans/Draft.multids | 4 +++ .../output-file-templates/Draft.multids.tid | 3 ++ .../output-file-templates/Misc.multids.tid | 1 + .../tiddlywiki/translators/ui/group/Draft.tid | 28 +++++++++++++++++++ .../translators/ui/group/Miscellaneous.tid | 1 + 11 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 core/language/en-GB/Draft.multids create mode 100644 editions/translators/tiddlers/system/$__status_UserName.tid create mode 100644 editions/tw5.com/tiddlers/releasenotes/5.4.0/draft-i18n.tid create mode 100644 languages/zh-Hans/Draft.multids create mode 100644 plugins/tiddlywiki/translators/output-file-templates/Draft.multids.tid create mode 100644 plugins/tiddlywiki/translators/ui/group/Draft.tid diff --git a/core/language/en-GB/Draft.multids b/core/language/en-GB/Draft.multids new file mode 100644 index 000000000..5fc50f115 --- /dev/null +++ b/core/language/en-GB/Draft.multids @@ -0,0 +1,4 @@ +title: $:/language/Draft/ + +Attribution: Draft of '<>' by {{$:/status/UserName}} +Title: Draft of '<>' \ No newline at end of file diff --git a/core/modules/wiki.js b/core/modules/wiki.js index ccf782396..0100e4600 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1664,12 +1664,14 @@ exports.addToStory = function(title,fromTitle,storyTitle,options) { Generate a title for the draft of a given tiddler */ exports.generateDraftTitle = function(title) { - var c = 0, - draftTitle, - username = this.getTiddlerText("$:/status/UserName"), - attribution = username ? " by " + username : ""; + let c = 0, + draftTitle; + const username = this.getTiddlerText("$:/status/UserName"); do { - draftTitle = "Draft " + (c ? (c + 1) + " " : "") + "of '" + title + "'" + attribution; + draftTitle = username ? $tw.language.getString("Draft/Attribution", {variables: {"draft-title": title}}) : $tw.language.getString("Draft/Title", {variables: {"draft-title": title}}); + if(c) { + draftTitle = draftTitle.concat(" ", (c + 1).toString()); + } c++; } while(this.tiddlerExists(draftTitle)); return draftTitle; diff --git a/editions/translators/tiddlers/Instructions for Translators.tid b/editions/translators/tiddlers/Instructions for Translators.tid index 11d2c7dd5..d3927f106 100644 --- a/editions/translators/tiddlers/Instructions for Translators.tid +++ b/editions/translators/tiddlers/Instructions for Translators.tid @@ -48,6 +48,7 @@ Prioritise the groups to translate first. A translation can be useful without be * Buttons * Control Panel * Date +* Draft * Edit Template * Getting Started * Import diff --git a/editions/translators/tiddlers/system/$__status_UserName.tid b/editions/translators/tiddlers/system/$__status_UserName.tid new file mode 100644 index 000000000..0dd5451f9 --- /dev/null +++ b/editions/translators/tiddlers/system/$__status_UserName.tid @@ -0,0 +1,3 @@ +title: $:/status/UserName + +Jermolene diff --git a/editions/translators/tiddlywiki.info b/editions/translators/tiddlywiki.info index 7fd405642..7c9ea3961 100644 --- a/editions/translators/tiddlywiki.info +++ b/editions/translators/tiddlywiki.info @@ -51,6 +51,7 @@ "--render","$:/plugins/tiddlywiki/translators/templates/ControlPanel.multids","language/ControlPanel.multids","text/plain", "--render","$:/plugins/tiddlywiki/translators/templates/CoreReadMe.tid","language/CoreReadMe.tid","text/plain", "--render","$:/plugins/tiddlywiki/translators/templates/Dates.multids","language/Dates.multids","text/plain", + "--render","$:/plugins/tiddlywiki/translators/templates/Draft.multids","language/Draft.multids","text/plain", "--render","$:/plugins/tiddlywiki/translators/templates/EditTemplate.multids","language/EditTemplate.multids","text/plain", "--render","$:/plugins/tiddlywiki/translators/templates/Exporters.multids","language/Exporters.multids","text/plain", "--render","$:/plugins/tiddlywiki/translators/templates/Fields.multids","language/Fields.multids","text/plain", diff --git a/editions/tw5.com/tiddlers/releasenotes/5.4.0/draft-i18n.tid b/editions/tw5.com/tiddlers/releasenotes/5.4.0/draft-i18n.tid new file mode 100644 index 000000000..794f6aa9c --- /dev/null +++ b/editions/tw5.com/tiddlers/releasenotes/5.4.0/draft-i18n.tid @@ -0,0 +1,15 @@ +title: $:/changenotes/5.4.0/#8891 +description: Draft title internationalization +release: 5.4.0 +tags: $:/tags/ChangeNote +change-type: enhancement +change-category: internal +github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/8891 +github-contributors: Leilei332 + +The title of the draft tiddler is now translatable. These new language strings are provided: + +* `$:/language/Draft/Title` The template of the title of a draft tiddler without attribution. The `draft-title` variable represents the title of the new tiddler. +* `$:/language/Draft/Attribution` The template of the title of a draft tiddler without attribution. + +The translators plugin is also updated. \ No newline at end of file diff --git a/languages/zh-Hans/Draft.multids b/languages/zh-Hans/Draft.multids new file mode 100644 index 000000000..5833bf2bc --- /dev/null +++ b/languages/zh-Hans/Draft.multids @@ -0,0 +1,4 @@ +title: $:/language/Draft/ + +Attribution: {{$:/status/UserName}}撰写的“<>”的草稿 +Title: “<>”的草稿 \ No newline at end of file diff --git a/plugins/tiddlywiki/translators/output-file-templates/Draft.multids.tid b/plugins/tiddlywiki/translators/output-file-templates/Draft.multids.tid new file mode 100644 index 000000000..52352b8fd --- /dev/null +++ b/plugins/tiddlywiki/translators/output-file-templates/Draft.multids.tid @@ -0,0 +1,3 @@ +title: $:/plugins/tiddlywiki/translators/templates/Draft.multids + +{{$:/language/Draft/||$:/plugins/tiddlywiki/translators/templates/multids}} \ No newline at end of file diff --git a/plugins/tiddlywiki/translators/output-file-templates/Misc.multids.tid b/plugins/tiddlywiki/translators/output-file-templates/Misc.multids.tid index 43ec9daf8..2d7c7a2d6 100644 --- a/plugins/tiddlywiki/translators/output-file-templates/Misc.multids.tid +++ b/plugins/tiddlywiki/translators/output-file-templates/Misc.multids.tid @@ -4,6 +4,7 @@ title: $:/plugins/tiddlywiki/translators/templates/Misc.multids -[all[tiddlers]prefix[$:/language/Buttons/]] -[all[tiddlers]prefix[$:/language/ControlPanel/]] -[all[tiddlers]prefix[$:/language/Date/]] +-[all[tiddlers]prefix[$:/language/Draft/]] -[all[tiddlers]prefix[$:/language/Docs/]] -[all[tiddlers]prefix[$:/language/EditTemplate/]] -[all[tiddlers]prefix[$:/language/Exporters/]] diff --git a/plugins/tiddlywiki/translators/ui/group/Draft.tid b/plugins/tiddlywiki/translators/ui/group/Draft.tid new file mode 100644 index 000000000..3a9f798ba --- /dev/null +++ b/plugins/tiddlywiki/translators/ui/group/Draft.tid @@ -0,0 +1,28 @@ +title: $:/plugins/tiddlywiki/translators/ui/group/Draft +caption: Draft +tags: $:/tags/TranslationGroup + +\procedure translatableTiddlerTitles() +[all[tiddlers+shadows]prefix[$:/language/Draft/]] ++[sort[title]] +\end +\procedure shortenTitle() +[all[current]removeprefix[$:/language/Draft/]] +\end + +! Draft + +Template for the title of draft tiddlers. + +Substitution result: + +<$let draft-title="Motovun Jack"> +<$wikify name="draft-with-attribution" text={{$:/language/Draft/Attribution}} output="text"> +<$wikify name="draft-without-attribution" text={{$:/language/Draft/Title}} output="text"> +<$codeblock code=<>/> +<$codeblock code=<>/> + + + + +<> diff --git a/plugins/tiddlywiki/translators/ui/group/Miscellaneous.tid b/plugins/tiddlywiki/translators/ui/group/Miscellaneous.tid index 19b640032..dcf092023 100644 --- a/plugins/tiddlywiki/translators/ui/group/Miscellaneous.tid +++ b/plugins/tiddlywiki/translators/ui/group/Miscellaneous.tid @@ -6,6 +6,7 @@ tags: $:/tags/TranslationGroup [all[tiddlers+shadows]prefix[$:/language/]] -[all[tiddlers+shadows]prefix[$:/language/Buttons/]] -[all[tiddlers+shadows]prefix[$:/language/ControlPanel/]] +-[all[tiddlers+shadows]prefix[$:/language/Draft/]] -[all[tiddlers+shadows]prefix[$:/language/Date/]] -[all[tiddlers+shadows]prefix[$:/language/Docs/]] -[all[tiddlers+shadows]prefix[$:/language/EditTemplate/]]