You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. $Id: languages.txt 582 2014-12-11 17:47:28Z imoore76 $
  2. This outlines in-depth the process used by phpVirtualBox's translation mechanisms and describes
  3. how a developer may add new translations. If the reader, as an end-user simply wishes to translate
  4. phpVirtualBox into a new language, see:
  5. https://github.com/phpvirtualbox/phpvirtualbox/wiki#translating-phpvirtualbox
  6. .. I) phpVirtualBox translation mechanism
  7. ....... a) Contexts
  8. ....... b) Data structure
  9. ....... c) Runtime translations in JavaScript
  10. ....... d) Runtime translations in PHP
  11. .. II) Adding a new language
  12. ....... a) Creating phpVirtualBox XML translation file
  13. ....... b) Converting QT .qm files
  14. ....... c) Updating language selection
  15. I. phpVirtualBox translation mechanism
  16. The translation mechanism in phpVirtualBox uses a combination of PHP serialized data along with
  17. runtime parsed XML files.
  18. VirtualBox's QT language files are pre-parsed (before runtime) and serialized into data consumable
  19. by PHP's unserialize function. These files contain all translations performed by VirtualBox's
  20. translators for the VirtualBox GUI frontend. Serialized translation files are placed in the
  21. languages/source folder.
  22. Some text that appears in phpVirtualBox is not in, or applicable to the VirtualBox GUI and therefore
  23. has no corresponding translation in VirtualBox's language files. This text is translated in XML files
  24. in the languages/ folder.
  25. lib/language.php contanis the __vbox_language class. Upon instantiation this class:
  26. 1) Determines which language to use by checking phpVirtualBox settings for the default language,
  27. and for the cookie vboxLanguage if passed by the web browser - the browser's cookie will
  28. overwrite the default language defined in config.php
  29. 2) Unserializes the language data from the appropriate file in the languages/source folder
  30. 3) Parses the XML data from the appropriate XML file in the languages folder
  31. 4) Merges language data into a single array structure allowing the XML translations to overwrite
  32. serialized data translations (if such a scenario exists)
  33. I.a Contexts
  34. Language contexts is a translational concept allowing one word (or phrase) to take on many meanings
  35. based on the context in which it is used. When text is being translated, the translation mechanism
  36. must also be passed a context. For instance the "Add" button to add a user may be translated
  37. differently than the "Add" button to add a VirtualMachine.
  38. I.b Data structure
  39. The data structure of parsed languages is a multidimensional associative array / hash / dict that
  40. contains a hierarchy of contexts -> messages -> translation(s). Using PHP's print_r, the output of
  41. this data structure is:
  42. Array
  43. (
  44. [contexts] => Array
  45. (
  46. .....
  47. [UINewHDWizardPageVariant] => Array
  48. (
  49. [messages] => Array
  50. (
  51. [Storage details] => Array
  52. (
  53. [translation] => Detalles de almacenamiento
  54. )
  55. )
  56. .....
  57. )
  58. .....
  59. ("array" refers to an associative array / hash / dict. They are all the same thing in PHP.)
  60. The context UINewHDWizardPageVariant is a key within the contexts array. It has a number of messages.
  61. Storage Details is a key in the messages array. It has a single item called translation that contains
  62. the translation of Storage Details.
  63. I.c Runtime translations in JavaScript
  64. When phpVirtualBox is loaded, it loads js/language.php. This instantiates __vbox_language and dumps
  65. its language data as a JSON encoded object. It also contains the phpVirtualBox JavaScript trans()
  66. function which takes (at a minimum) a context and message, and returns the corresponding translation.
  67. I.d Runtime translations in PHP
  68. lib/language.php contains a trans() function defined in PHP which takes (at a minimum) a context and
  69. message, and returns the corresponding translation using an instance of __vbox_language. Since
  70. language loading is an expensive process (unserializing a large amount of data and parsing XML), the
  71. instantiation of the __vbox_language only occurs if trans() is called in PHP. Subsequent calls to
  72. trans() will of course use the existing instantiation. Translation inside PHP Is rare and restricted
  73. to error messages returned by phpVirtualBox.
  74. II. Adding a new language
  75. Adding a new language requires relatively little work. First, determine the 2 letter language code
  76. for the target language. See http://en.wikipedia.org/wiki/ISO_639-1
  77. II.a Creating phpVirtualBox XML translation file
  78. Copy an existing XML file in phpVirtualBox's languages folder using the 2 letter language code
  79. described above.
  80. Here is an example:
  81. <?xml version="1.0" encoding="utf-8"?>
  82. <language>
  83. <context>
  84. <name>phpVirtualBox</name>
  85. <message>
  86. <source>Warning: A VirtualBox internal operation is in progress. Closing this
  87. window or navigating away from this web page may cause unexpected and
  88. undesirable results. Please wait for the operation to complete.
  89. </source>
  90. <translation>Warnung: Interne Aktion läuft. Wenn Sie dieses Fenster schließen
  91. oder diese Seite verlassen, kann das zu unerwünschten oder
  92. unbeabsichtigten Effekten führen. Bitte warten Sie bis die Aktion
  93. abgeschlossen ist.
  94. </translation>
  95. </message>
  96. <message>
  97. <source>Operation Canceled</source>
  98. <translation>Aktion abgebrochen</translation>
  99. </message>
  100. ......
  101. You will see translation messages such as:
  102. <message>
  103. <source>Operation Canceled</source>
  104. <translation>Aktion abgebrochen</translation>
  105. </message>
  106. Text within the <source> tag is the text that is to be translated. The translated text goes in the
  107. <translation> tag. E.g.
  108. <message>
  109. <source>Operation Canceled</source>
  110. <translation>Your translation of "Operation Canceled" goes here...</translation>
  111. </message>
  112. WARNING: Do not change the text in the <source> tag. Even adding an extra line will break the
  113. translation.
  114. II.b Converting .ts files from official Virtualbox
  115. You will need a copy of VirtualBox installed and to navigate to your VirtualBox installation folder on your computer, then to the "nls" folder.
  116. Otherwise, you can navigate to the URL: "https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Frontends/VirtualBox/nls".
  117. You should see files which have the naming convention VirtualBox_xx.ts - where xx is the language code described above.
  118. If you can't find the needed language, you won't be able to add or update it in phpVirtualbox.
  119. Copy the "VirtualBox_xx.ts" file corresponding to the needed language.
  120. The script languages/source/parse_vbox_lang.php provided with phpVirtualbox can then be used to parse this ".ts" file into a ".dat" file consumable by phpVirtualBox.
  121. Navigate to you phpVirtualbox installation folder and then to languages/source. Put the previously copied "VirtualBox_xx.ts" file there, then run the following command (you will need a working php setup) :
  122. php parse_vbox_lang.php VirtualBox_xx.ts > xx.dat (replace xx with the language code)
  123. This will create a "xx.dat" file that should be readable by phpVirtualBox.
  124. II.c Updating language selection
  125. Once translation files have been added to languages/ and languages/source/ the interface must be
  126. updated so that the new language is available for selection. Edit panes/settingsGlobalLanguage.html
  127. and add the new language to the JavaScript vboxLanguages array.
  128. var vboxLanguages = [
  129. {'id':'en','name':'English'},
  130. {'id':'pt_br','name':'Portuguese (Brazil)','name_tr':'Português (Brasil)'},
  131. {'id':'ru','name':'Russian','name_tr':'Русский'},
  132. {'id':'it','name':'Italian','name_tr':'Italiano'},
  133. ....
  134. ];
  135. This is an array of associative arrays of language definitions that must contain the following keys:
  136. id - must match the language file name in languages/ (minus the .xml extension)
  137. name - the name of the language in English
  138. name_tr - the name of the language in its native speech