Package api l10n
Package Localisation
An optional section in the package schema declares localisation bundles that can be used to localise output for the package's nodes and configuration.
The hyrrokkin user interface allows users to select their preferred language for each package from those defined in the package schema.
The hyrrokkin topology API also allows the user to obtain localisation bundles and use them to localise text.
The relevant section in the textgraph schema.json file is:
{
...
"l10n": {
"languages": {
"en": {
"name": "English",
"bundle_url": "l10n/en.json"
},
"de": {
"name": "Deutsch",
"bundle_url": "l10n/de.json"
}
},
"default_language": "en"
},
...
}
The urls in these files are resolved relative to the package folder (the folder containing the package's schema.json file) and point to localisation bundles, which are json encoded dictionaries mapping from a localisation key to a localised string.
{
"package_name": "Text Graph",
"package_description": "A toy example package for analysing text",
"textgraph_configuration": "Text Graph Configuration",
"text_input": "Text Input",
"text_input_description": "Input a text document to be analysed",
"open": "Open",
"word_frequency": "Word Frequency",
"word_frequency_description": "Calculate the frequencies of words in the input text",
"frequency_threshold": "Frequency Threshold",
"merge_frequencies": "Merge Frequencies",
"merge_frequencies_description": "Merge multiple word frequencies",
"merge_text": "Merge Text",
"merge_text_description": "Merge multiple text inputs",
"merge_mode": "Merge Mode",
"add_frequencies": "Add Frequencies",
"subtract_frequencies": "Subtract Frequencies",
"table_display": "Data Table Display",
"table_display_description": "Display tabular data containing the results of analysing text",
"link_type_text": "Text",
"link_type_text_description": "This type of link carries text values",
"link_type_table": "Data table",
"link_type_table_description": "This type of link carries data table values",
"rows": "Rows",
"no_data": "No Data",
"word": "Word",
"frequency": "Frequency",
"add_stop_words": "Add Stop Words",
"stop_words": "Stop Words",
"add": "Add",
"configure": "Configure..."
}
{
"package_name" : "Textdiagramm",
"package_description": "Ein Spielzeug-Beispielpaket zur Textanalyse",
"textgraph_configuration": "Textdiagramm Konfiguration",
"text_input": "Eingabetext",
"text_input_description": "Geben Sie ein zu analysierendes Textdokument ein",
"open": "Offnen",
"word_frequency": "Worthäufigkeit",
"word_frequency_description": "Berechnen Sie die Häufigkeit von Wörtern im Eingabetext",
"frequency_threshold": "Frequenzschwelle",
"merge_frequencies": "Frequenzen zusammenführen",
"merge_frequencies_description": "Mehrere Worthäufigkeiten zusammenführen",
"merge_text": "Text zusammenführen",
"merge_text_description": "Mehrere Texteingaben zusammenführen",
"merge_mode": "Zusammenführungsmodus",
"add_frequencies": "Frequenzen hinzufügen",
"subtract_frequencies": "Frequenzen subtrahieren",
"table_display": "Datentabellenanzeige",
"table_display_description": "Zeigen Sie tabellarische Daten mit den Ergebnissen der Textanalyse an",
"link_type_text": "Text",
"link_type_text_description": "Dieser Linktyp enthält Textwerte",
"link_type_table": "Datentabelle",
"link_type_table_description": "Dieser Linktyp überträgt Datentabellenwerte",
"rows": "Reihen",
"no_data": "Keine Daten",
"word": "Wort",
"frequency": "Haufikeit",
"add_stop_words": "Stoppwörter hinzufügen",
"stop_words": "Stoppwörter",
"add": "Hinzufügen",
"configure": "Konfigurieren..."
}
How to use localisation keys
A package configuration and nodes can use the {{key}} syntax in various places:
- in status messages output using the
set_statusAPI call - in web pages attached to the configuration or nodes
- in many places in the
schema.jsonfile, for example
{
...
"metadata": {
"name": "{{package_name}}",
"description": "{{package_description}}",
"version": "0.5.0",
"license": "MIT",
"link": "html/about.html"
},
...
}
Using localisation in configuration/node web-pages
To do this, include localisation keys in the page using the {{key}} syntax, for example:
<h1>{{table_display}}</h1>
Also, style the document's <body> to be hidden, initially
<body style="visibility: hidden;">
Then include the following that replaces these text patterns with localised text and then make the page visible once the page is loaded:
<script>
hyrrokkin.page.set_connection_handler(() => {
hyrrokkin.page.localise_body();
document.body.style.visibility = "visible";
});
</script>
When hyrrokkin's ui connects to a web page opened from a configuration or node, it will send a localisation bundle for the package's selected language to the page. The hyrrokkin.page.localise_body() call then scans the page and replaces localisation keys with localised text.