Advanced Localization Techniques

QCubed allows you to store your translations in any format that works for you. If you already have a database with translated terms in a given schema, you probably don't want to have to generate .po files, right? Or, if you have a custom XML file that defines the translations - you want to keep using it, understandably.

QCubed allows you to do just that. It's actually really easy - just define your own class that implements the QTranslationBase interface. In that class, you specify how exactly the translations should be retrieved. There are static methods that you need to implement:
  1. public static function Initialize(). In this factory method, your class is supposed to read QApplication::$LanguageCode and QApplication::$CountryCode settings and based on these settings, initialize itself, returning a new instance (usually by calling self::Load())
  2. public static function Load ($strLanguageCode = null, $strCountryCode = null). In this factory method, your class is supposed to load up everything it needs to later on spit out translations really quickly. If you store translations in the database, load them here and cache them. Just like any factory method, this methoid is supposed to return an instance of your translator class.
  3. public function TranslateToken ($strToken). Just like you'd expect, after everything is initialized, you can do the actual translation :-). This method is called every time something is to be translated in the user interface - for example, when QApplication::Translate() is called. Remember that this method is NOT supposed to include any long-running operations - those are supposed to be done in Load().
Take a look at the implementation of the example QSampleTranslation class in View Source - it does something very simple.It loads up the translations from a pre-written array (which could have as easily been a database) in Load(), and once that's done, quickly translates everything in TranslateToken().

Translations made using the custom QSampleTranslation class

French (default set in Form_Create())
Required -> Requis
Optional -> Facultatif

Spanish
Required -> Obligatorio
Optional -> Opcional