In the Semantic Web, every object of interest has a URI, a unique identifier. These URIs can be resolved in order to look up more data about the object, for example its label in different languages.
This is exactly what qLabel does. These labels are then used to replace the text content of the annotated element, when so requested by the user.
One frequent issue with the approach sketched above is that resolving every single URI one after the other simply takes a lot of time and resources. qLabel provides a mechanism to register different loaders, and even three example loaders (for Wikidata, Freebase, and the fallback Semantic Web loader). These loaders can be implemented much more efficiently (e.g. the Wikidata and Freebase loaders cut down the number of web requests by an order of magnitude and more). They also don't require the rdfquery library, so that you don't have to parse RDF/XML in the browser, which could further reduce your footprint.
The qLabel library adds the
$.qlabel object that has the
following public interface.
Sets the language to
lang (which is a ISO 639 language code)
and changes the displayed text on the Website.
It will first gather all annotating URIs from all elements that have class
qlabel, check if these URIs are already known,
load the unknown ones, and once they are all loaded, the text content of the
elements changes if a label in the requested language exists.
The function returns a
promise that will resolve once the
language has switched.
Returns the ISO 639 language code that was set last.
Sets the class name used to find the elements that should be translated.
The default class name is
Returns the class name used to find the elements that should be translated
which was set last or
qlabel if nothing was set.
Returns a label for the requested URI and language. If the URI is unknown,
or if there is no label for the specified language for the requested URI,
undefined is returned.
Returns an object where the keys are the language codes and the values
are the labels, for the requested URI. If the URI is unknown,
undefined will be returned.
Provide qLabel with a Label for the given URI and language. Now, the URI
is known (and will not be loaded when calling
setLabel can be used to set the labels manually and not load
the labels for every user, and can thus safe resources.
The parameter is optional. URIs is a list of URIs for which labels
will be loaded. If they are already known, they will not be loaded.
If URIs is empty, all annotating URIs on elements with the class
qlabel will be loaded.
The function returns a
promise that will be resolved
once the labels are loaded.
Returns an array with all URIs that are known.
Sets a loader. A loader consists of two functions, a
The tester takes a single string and
returns a (possibly normalized) string if the loader is able to load the
given URI (and returns
The loader takes an array of strings that the loader will load.
The loader should use the
setLabel function to set all loaded
labels, and return a promise which will be resolved once the loader is finished.
There are three loaders already available: a Freebase loader, a Wikidata loader, and a generic Semantic Web loader using Linked Data principles.
Sets the Google Freebase API key to be used when calling Freebase.
Returns the previously set Google Freebase API key, or an empty string if none is set.
I am not particularly keen on maintaining qLabel. The library is Open Source and I am happy if someone wants to take over maintenance and further development.
A few open issues: