HomeActive Query Builder - IntroductionLocalizing Active Query BuilderSelecting language in run-time

5.2. Selecting language in run-time

There are two ways to select language. First is to select it from the list of available languages. If you can not find your language in this list, you may localize the component by yourself and load your language from the language file.

  • Selecting language in VCL Edition (Delphi):

     
         // use this unit to get access to acQBLanguageManager global object
         uses acQBLocalizer;
     
         // show languages
         for i:=0 to acQBLanguageManager.LanguagesCount-1 do
         begin
             ShowMessage(acQBLanguageManager.Language[i].LanguageName);
         end;
     
         // set built-in default language
         acQBLanguageManager.CurrentLanguageIndex := -1;
     
         // set language #0
         acQBLanguageManager.CurrentLanguageIndex := 0;
     
         // load and apply custom language from file (lng is integer)
         lng := acQBLanguageManager.AddLanguageFromFile('MyLanguage', 'MyLang.lng');
         acQBLanguageManager.CurrentLanguageIndex := lng;
     
         // load and apply language from resource 
         // (lng is integer, MyLang is resource name, LANGUAGES is resource type)
         lng := acQBLanguageManager.AddLanguageFromResource('MyLanguage', 'MyLang', 'LANGUAGES');
         acQBLanguageManager.CurrentLanguageIndex := lng;
     
         // load and apply language from string (lng is integer, sLanguage is string)
         lng := acQBLanguageManager.AddLanguageFromString('MyLanguage', sLanguage);
         acQBLanguageManager.CurrentLanguageIndex := lng;
     
         // load and apply language from TStrings (lng is integer, ssLanguage is TStrings)
         lng := acQBLanguageManager.AddLanguageFromStrings('MyLanguage', ssLanguage);
         acQBLanguageManager.CurrentLanguageIndex := lng;
    
  • Selecting language in ActiveX Edition (VB.NET):

     
        ' show languages
        For i = 0 To ActiveQueryBuilderX1.Localizer.Count - 1
            MsgBox "Language #" + Str(i) + ": " + ActiveQueryBuilderX1.Localizer.LanguageName(i)
        Next i
     
        ' set built-in default language
        ActiveQueryBuilderX1.Localizer.CurrentLanguage = -1
     
        ' set language #0
        ActiveQueryBuilderX1.Localizer.CurrentLanguage = 0
     
        ' load and apply custom language from file
        lng = ActiveQueryBuilderX1.Localizer.AddLanguageFromFile("MyLanguage", "MyLang.lng")
        ActiveQueryBuilderX1.Localizer.CurrentLanguage = lng
     
        ' load and apply custom language from string (sLanguage is string)
        lng = ActiveQueryBuilderX1.Localizer.AddLanguageFromString("MyLanguage", sLanguage)
        ActiveQueryBuilderX1.Localizer.CurrentLanguage = lng
    
  • Selecting language in ActiveX Edition (C#):

    
        // show languages
        for (int i = 0; i < axActiveQueryBuilderX1.Localizer.Count; ++i)
        {
            MessageBox.Show("Language #" + i.ToString() + ": " + 
            axActiveQueryBuilderX1.Localizer.get_LanguageName(i));
        }
     
        // set built-in default language
        axActiveQueryBuilderX1.Localizer.CurrentLanguage = -1;
     
        // set language #0
        axActiveQueryBuilderX1.Localizer.CurrentLanguage = 0;
     
        // load and apply custom language from file
        int lng = axActiveQueryBuilderX1.Localizer.AddLanguageFromFile("MyLanguage", "MyLang.lng");
        axActiveQueryBuilderX1.Localizer.CurrentLanguage = lng;
     
        // load and apply custom language from string (sLanguage is string)
        int lng = axActiveQueryBuilderX1.Localizer.AddLanguageFromString("MyLanguage", sLanguage);
        axActiveQueryBuilderX1.Localizer.CurrentLanguage = lng;
    
  • Selecting language in .NET Edition (C#):

     
        // How to load a language from an external source:
     
        // load language from specified file
        ActiveDatabaseSoftware.ActiveQueryBuilder.Helpers.Localizer.LoadLanguageFromFile(string languageFile);
        // load language from a XML string
        ActiveDatabaseSoftware.ActiveQueryBuilder.Helpers.Localizer.LoadLanguageFromString(string xmlString);
        // load language from a stream containing an XML string
        ActiveDatabaseSoftware.ActiveQueryBuilder.Helpers.Localizer.LoadLanguageFromStream(Stream languageStream);
     
        // How to get a list of available languages:
        foreach (string lng in ActiveDatabaseSoftware.ActiveQueryBuilder.Helpers.Localizer.Languages)
        {
            Trace.WriteLine(lng);
        }
     
        // The language list always contains "Auto" and "Default" strings.
        // - "Auto" means the language will be detected automatically according to CultureInfo specified for 
        //   UI culture of the current thread (System.Threading.Thread.CurrentThread.CurrentUICulture).
        // - "Default" means usage of default strings containing in embedded resources.
     
        // How to set current language:
        queryBuilder1.Language = "es-MX";
        // If specified language doesn't exist, Localizer will try to fallback to the base language ("es")
        // If it doesn't exist too, the Localizer will use the "Default" language.
    
  • Selecting language in ASP.NET Edition (C#):

    To get list of available languages, use the code above for WinForms .NET Edition.

    Use the QueryBuilderControl.Language property to specify required language for the control. Language will be detected automatically according to the "Accept-Language" HTTP request header field if this property is set to "Auto".

    To load language from external language file, place it to the "Language Files" at the root of your web site and set the QueryBuilderControl.UseCustomLanguageFiles. Language file will be determined according to the Language property value.

  • Selecting language in Java Edition:

     
        // How to load a language from an external source:
     
        // load language from specified file
        com.adbs.utils.Helpers.localizer.loadLanguageFromFile(String languageFile);
        // load language from a XML string
        com.adbs.utils.Helpers.localizer.loadLanguageFromString(String xmlString);
        // load language from a stream containing an XML string
        com.adbs.utils.Helpers.localizer.loadLanguageFromStream(InputStream languageStream);
     
        // How to get a list of available languages:
        for (String lng : com.adbs.utils.Helpers.localizer.languages)
        {
            System.out.println(lng);
        }
     
        // The language list always contains "Auto" and "Default" strings.
        // - "Auto" means the language will be detected automatically according to information
        // from java.util.Locale.getDefault()
        // - "Default" means usage of default (English) strings containing in embedded resources.
     
        // How to set current language:
        queryBuilder1.setLanguage("es-MX");
        // If specified language doesn't exist, Localizer will try to fallback to the base language ("es")
        // If it doesn't exist too, the Localizer will use the "Default" language.
    

This page was: Helpful | Not Helpful