Hi @FRDV,
do you have also an idea to select the filter from the $./language setting?
My target is that the user select only once the language and the content will be selected automatically.
Stefan
Hi @FRDV,
do you have also an idea to select the filter from the $./language setting?
My target is that the user select only once the language and the content will be selected automatically.
Stefan
Hi @telumire,
good idea, but my target is that the user select only once the language and the content will be selected automatically.
Stefan
I’m searching a solution, right now I have this :
<$list filter="[all[tiddlers+system+shadows]field:plugin-type/language/] +[removeprefix[$:/languages/]]" variable="available-languages">
<<available-languages>>
</$list>
You might also have a look at $:/snippets/languageswitcher
Hi @FRDV,
Excellent! This is separating the right name of the field.
How to get it in “{{ }}” brakets to get the content from the “Tiddler name” in the field?
I think there will be a solution
Stefan
hi @stefan_from_germany I believe this is a job for ViewTemplate cascades:
Create a tiddler tagged with $:/tags/ViewTemplateBodyFilter
, with the following text field:
[fields[]]
:filter[{$:/language}removeprefix[$:/languages/]match<currentTiddler>]
:map[<..currentTiddler>get<currentTiddler>]
and a list-before
field with an empty value.
That should be enough to fulfill your purpose:
list-before
field puts your filter tiddler on top of the cascadeFinally I made it!
Create a field for each language you have a translation
field de-DE
value Tiddler (Deutsch)
field en-GB
value Tiddler (English)
field fr-FR
value Tiddler (Français)
NOTE:
use the dash - between the letters, not the underscore _
[[$:/languages/en-GB]]
at the beginning of the filter forces the default language in the list
<$list filter="[[$:/languages/en-GB]] [all[tiddlers+system+shadows]field:plugin-type/language/] +[removeprefix[$:/languages/]]" variable="available-languages">
<<available-languages>> <!-- for demo purpose -->
<$list filter="[<currentTiddler>has<available-languages>get<available-languages>]" variable="thislanguage" >
<$transclude tiddler=<<thislanguage>> />
</$list>
</$list>
Code works in the Tiddler (Whatever)
Have fun!
Added emptyMessage="no translation"
, just for the fun of it
<$list filter="[[$:/languages/en-GB]] [all[tiddlers+system+shadows]field:plugin-type/language/] +[removeprefix[$:/languages/]]" variable="available-languages">
<<available-languages>> <!-- for demo purpose -->
<$list filter="[<currentTiddler>has<available-languages>get<available-languages>]" emptyMessage="no translation" variable="thislanguage" >
<$transclude tiddler=<<thislanguage>> />
</$list>
</$list>
Hi @FRDV,
thank you for your support.
What is ti I am doing wrong here.
I only want to see der german or english tiddler. Not all of them
Here is the code i am using
<$list filter="[[$:/languages/en-GB]] [all[tiddlers+system+shadows]field:plugin-type/language/] +[removeprefix[$:/languages/]]" variable="available-languages">
<$list filter="[<currentTiddler>has<available-languages>get<available-languages>]" emptyMessage="no translation" variable="thislanguage" >
<$transclude tiddler=<<thislanguage>> />
</$list>
</$list>
And here the result
This is English
Dies ist Deutsch
So both Tiddlers are displayed not only the one of the setting in language.
Can you help me here to change it to display only the right tiddler?
Stefan
Hi Stefan
For the languages you don’t want to see you only have to:
Hi @FRDV,
hopefully not
What I am looking for is, the possibility if a user is switching from english to german (or an other language), the content will change automatically, not to have all available langauges displayed the same time.
Is that possible?
Thx
Stefan
This should do the trick
<$list filter="[{$:/language!!text}] +[removeprefix[$:/languages/]]" variable="available-languages">
<$list filter="[<currentTiddler>has<available-languages>get<available-languages>]" emptyMessage="no translation for {{$:/language}}" variable="thislanguage" ><$transclude tiddler=<<thislanguage>> />
</$list>
</$list>
EDIT: changed the emptyMessage to indicate the language of a missing translation
NOTES:
you can change
{$:/language!!text}
to {$:/language}
(same thing but shorter)available-languages
to available-language
(because there is only one language)Core feature: feat: t macro and docs by linonetwo · Pull Request #7821 · Jermolene/TiddlyWiki5 · GitHub
Just use lingo precedure, see Docs in Preview site
filter="[[$:/language]get[text]get[name]else[en-GB]]"
Nice!
I saw that field name
in $:/languages/
but somehow I was too focused on removing the prefix that I didn’t use it! Seems I did it the hard way
Question:
In this code below
<$set name="lang" filter="[[$:/language]get[text]get[name]else[en-GB]]" select="0">
<<lang>>
</$set>
what is the use of select="0"
?
<$set name="lang" filter="[[$:/language]get[text]get[name]else[en-GB]]" >
<<lang>>
</$set>
Whatever language I select in control panel I get the same result: the name of the selected language
I have already looked at that before and I don’t understand how the lingo procedure works, the given example are very obscure to me.
Someday I will have a closer look under the hood.
Thank you for your advices.
Hi @xcazin,
I was not able to reproduce your solution.
Here is the result tiddler:
de-DE: Tiddler (Deutsch)
en-GB: Tiddler (English)
tags: $:/tags/ViewTemplateBodyFilter
title: Result 1
[fields[]]
:map[{$:/language}removeprefix[$:/languages/]match<currentTiddler>]
:and[!is[blank]]
:map[<..currentTiddler>get<currentTiddler>]
And this is the returned (screenshot)
Stefan
SUMMARY OF SOLUTION!!!
This is the RESULT TIDDLER
de-DE: Tiddler (Deutsch)
en-GB: Tiddler (English)
modified: 20240521215629308
modifier: myself
tags:
title: Result
<$list filter="[{$:/language}] +[removeprefix[$:/languages/]]" variable="selected-language">
<$list filter="[<currentTiddler>has<selected-language>get<selected-language>]" emptyMessage="no translation for {{$:/language}}" variable="thislanguage" ><$transclude tiddler=<<thislanguage>> />
</$list>
</$list>
This is the tiddler containing the german content
created: 20240515103643289
creator: myself
modified: 20240521213929186
modifier: myself
tags:
title: Tiddler (Deutsch)
Dies ist Deutsch!
This is the tiddler containing the english content
created: 20240515103657992
creator: myself
modified: 20240516073520956
modifier: myself
tags:
title: Tiddler (English)
This is English
If you switch the language now the content in the “Tiddler /(Deutsch)” or “Tiddler (English)” will be shown.
For me it is acceptable nevertheless that the title, date and author information will not be displayed if the language will be switched.
Special thanks to @FRDV
Stefan
You’ll need to wrap that filter in something, a text widget, or {{{ ... }}}
.
From the code, I thought that was the goal. I must admit I haven’t read everything thoroughly, but it looked as though you wanted to use the various fields in the current tiddler along with the $:/language
tiddler to choose which content to show, which is precisely what this does.
But it seems you want to grab the text of a tiddler. You can just extend it with get[text]
"
{{{ [fields[]]
:map[{$:/language}removeprefix[$:/languages/]match<currentTiddler>]
:and[!is[blank]]
:map[<..currentTiddler>get<currentTiddler>get[text]] }}}
<!-- ^^^^^^^^^ -->
Hi @stefan_from_germany, the beauty of ViewTemplate cascades is that once you figure out the right filter, you don’t have to modify the tiddlers in your story: they display automagically the way you want.
In the site below, I’ve embedded the very tiddlers of your original post (I couldn’t resist to add an fr-FR field to your Result tiddler, but they are otherwise unchanged), plus my (simplified) cascade filter tiddler, plus a few payload tiddlers to show how ViewTemplate cascades solve your problem in a generic way.
Note that it is also possible to use the ViewTemplate cascade mecanism to localise the display of the title as well. For this, the magic tag to use is $:/tags/ViewTemplateTitleFilter. As an example, I’ve added a filter tiddler that calls a template Template for localised title substitution to replace the Result title if the content tiddlers have a localised title
field.
In both cases, the underlying tiddler Result is never modified: only the way it is viewed in the story river.