Field selection by $:/language

  1. first link you gave

filter="[[$:/language]get[text]get[name]else[en-GB]]"

Nice!

:hot_face: 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 :laughing:

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 :thinking:

  1. second link

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.

1 Like

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

  1. The RESULT tiddler has fields named in the same way as the selected language for translated content.
    1a. Field en-GB : Tiddler (English)
    1b. Field de-DE : Tiddler (Deutsch)
  2. The content itself is available in different tiddlers.
    2a. German content stored in Tiddler (Deutsch)
    2b. English content stored in Tiddler (English)

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 :pray:
Stefan

You’ll need to wrap that filter in something, a text widget, or {{{ ... }}}.

Hi @Scott_Sauyet,

If I do this this is the result:
image

Stefan

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.

  1. Go to the demo site with relevant tiddlers.
  2. See how the ViewTemplate cascade found out that the current language was de-DE and changed the ViewTemplate of the Result tiddler accordingly
  3. Use the side bar to switch between languages
  4. Go to the ControlPanel to see the new ViewTemplateBodyFilter tiddler on top of the cascade.

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.

1 Like