User Tools

Site Tools


en:dev:284:translate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:dev:284:translate [13.08.2015 21:39] – [Structure of translation tables] a few minor corrections mrbasemanen:dev:284:translate [18.07.2018 12:46] (current) – [Translations before 2.8.4] Manuela v.d.Decken
Line 1: Line 1:
-FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)// 
- 
 ====== Centralized management of translations ====== ====== Centralized management of translations ======
 **Translate** is a package consisting of several classes, that already in WB 2.8.4 take care about all the handling of translations known as 'language files' up to now. **Translate** is a package consisting of several classes, that already in WB 2.8.4 take care about all the handling of translations known as 'language files' up to now.
Line 20: Line 18:
 ==== General ==== ==== General ====
 For simplicity, I'm talking only about 'language files' here. However, in real case usage the translations no longer have to be defined necessarily as arrays in PHP files. Any conceivable suitable file format is possible now. The data don't not even have to be on the same server. The data could be provided by a web service, or stored in a database. For such use cases only a small, specialized driver is necessary, which can be loaded any time, even temporarily even for a single addon or template involved. For simplicity, I'm talking only about 'language files' here. However, in real case usage the translations no longer have to be defined necessarily as arrays in PHP files. Any conceivable suitable file format is possible now. The data don't not even have to be on the same server. The data could be provided by a web service, or stored in a database. For such use cases only a small, specialized driver is necessary, which can be loaded any time, even temporarily even for a single addon or template involved.
