LightSaber automatic language translator engine for Delphi

This is an RTTI-based automatic translation engine for Delphi.

It will translate all GUI strings (for example TLabel.Caption, TLabel.Hint, TMenuItem.Caption) for all live forms in your application. You need only two lines of code for this!


The text is stored in an INI file which can be sent to DeepL or GoogleTranslate for translation.

Downloading the code

 The code can be downloaded now from the LightSaber repository.


Advantages

  • Changing language is life without the need to restart the app
  • The text translated can be seen live, as we translate it
  • The user can create his own translations easily (with the included utility)
  • Full Unicode support
  • All text is automatically saved to a file.
  • The user does not have to collect the text manually from the screen.
  • No room for errors (missed/hidden text).
  • Instant/automatic translations via Google Translate (not fully implemented yet)
  • Press the “Translate to xyz language” button, then 3 seconds later the GUI switches to that language.
  • RTTI-based – Supports everything
  • Support for multiple properties (Caption, TextHint, or Hint).
  • Support for ANY classic Delphi control (TButton, TLable, TCheckbox, etc) that implements those properties.
  • Support for ANY classic Delphi component (TMenu, TAction, etc)
  • Support for ANY custom-made/3rd party Delphi component
  • Easy to integrate
  •        Only 4 lines of code are required
  •        Low dependency
  • Clean code, documented, tested (mostly) & Demo app

Limitations

   1. Cannot translate forms that are not live (naturally)  
      Proposed solution: Add a flag like TTranslator.LiveTranslation. When a new form is created it will check the flag. If the flag is true, the form will save itself to the English INI file.  

   2. Strings into the source code will not be translated automatically (naturally)  
      Proposed solution: Add a function that can read strings from the INI file. Add support for something similar to the Format(%s %f Fd) Delphi function.  
      Proposed solution: If the strings are embedded as resources, we can translate them live.  

How to use it

1. To load a language into all LIVE forms in your app:  

   procedure TMainForm.LateInitialize;  
   begin  
    LoadForm(Self);  
    Translator:= TTranslator.Create;  

    // If no translation was selected (program's first start) the "Choose Language" dialog will appear.  
    Translator.LoadLastTranslation;  
   end;  


2. To load a language into a form that is not live (we do it on the form's creation):  

   procedure TDynamicForm.Initialize;  
   begin  
    // Call LoadFormTranlation() for DYNAMICALLY created forms, when they are created  
    Translator.LoadFormTranlation(DynamicForm);  
   end;  


3. Save all live forms to the INI file to be translated:  

   a. Call Translator.SaveTranslation;  //Note: Only currently existing/live forms will be saved to disk.  
   b. Manually translate the text (or use www.DeepL.com). There is a helper tool in FormTranslator.pas.  
   c. Place the newly translated file in the 'Lang' folder. The program will discover the new file when the ShowSelectLanguage procedure is called (no need to restart).  


4. Let the user choose/switch a language:  

   a. Call FormSelectLang.pas ShowSelectLanguage  
   b. Languages are switched 'Live'. No need to restart the program.  

**INFO**  
   The path where the translation files are stored is returned by GetLangFolder().  
   If no translation is found in the INI file for a GUI control, its text will be left untranslated.  
   Mark controls that should not be translated (for ex, labels that will have their caption changed dynamically) with Tag=128  

**WARNING**  
   Make sure you make your GUI controls (labels, buttons, etc) large enough. Some languages require more space (more characters) than others.  

Scroll to Top