From 689ad53accc83d00b5a521ba4bf8ca9e36109f4e Mon Sep 17 00:00:00 2001 From: Leilei332 Date: Fri, 7 Nov 2025 19:47:59 +0800 Subject: [PATCH] Update docs & add language code validation --- core/modules/wiki.js | 3 ++- editions/tw5.com/tiddlers/Locale Example.tid | 4 ++-- editions/tw5.com/tiddlers/filters/examples/sort.tid | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 551595c8e..30bc5feb4 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -371,6 +371,7 @@ Sort an array of tiddler titles by a specified field */ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric,isAlphaNumeric,locale) { var self = this; + locale = $tw.utils.checkLanguageCode(locale) ? locale : undefined; if(sortField === "title") { if(!isNumeric && !isAlphaNumeric) { if(isCaseSensitive) { @@ -380,7 +381,7 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is }); } else { titles.sort(function(a,b) { - return a.localeCompare(b); + return a.localeCompare(b, locale); }); } } else { diff --git a/editions/tw5.com/tiddlers/Locale Example.tid b/editions/tw5.com/tiddlers/Locale Example.tid index 61555eb7c..981d11e70 100644 --- a/editions/tw5.com/tiddlers/Locale Example.tid +++ b/editions/tw5.com/tiddlers/Locale Example.tid @@ -1,6 +1,6 @@ created: 20251001034405510 -list: A a Ä ä Z z -modified: 20251001034911337 +list: A a Ä ä Z z I ı İ i Ö ö Ü ü +modified: 20251107113112003 tags: title: Locale Example type: text/vnd.tiddlywiki \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/examples/sort.tid b/editions/tw5.com/tiddlers/filters/examples/sort.tid index 8f94d7f1a..ba1507660 100644 --- a/editions/tw5.com/tiddlers/filters/examples/sort.tid +++ b/editions/tw5.com/tiddlers/filters/examples/sort.tid @@ -1,5 +1,5 @@ created: 20150124112340000 -modified: 20251001034921899 +modified: 20251107113531458 tags: [[sort Operator]] [[Operator Examples]] title: sort Operator (Examples) type: text/vnd.tiddlywiki @@ -11,5 +11,10 @@ type: text/vnd.tiddlywiki <<.operator-example 3 "one two Three four +[sort[]]">> <<.operator-example 4 "[prefix[Tiddl]sort[text]]">> <<.operator-example 5 "[has[created]sort[created]limit[10]]" "the oldest 10 tiddlers in the wiki">> -<<.operator-example 6 "[list[Locale Example]sort[],[de]]">> + +! Using a custom locale +The following examples shows the differences when using the sort operator with default, Swedish and Turkish locale. + +<<.operator-example 6 "[list[Locale Example]sort[]]">> <<.operator-example 7 "[list[Locale Example]sort[],[sv]]">> +<<.operator-example 8 "[list[Locale Example]sort[],[tr]]">>