O Manual de Programação do KDevelop: O Guia do Utilizador para Desenvolvimento de Aplicações C++ para o Ambiente de Trabalho K (KDE) com o ambiente de trabalho KDevelop, Versão 2.1 | ||
---|---|---|
Prev | Capítulo 11. Internationalization | Next |
KDevelop also takes part on making life easier for developers to include native language support to their applications. Whenever you create a new KDE project, a po directory is added to the main project directory. There, your &<;application&>;.pot file will be placed after the generation is complete. The .pot file already contains all strings that are set up with the i18n() macro, therefore you only have to write your code using the macro again. From time to time, you should do a "Project"-"Make messages and merge", which will automatically extract all macros again and rebuilds the potfile.
To add a language to your application, choose "Project"-"Add translation file", which opens the language selection dialog. Select the desired language and press OK. Then, the according &<;lang&>;.po file will be build in the po directory. Then start translating the po file by selecting it from the po directory in the Real File Viewer or from the LFV, folder "Translations". If you have KTranslator installed, it will be opened in the "Tools" window with KTranslator , otherwise as a text file in the header/resource window. KTranslator makes it very easy to translate strings by scanning the existing translations of your local KDE installation, so they can be used already.
For editing by hand, we'll have a look at an example:
#: kscribble.cpp:619 msgid "Opens an existing document" msgstr "" |
The above shows a string that was extracted from the file kscribble.cpp at line 619. msgid and msgstr are the tags which give the information for the translation; msgstr will contain the translated string. There, you have to watch escape sequences such as \n or \t, which have to be included into the translation string. A German translation would therefore look like this:
#: kscribble.cpp:619 msgid "Opens an existing document" msgstr "Öffnet ein existierendes Dokument" |
That would be all to watch for translation; after you're done, save the file. When make is run within the po directory, the message files will be processed and errors may occur if strings are not translated consistently, e.g. escape sequences are missing. Then edit the according message string again and make sure that make runs without errors.
Additionally, you should be very careful when translating ampersands within text strings. The letters after ampersands are used as keyboard accelerators in conjunction with the ALT key to access menubar or popup menu items to change the keyboard focus to the selected item more quickly. Now, if the same accelerator letter appears in the same keyboard focus area (which would be the main widget on one time, and a dialog at another), each widget after the first one cannot be accessed by the supposed keyboard accelerator. So even translators have a responsibility for the usage of the application under their language. There is also no guarantee that the original letter will occur in the translation, so translators have to choose very carefully and should test the application under their language after they installed the translation to ensure it runs without these malfunctions.