Using Languages and Cultures |
The Telogis.GeoBase.Internationalization namespace provides classes for accessing strings and audio announcements for language based operations. The classes rely upon a language configuration file, lang.xml, which specifies the necessary language information: language, cultures, strings, directions and announcements. Lang.xml resides in a language/culture-specific folder ("en-US", for example), along with the necessary audio files, in the langs folder, which is typically found at: \Program Files\Telogis\GeoBase\GeoBaseResources. Adding more languages or cultures is as simple as adding more language and culture-specific folders to the langs folder.
Note |
---|
The Internationalization namespace uses the CultureInfo class. |
Internationalization is supported by GeoBase's MessagesBundle, an abstract class which provides access to internationalized messages (for example, strings and announcements) for a single culture.
GeoBase provides the developer with two concrete sub-classes: DirectoryMessagesBundle, and StringMessagesBundle. With the DirectoryMessagesBundle class, the messages for the culture are obtained from an XML file in a directory, allowing other resources (for example announcement sound files) to be obtained from the same directory. With the StringMessagesBundle class, messages and associated resources for the culture are obtained from an XML string.
To create a MessagesBundle object, use one of the following constructors:
// DirectoryMessagesBundle public DirectoryMessagesBundle( string rootPath, // Root path containing directories for different cultures. string bundleFilename, // Name of the XML file containing the configuration for a culture. CultureInfo culture, // The bundle's culture. bool debugMode // Whether debug mode will be used when generating strings. ) // StringMessagesBundle public StringMessagesBundle( string XmlString // XML configuration for the bundle, in either ASCII or UTF-8 format. )
For example:
// DirectoryMessagesBundle string rootPath = Settings.GeoBasePath("langs"); // or use an absolute path, such as // string rootPath = @"C:\telogis\geobase\geobaseresources\langs"; string bundleFileName = "lang.xml"; CultureInfo culture = new CultureInfo("en-US"); bool debugMode = false; MessagesBundle myMsgBundle = new DirectoryMessagesBundle( rootPath, bundleFileName, culture, debugMode); // StringMessagesBundle MessagesBundle myMsgBundle = new StringMessagesBundle(xmlString);
The Navigator can be set up for specific languages and cultures with the overloaded constructor:
Navigator(IGps gps, MessagesBundle messagesBundle) Navigator(IGps gps, string langPath, CultureInfo culture) Navigator(IGps gps, string langPath, CultureInfo culture, bool debugMode)
'langPath' provides the path to the directory containing the langs directory.
'culture' provides the language/culture specific information.
'debugMode', when set to true, tells the Navigator to:
raise MessagesBundleExceptions when errors are found in the language configuration file
print announcements to the console to aid in the development of new announcements
As an example:
Navigator nav = new Navigator(myGps, myMsgBundle);
The NavigationManager can be set up for specific languages and cultures with the overloaded constructor:
NavigationManager(MapCtrl map, string langPath, CultureInfo culture) NavigationManager(MapCtrl map, string langPath, CultureInfo culture, bool debugMode)
'langPath' provides the path to the directory containing the langs directory.
'culture' provides the language/culture specific information.
'debugMode', when set to true, tells the NavigationManager to:
As an example:
NavigationManager navMgr = new NavigationManager(myMapCtrl, myLangPath, "en-US");
The Route class provides the overloaded GetDirections method where the Directions can be returned according to the given culture.
The following shows an example of how to obtain routing directions for a specific culture:
// Set up the route RouteStop rsA = new RouteStop(new LatLon(34.1018, -118.2973)); RouteStop rsB = new RouteStop(new LatLon(34.0720, -117.4962); // Create the route with the route stops Route myRoute = new Route(rsA, rsB); // Get the directions in the preferred language/culture Directions myDirections = myRoute.GetDirections("en-US");
The XmlWaveAnnouncer in the Telogis.GeoBase.Navigation namespace can be created by specifying both the culture and the path to the languages directory. If the path is not given then the XmlWaveAnnouncer uses a sounds directory set to the default langs directory in the GeoBase system's data path. If the culture is not specified, then the XmlWaveAnnouncer uses the a culture set to CurrentCulture.
The following example shows how to create an XMLWaveAnnouncer with a given sounds directory and culture.
// Set up path to 'langs' String langPath = Settings.GeoBasePath("langs"); // Set up culture CultureInfo myCulture = new CultureInfo("en-US"); // Create announcer WaveAnnouncer wa = new XmlWaveAnnouncer(langPath, myCulture);