Bundt Programmer's Guide · Bundt Programmer's Interface version 1.0.1.0

Work with Multilingual Instances

The following example shows how to work with multiple languages in an instance model.

Multilingualism is a cross-cutting aspect in Bundt. Every model has at least one language, but more can be added. In multilingual instance models, you can store localized data as dictated by multilingual attribute specifications in the corresponding type model. For example, if the type model defines a Person.Job attribute of type Text and having the multilingual flag set, you will be able to store values for this attribute in each of the languages of the instance model.

Please see the multilingualism concept in the Bundt User's Manual for additional details.

To execute this code, you will need a reference to the ModellingEngine library.

using Incipit.Bundt.ModellingEngine;

//create a type model.
var tmo = ModelManager.CreateTypeModel("TypeTest", VersionInfo.OneZeroZeroZero);

//add class and a multilingual attribute.
var clPerson = tmo.AddNewClass("Person", false);
var attJob = clPerson.AddNewAttribute("Job", Cardinality.One, BaseDataType.Text);
attJob.IsMultilingual = true;

//create an instance model with two languages, conforming to the previous type model.
var imo = ModelManager.CreateInstanceModel(tmo, "InstanceTest", VersionInfo.OneZeroZeroZero);
imo.AddNewLanguage("es_ES", "Spanish");

//add a Person object.
var obBob = imo.AddNewObject(clPerson, "bob");

//add a value in both languages.
obBob.ValueSets[attJob].SetContents(imo.NewMultilingualString("Lawyer", "Abogado"));

//alter value contents for English.
obBob.ValueSets[attJob].SingleValue.ContentTextML["en"].Value = "Solicitor";

In line 4, we create a type model.

In lines 7-9, we add a Person class to the model, and then a Job attribute of type Text. Then, we set Attribute.IsMultilingual to true so that it accepts multilingual data when instantiated.

In lines 12-13, we create an instance model that conforms to the previous type model. No language arguments are passed to ModelManager.CreateInstanceModel, so that the default British English is assumed. Then, the European Spanish language is added.

In lines 16, a Person object is created. Initially, this object has no value for its Job attribute.

In line 19, a multilingual value is set for bob.Job. This is accomplished by calling ValueSet.SetContents and passing a multilingual string as argument. Notice that the multilingual string is constructed by calling Model.NewMultilingualString and passing the text content for each language as an argument list.

Finally, in line 22 we change the English content of the bob.Job value from the original "Lawyer" to "Solicitor".


Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020