Semanticmediawiki: Multilingual ask queries

Created on 8 May 2019  路  10Comments  路  Source: SemanticMediaWiki/SemanticMediaWiki

In reference to https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/594 and https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/1621 a lot has been achieved already in order to provide possibilities of handling multilingual content in SMW.

However after some research I guess there are still some things left to do, especially regarding ask queries.

Feature request

The following elements of an ask query cannot be constructed in a multilingual way:

|mainlabel
|searchlabel
|default
maybe also |intro |outro

Use case

Imagine a simple output in a table format. All the property names in the table header will be shown in the users preferred language once they are set up using "Has preferred property label". Only the mainlabel will stay in whatever language the ask query is constructed.

Suggestion

What if we add the @en capability to ask quers like so
|mainlabel=books@en,B眉cher@de
This solution will work well if only a handful of languages are supported, which I guess is very common. However, you might end up with very long ask queries this way.

Another, more generic way could be to define properties to be used. E. g. [[Property:Books]] where we can reuse the "Has preferred property label" elements? Then we could write
|mainlabel=[[Property:Books]]
indicating that the label for the mainlabel should be retrieved from the "Has preferred property label" setting in the users language.
Or even shorter
|mainlabel=Books
where SMW would simply write "Books" if no Property:Books is present or no preferred property label is defined or take the preferred property label as soon as this property is defined.

question

Most helpful comment

To me, like @mwjames said, it seems like using {{int:}} does the job (in combination with the Universal Language Selector extension and {{CONTENTLANGUAGE}} and {{PAGELANGUAGE}} parser functions). At least is what I did in my wiki. See [0], then, click on the ULS and change to Fran莽ais, for instance. Look how "Author", "Subject", "Date of publication" and "Language" become "Auteur", "Sujet", "Date de publication" and "Langue" in the filtered format filters. In [1] you can see the ask queries using {{int:wikincat-author}}, {{int:wikincat-subject}}, etc.

Note: This was made long before SMW have "Has preferred property label" and the "Monolingual text" datatype.

[0] http://wikincat.org/wiki/Wikis_(Ci锚ncia_da_computa莽茫o)
[1] http://wikincat.org/w/index.php?title=Template:Subject&action=edit

All 10 comments

In combination with the Translate extension we already to multilingual queries on smw.o. See here. I think we/I also tested multilingual queries depending on the logged in users language somewhere. There you also need the {{UILANGCODE}} magic word or the alternative to it (forgot what it is called). Cannot find the spot right now.

|mainlabel
|searchlabel
|default
maybe also |intro |outro

Those mentioned identifiers are manipulators for string elements and have no direct relation to a property therefore connection them to a "preferred property label" to construct an output depending on a language context is unlikely the correct approach. Instead you should rely on {{int: message-key}} (which also can be a key in the local MediaWiki NS) [0] to produce an language depending output.

{{#ask: [[Has number::+]]
 |?Has number
 |mainlabel={{int:local-mainlabel}}
 |intro={{int:local-intro}}
 |limit=5
 |searchlabel={{int:local-intro}}
}}

If for some reason you wanted to facilitated the preferred property label as part of one of those string representations then using @@@ [1, 2] as part of a string output generation could be an option.

 |mainlabel=[[Has number::@@@ja]]
 |intro=[[Has number::@@@en]]

Or even shorter
|mainlabel=Books
where SMW would simply write "Books" if no Property:Books is present or no
preferred property label is defined or take the preferred property label as
soon as this property is defined.

I'm no particular supporter of implicit magic because the code that handles those cases normally becomes convoluted and will be hard to maintain in future.

[0] https://www.mediawiki.org/wiki/Help:Magic_words#Localisation
[1] https://www.semantic-mediawiki.org/wiki/Help:Property_links
[2] https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/2049

Thank you for your reply. Interesting, I wasn't even aware of [0].

To make things clearer, I will try to elaborate on my use case. I'll leave the design of a possible soution to you ;-)

The use case is simply that a multi-lingual community will work in a single wiki. This does NOT mean, that there will be a wiki translated in every language of the users. It might mean, though, that a french person will switch his or her interface language to french in order to have as much french as he can in the wiki.

