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

Work with Multilingual Types

The following example shows how to work with multiple languages in a type model.

Multilingualism is a cross-cutting aspect in Bundt. Every model has at least one language, but more can be added. In multilingual type models, you can refer to model elements by their localized names, as shown below. Globalized text properties, such as Class.Name, always return a value in the default language. The matching multilingual properties, such as Class.NameML, return a MultilingualString object containing all the localized variants of the text.

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 with two languages.
var tmo = ModelManager.CreateTypeModel("TypeTest", VersionInfo.OneZeroZeroZero, "en_GB", "English");
tmo.AddNewLanguage("es_ES", "Spanish");

//add a class and set its name in both languages.
var clBuilding = tmo.AddNewClass("Building", false);
clBuilding.NameML["es"].Value = "Edificio";

//find the class in the model by its English name.
var clFound1 = tmo.FindClass("Building");

//switch the model's default language to Spanish.
tmo.DefaultLanguage = tmo.FindLanguage("es");

//find the class in the model by its Spanish name.
var clFound2 = tmo.FindClass("Edificio");

//they are the same class.
Assert.AreEqual(clFound1, clFound2);

In lines 4-5, we create a type model by calling CreateTypeModel with explicit arguments for the initial default language name and description for British English. Then we add Eurpean Spanish as a new language.

In lines 8-9, we create a class in the model, providing a name in English, as this is the default language. Then, we add a class name in Spanish through the NameML property.

In line 12, we retrieve the Building class by its name, using English as this is still the default language. At this point, using the class' Spanish name in the call to FindClass would not retrieve it.

In line 15, we switch the model's default language to Spanish. From now on, all globalized text properties will return values in Spanish.

In line 18, we retrieve the Building class by its name again, this time using Spanish as this is now the default language.

Finally, line 21 shows that both references point to the same class in the model.

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