Code example: Localization and translation

Updated: 13 May 2019

This Tekla Open API code snippet shows how to create a separate localization instance.

Enable localization of several Forms (using the Localization field of Form1), without inheriting from ApplicationFormBase and connect to Tekla Structures through a model object.

Unfortunately, the whole source code of this example is not available for downloading. Please copy-paste the following code snippet to your project.

using TeklaModel = Tekla.Structures.Model.Model;
using TeklaLocalization = Tekla.Structures.Dialog.Localization; 
namespace LocalizationExample
    public partial class Form1 : Form     
        private static TeklaModel _model;         
        private static TeklaLocalization _localization;                  
        public Form1()         
        // Create a new Model object.
        public TeklaModel Model         
                if (_model == null)                 
                    _model = new TeklaModel();                 
                return _model;             
        // Create a separate localization instance
        public TeklaLocalization Localization         
                if (_localization == null)                 
                    string language = string.Empty;                     
                    string languageFile = string.Empty; 
                    Model.GetAdvancedOption("XS_LANGUAGE", ref language);                     		
                    Model.GetAdvancedOption("XS_DIR", ref languageFile); 
                    languageFile = Path.Combine(languageFile, @"messages\DotNetDialogStrings.xml");                                          
                    _localization = new TeklaLocalization();     
                    _localization.Language = GetShortLanguage(language);
                return _localization;             
        private static string GetShortLanguage(string Language)         
            switch (Language)             
                case "ENGLISH":
                    return "enu";                 
                case "DUTCH":
                    return "nld";
                case "FRENCH":     
                    return "fra";          
                case "GERMAN":                   
                    return "deu";
                case "ITALIAN":           
                    return "ita";       
                case "SPANISH":                   
                    return "esp";     
                case "JAPANESE":             
                    return "jpn";           
                case "CHINESE SIMPLIFIED":              
                    return "chs";           
                case "CHINESE TRADITIONAL":          
                    return "cht";           
                case "CZECH":              
                    return "csy";         
                case "PORTUGUESE BRAZILIAN":  
                    return "ptb";                
                case "HUNGARIAN":     
                    return "hun";    
                case "POLISH":     
                    return "plk";     
                case "RUSSIAN":       
                    return "rus";                  
                    return "enu";             

Load several localization files by calling method LoadFile for each of them. The translations are searched in the loading order and the first match is returned.

Was this helpful?
The feedback you give here is not visible to other users. We use your comments to improve the content.