So these French, German and Chinese researchers are putting together content in a wiki. With all the language features in place, I am able to very well have preferred labels for almost everything except the mainlabel.

So what can I do? I was thinking about re-using features available already without having to implement an environment with a usecase of fully multilingual content in a wiki (aka translaton extension).

Version 1 would be as described above to do it in the ask quer itself. I agree, tis is not the best solution.
Version 2 would be (just came to my mind) to specify this. e. g. on Category Pages.

What about the following:
Let us define a new property: "has preferred mainlabel". So I set a similar property that I would on a property page now on a category page.

In my aks query, I can still do
|mainlabel=Books and Documents
if I wish to manually override the setting, but if I don't specify anything, SMW would show the string defined for the language as main label text.

This would be very transparent for all users. It would not give me the freedom to change this on every single ask query, but at least I can define this on every content category what the meaning of the mainlabel column is.

So for all pages that I enter in the category "Books", I could have the preferred label "B眉cher" if I select German as interface language for the mainlabel.

Hence I could also think of a property "has preferred searchlabel", that I could set as "please let me see even more books" in English and accordingly in other languages.

In my aks query, I can still do
|mainlabel=Books and Documents
if I wish to manually override the setting, but if I don't specify anything, SMW would show the string defined for the language as main label text.

Just to be clear (without having read the entire thread), SMW will __not__ provide any magic to the mainlabel as it only represents a simple string label. A user is free to add any text in any form s(he) prefers by relying on some parser function or template substitution but for SMW, the mainlabel is nothing more than a label and has no connection to a property or property instance.

You may write a parser function (or use int:) to construct the string you need in the mainlabel such as:

{{#ask: [[Condition::foo]]
 |?Foo
 |?Bar
 |mainlabel={{my_parser_function: generate some text from ...}}
}}

{{my_parser_function: generate some text from ...}} may fetch information from a property or some arbitrary source but this has nothing to do with SMW as far as it concerns the construction of the query and its output. my_parser_function may detect the interface language and switch the text it generates but all this happens outside of SMW and its responsibility to construct a query.

my_parser_function may detect the interface language and switch the text it generates but all this happens outside of SMW and its responsibility to construct a query.

Having said above doesn't prevent someone to write a {{property: ...}} parser function in SMW core to provide access to information about a property (label, description etc.) but that would be orthogonal to the initial topic of constructing a #ask with language dependent labels. {{property: ...}} as an accessor could be leveraged in a query (and hereby the mainlabel, intro etc.) but making that a non-specialized solution that can provision benefits elsewhere by being unbound to #ask.

To me, like @mwjames said, it seems like using {{int:}} does the job (in combination with the Universal Language Selector extension and {{CONTENTLANGUAGE}} and {{PAGELANGUAGE}} parser functions). At least is what I did in my wiki. See [0], then, click on the ULS and change to Fran莽ais, for instance. Look how "Author", "Subject", "Date of publication" and "Language" become "Auteur", "Sujet", "Date de publication" and "Langue" in the filtered format filters. In [1] you can see the ask queries using {{int:wikincat-author}}, {{int:wikincat-subject}}, etc.

Note: This was made long before SMW have "Has preferred property label" and the "Monolingual text" datatype.

[0] http://wikincat.org/wiki/Wikis_(Ci锚ncia_da_computa莽茫o)
[1] http://wikincat.org/w/index.php?title=Template:Subject&action=edit

Thank you for the great example!

I didn't make the connection from {{int:message name}} to user-defined interface messages.

I was wondering why I did not come up with the int parser function since I am using this one on wikis myself. I did not use this approach on smw.o since I do not like to grant a whole bunch of people admin permissions and create yet another user group to manage.

Anyways, I just referenced this question on smw.o

@krabina It will be utterly great if you could set up an example on sandbox to link to from the page mentioned above.

I am planning to write an easy to use Help page on SMW.org...

I am planning to write an easy to use Help page on SMW.org...

Cool. Supplementing this with a life example ... :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mwjames picture mwjames  路  3Comments

mwjames picture mwjames  路  3Comments

WolfgangFahl picture WolfgangFahl  路  3Comments

alex-mashin picture alex-mashin  路  4Comments

simontaurus picture simontaurus  路  3Comments