-==== Translations before 2.8.==== +==== Translations before 2.10.==== 
-Let's start at the current level at the beginning of 2.8.and earlier. In the central language directory of the core, there are a large number of language files (DE.php | EN.php | etc.). Each of these files contains an overwhelmingly large number of language variables (specifically, currently about 600 !!). The used system requires that in each language file, each entry is present. Missing one often ends up in a runtime error. Once WebsiteBaker starts, one of these language files will be loaded with its full 600 entries forcibly. completely independent of whether even one of them is required! Of course, different addons then load their own language files still additionally. Having several different addons on one page even a very considerable number can also come together.\\ //(From historical times, the translation of many ancient modules are included and a real care of the files, with a reasonable time / effort is virtually impossible. Whoever says otherwise, must be happy from now on take care of these fossil files. ;-))//\\+Let's start at the current level at the beginning of 2.10.and earlier. In the central language directory of the core, there are a large number of language files (DE.php | EN.php | etc.). Each of these files contains an overwhelmingly large number of language variables (specifically, currently about 600 !!). The used system requires that in each language file, each entry is present. Missing one often ends up in a runtime error. Once WebsiteBaker starts, one of these language files will be loaded with its full 600 entries forcibly. completely independent of whether even one of them is required! Of course, different addons then load their own language files still additionally. Having several different addons on one page even a very considerable number can also come together.\\ //(From historical times, the translation of many ancient modules are included and a real care of the files, with a reasonable time / effort is virtually impossible. Whoever says otherwise, must be happy from now on take care of these fossil files. ;-))//\\ 
 +=== Aufbau der Sprachdateien (EN.php) === 
 +<PHP> 
 +//Modul Description 
 +$module_description = 'Enter here a really short description of your module. About 200-250 characters should suffice.'; 
 + 
 +$MOD_MyModule['PRINT'                      = 'Please print this page, if a copy is desired for your records.'; 
 +$MOD_MyModule['LOAD_LAYOUT'                = 'Load Default Layout'; 
 +$MOD_MyModule['TEXT_GUEST'                 = 'Guest'; 
 +$MOD_MyModule['TEXT_UNKNOWN'               = 'unknown'; 
 +$MOD_MyModule['TEXT_PRINT_PAGE'            = 'Print page'; 
 +$MOD_MyModule['MESSAGE_ARCHIVE_DELETED'    = 'Zip(s) deleted successfully.'; 
 +$MOD_MyModule['MESSAGE_ARCHIVE_NOT_DELETED'] = 'Cannot delete the selected Zip(s).'; 
 +</PHP> 
 +somebody wrote this kind of entries: 
 +<PHP> 
 +$MOD_MyModule['PRINT'                      = 'Please print this page, if a copy is desired for your records.'; 
 +$MOD_MyModule_TEXT['GUEST'                 = 'Guest'; 
 +$MOD_MyModule_MESSAGE['ARCHIVE_DELETED'    = 'Zip(s) deleted successfully.'; 
 +</PHP> 
 +It does not look that good, but it works. Both syntax lead to the same Translate keys. 
 +<PHP> 
 +echo $oTrans->MOD_MyModule_PRINT; 
 +echo $oTrans->MOD_MyModule_LOAD_LAYOUT; 
 +echo $oTrans->MOD_MyModule_TEXT_GUEST; 
 +echo $oTrans->MOD_MyModule_TEXT_UNKNOWN; 
 +echo $oTrans->MOD_MyModule_TEXT_PRINT_PAGE; 
 +echo $oTrans->MOD_MyModule_MESSAGE_ARCHIVE_DELETED; 
 +echo $oTrans->MOD_MyModule_MESSAGE_ARCHIVE_NOT_DELETED; 
 +</PHP> 
 + 
 + 
  
 ==== The basic system behind Translate ==== ==== The basic system behind Translate ====
Line 36: Line 66:
  
 When you look at the table on the left (Extract from the Language support of Firefox), you can already see various Chinese, several German and English language in several dialects. The previously used, simple 2-letter codes purely following [[http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes|ISO 639-1]] no longer satisfy at least the most languages with their major, regional to define variations. The use of [[http://en.wikipedia.org/wiki/IETF_language_tag|IETF language tag]] according to [[http://tools.ietf.org/html/rfc5646|RFC 5646]] has therefore in the meantime become to an established standard.  //**Translate**// supports at least the major part of the IETF tags. Not supported are currently the optional //script subtags//, //extension subtags//, and the //private-use subtag//.\\ When you look at the table on the left (Extract from the Language support of Firefox), you can already see various Chinese, several German and English language in several dialects. The previously used, simple 2-letter codes purely following [[http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes|ISO 639-1]] no longer satisfy at least the most languages with their major, regional to define variations. The use of [[http://en.wikipedia.org/wiki/IETF_language_tag|IETF language tag]] according to [[http://tools.ietf.org/html/rfc5646|RFC 5646]] has therefore in the meantime become to an established standard.  //**Translate**// supports at least the major part of the IETF tags. Not supported are currently the optional //script subtags//, //extension subtags//, and the //private-use subtag//.\\
-{{ :dev:284:translate:translatemixing.gif?nolink|}}+{{ :dev:284:translate:translatemixing.png?nolink|}}
 //**Translate**// itself currently includes the following tags: //**Translate**// itself currently includes the following tags:
   * //**Primary language subtag**// based on [[http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes|ISO-639-1/639-2T/639-3]]   * //**Primary language subtag**// based on [[http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes|ISO-639-1/639-2T/639-3]]
Line 42: Line 72:
   * //**Variant subtags**// in part based on the [[http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry|IANA language-subtag-registry]]. Here 2-8 characters are allowed, in addition, one or more hyphens can be contained.\\   * //**Variant subtags**// in part based on the [[http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry|IANA language-subtag-registry]]. Here 2-8 characters are allowed, in addition, one or more hyphens can be contained.\\
 With this system, almost all languages and language variations occurring in the world can be mapped. In the full IETF tags still stood far more information, including the used character set (script). We have restricted ourselves here deliberately only to the actual language code plus the regional allocation. The Variant tag is used for the definition of slightly modified differences of language in the same country. For example, there is indeed Chinese in China and which in turn contains Mandarin or Cantonese, Singapore etc ... This linguistic diversity is essentially more common than one can imagine at first glance. With this system, almost all languages and language variations occurring in the world can be mapped. In the full IETF tags still stood far more information, including the used character set (script). We have restricted ourselves here deliberately only to the actual language code plus the regional allocation. The Variant tag is used for the definition of slightly modified differences of language in the same country. For example, there is indeed Chinese in China and which in turn contains Mandarin or Cantonese, Singapore etc ... This linguistic diversity is essentially more common than one can imagine at first glance.
-==== Wie verarbeitet Translate jetzt diese Informationen? ==== +==== How does Translate process this information now? ==== 
-Die komplette Struktur von Translate basiert auf komplexen Übersetzungstabellen die jeweils für den Coreein Modul oder ein Template zuständig sindDer Grundstruktur basiert auf den Spracheinstellungen und dem FallBack-Mechanismus, den WebsiteBaker vorgibt:\\ +The complete structure of Translate is based on complex translation tables which are each responsible for the corea module or templateThe basic structure is based on the language settings and the fallback mechanism specified by WebsiteBaker: \\ 
-  - die Systemsprache (SYSTEM_LANGUAGE). Das ist die Sprache des Systemsauf deren Basis grundsätzlich programmiert wirdIn der Regel einfaches Englisch **[en]**. +  - The system language (SYSTEM_LANGUAGE). This is the language of the systemwhich is the basis on which usually all programmed is doneAs a rule, simply English **[en]**. 
-  - die Default-Sprache (DEFAULT_LANGUAGE), wird bei der Installation ausgewähltEine deutsche Website wird da deutsch **[de]** oder **[de-de]** wählen+  - The default language (DEFAULT_LANGUAGE) is selected during installationFor a German website would choose German **[de]** or **[de-de]**. 
-  - die Benutzersprache (USER_LANGUAGE), die sich der einzelne Besucher der Website aussucht.  +  - The user language (USER_LANGUAGE) that the individual visitor to the website chooses
-Für jede Spracheinstellung wird jetzt eine Hilfstabelle aufgebautdie sich jeweils wiederum aus bis zu Sprachdateien zusammengemischtdie der Sprachcode vorgibtDiese Hilfstabellen werden nur in der Reihenfolge System->Default->User zu der eigentlichen Übersetzungstabelle zusammengemischt (in real etwas komplexer um Zeit und Speicher zu sparen), die dann auch automatisch gecacht wird. Beim nächsten Aufruf mit der selben Spracheinstellung entfällt also das ganze vorbeschriebene Prozedere und es wird einfach nur die fertige Tabelle aus dem Cache geladen.\\ +Nowan auxiliary table is set up for each language setting, each in turn mixed together from up to language fileswhich specifies the language codeThis auxiliary tables are then mapped together in the order System->Default->User to obtain the actual translation table (in fact it's a bit more complex to save time and memory), which is then also automatically cached. So the next call to the same language setting eliminates all the above-described procedure and just the final table is loaded from the cache. \\ 
-So wie das jetzt für die zentrale Übersetzungstabelle beschrieben ist, exakt genau so geschieht es auch für jedes einzelne Modul und dessen Template, das Sprachdateien mitliefert und das auch tatsächlich geladen und benutzt wird. +Exactly as just described for the central translation tableit also happens the same way for each individual module and its template which ships with language files and actually loads and uses them.
- +
- +
-==== Wie wird Translate benutzt? ==== +
- +
-Für Addon-Entwickler ist Translate sehr einfach einzusetzenDie Grundinitialisierung wird **immer** automatisch vom Core vorgenommen und Addons haben damit überhaupt nichts zu schaffen. Bei älteren Addons, die noch PHP-Dateien enthalten, die direkt von außen aufgerufen werden müssen, sind 2 bis maximal 4 Translate-Methoden erforderlich (alle Kommandos werden in der Standalone-Form angegeben). Bedingung für den Einsatz von Translate ist, dass die Datei ''framework/initialize.php'' bereits geladen (included) ist: +
-  * <php>Translate::getInstance()->enableAddon('modules\\MeinAddon');</php> Dieser Befehl wird gleich zu Beginn einer aufgerufenen Datei eingesetzt. Dadurch werden eventuell vorhandene Sprachdateien dieses Addons aktiviert. Sollte noch ein anderes Addon aktiviert sein, wird dieses zuerst deaktiviert. +
-  * <php>Translate::getInstance()->enableAddonTemplate('NameDesTemplates');</php> Dieser Befehl aktiviert bei Bedarf vorhandene Sprachdateien eines zugehörigen Templates. Wird kein 'NameDesTemplates' angegebenwird nach dem allgemein eingestellten Template gesucht. Wird das nicht gefunden, erfolgt ein Fallback auf das Default-Template. +
-  * <php>Translate::getInstance()->enableAddonTheme('NameDesThemes');</php> Dieser Befehl aktiviert bei Bedarf vorhandene Sprachdateien eines zugehörigen Themes. Wird kein 'NameDesThemes' angegeben, wird nach dem allgemein eingestellten Theme gesucht. Wird das nicht gefunden, erfolgt ein Fallback auf das Default-Theme. +
-  * <php>Translate::getInstance()->disableAddon();</php> Mit diesem Kommando wird das aktive Addon mitsamt seinem Theme und/oder Template wieder von Translate getrennt. +
-Einfacher noch geht es bei Addon-Dateien, die Core-gesteuert aufgerufen werden: Hier wird das Addon bereits vom Core aktiviert. Einzig das Template und/oder das Theme müssen derzeit noch vom Addon selbst aktiviert werden. Auch die Deaktivierung erfolgt automatisch durch den Core. +
- +
-Jetzt müssen eigentlich nur noch die Übersetzungstexte von Translate abgerufen werden. Der einfachste Weg ist:\\ +
-<php> $sText = Translate::getInstance()->TEXT_CANCEL; </php> (entspricht dem früheren <php> $sText = $GLOBALS['TEXT']['CANCEL']; </php>+
- +
-Für ältere Addons existiert vorübergehend eine Methode, sämtliche Übersetzungstexte in einem Zug an die //**phplib**// Templateengine zu übergeben:\\ +
-<php> $template->set_var(Translate::getInstance()->getLangArray()); </php> eingebunden werden die Texte im Template mit ''{TEXT_CANCEL}''.  +
-Das Problem bei dieser Methode ist, dass immer eine komplette Kopie der Übersetzungstabelle an die Templateengine übergeben wird.+
  
-Wesentlich einfacher und platzsparender ist die Verwendung in Verbindung mit Twig, da hier nur eine speichersparende Referenz auf das Translateobjekt übergeben wird:\\ +==== How to use Translate ====
-<php> $aTwigData['Trans'= Translate::getInstance(); </php> die Anzeige im Template erfolgt durch ''%%{{ Trans.TEXT_CANCEL }}%%''+
  
 +For Addon developers Translate is very easy to use. The basic initialization is done automatically **always** from Core and therefore Addons don't have to care at all about this mechanism. In older addons that contain PHP files that need to be called directly from the outside, 2 to a maximum of 4 Translate methods need to be called (all commands are given in the form of standalone). Condition for the use of Translate is that the file ''framework/initialize.php'' has been loaded (included) already:
 +  * <php>Translate::getInstance()->enableAddon('modules\\MyAddon');</php> This command is used at the very beginning of the file being accessed. Thus possibly existing language files of this addon are enabled. In case another addon is already enabled, it will be deactivated first.
 +  * <php>Translate::getInstance()->enableAddonTemplate('NameOfTemplate');</php> This command activates when needed existing language files of an associated template. If no 'NameOfTemplate' is specified, it looks for the template globally set. If this is not found, a fallback to the default template is used.
 +  * <php>Translate::getInstance()->enableAddonTheme('NameOfTheme');</php> This command if necessary enables existing language files of an associated theme. If no 'NameOfTheme' is specified, it looks for the theme globally set. If this is not found, a fallback to the default theme is used.
 +  * <php>Translate::getInstance()->disableAddon();</php> With this command the active addon together with its theme and/or template are disconnected again from Translate.
 +Even simpler with add-on files that are called Core-controlled: Here the addon is already activated from the Core. Only the template and/or the theme must still be activated by the addon itself. The deactivation is performed automatically by the core.
  
 +Now basically the only thing left is actually to call the translated texts by Translate. The easiest way is: \\
 +<php> $sText = Translate::getInstance()->TEXT_CANCEL; </php>  (corresponds to the former <php> $sText = $GLOBALS['TEXT']['CANCEL']; </php>)
  
 +Temporarily for older Addons a method exists that allows to pass all translation texts in one rushto the //**phplib**// Template Engine:\\
 +<php> $template->set_var(Translate::getInstance()->getLangArray()); </php> in the template the texts are inserted with ''{TEXT_CANCEL}''.
 +The problem with this method is that always a complete copy of the translation table is passed to the Template Engine.
  
 +Much easier and less space is used in conjunction with Twig, since only a memory-saving reference is passed to the Translate object:\\
 +<php> $aTwigData['Trans'] = Translate::getInstance(); </php> - in order to display it in the template use ''%%{{ Trans.TEXT_CANCEL }}%%''
  
en/dev/284/translate.1439501998.txt.gz · Last modified: 13.08.2015 21:39 by mrbaseman