doxygen_manual-1.8.1 (1035109), страница 42
Текст из файла (страница 42)
All translators that previously derived from theTranslator class now derive from this adapter class.The TranslatorAdapter_x_y_z class implements the new, required methods. If the new method replacessome similar but obsolete method(s) (e.g. if the number of arguments changed and/or the functionality of the oldermethod was changed or enriched), the TranslatorAdapter_x_y_z class may use the obsolete method toGenerated by Doxygen176Internationalizationget the result which is as close as possible to the older result in the target language. If it is not possible, the result(the default translation) is obtained using the English translator, which is (by definition) always up-to-date.For example, when the new trFile() method with parameters (to determine the capitalization of the first letterand the singular/plural form) was introduced to replace the older method trFiles() without arguments, thefollowing code appeared in one of the translator adapter classes:/*! This is the default implementation of the obsolete method* used in the documentation of a group before the list of* links to documented files.
This is possibly localized.*/virtual QCString trFiles(){ return "Files"; }/*! This is the localized implementation of newer equivalent* using the obsolete method trFiles().*/virtual QCString trFile(bool first_capital, bool singular){if (first_capital && !singular)return trFiles(); // possibly localized, obsolete methodelsereturn english.trFile(first_capital, singular);}The trFiles() is not present in the TranslatorEnglish class, because it was removed as obsolete.
However, it was used until now and its call was replaced bytrFile(true, false)in the doxygen source files. Probably, many language translators implemented the obsolete method, so it perfectlymakes sense to use the same language dependent result in those cases. The TranslatorEnglish does notimplement the old method. It derives from the abstract Translator class. On the other hand, the old translatorfor a different language does not implement the new trFile() method. Because of that it is derived from anotherbase class – TranslatorAdapter_x_y_z. The TranslatorAdapter_x_y_z class have to implementthe new, required trFile() method. However, the translator adapter would not be compiled if the trFiles()method was not implemented. This is the reason for implementing the old method in the translator adapter class(using the same code, that was removed from the TranslatorEnglish).The simplest way would be to pass the arguments to the English translator and to return its result.
Instead, theadapter uses the old trFiles() in one special case – when the new trFile(true, false) is called. Thisis the mostly used case at the time of introducing the new method – see above. While this may look too complicated,the technique allows the developers of the core sources to change the Translator interface, while the users may noteven notice the change. Of course, when the new trFile() is used with different arguments, the English resultis returned and it will be noticed by non English users.
Here the maintainer of the language translator shouldimplement at least that one particular method.What says the base class of a language translator? If the language translator class inherits from any adapterclass the maintenance is needed. In such case, the language translator is not considered up-to-date. On the otherhand, if the language translator derives directly from the abstract class Translator, the language translator isup-to-date.The translator adapter classes are chained so that the older translator adapter class uses the one-step-newertranslator adapter as the base class. The newer adapter does less adapting work than the older one.
The oldestadapter class derives (indirectly) from all of the adapter classes. The name of the adapter class is chosen so thatits suffix is derived from the previous official version of doxygen that did not need the adapter. This way, one cansay approximately, when the language translator class was last updated – see details below.The newest translator adapter derives from the abstract TranslatorAdapterBase class that derives directlyfrom the abstract Translator class. It adds only the private English-translator member for easy implementationof the default translation inside the adapter classes, and it also enforces implementation of one method for noticingthe user that the language translation is not up-to-date (because of that some sentences in the generated files mayappear in English).Generated by Doxygen177Once the oldest adapter class is not used by any of the language translators, it can be removed from the doxygenproject.
The maintainers should try to reach the state with the minimal number of translator adapter classes.To simplify the maintenance of the language translator classes for the supported languages, thetranslator.py Python script was developed (located in doxygen/doc directory). It extracts the important information about obsolete and new methods from the source files for each of the languages.
The informationis stored in the translator report ASCII file (translator_report.txt).Looking at the base class of the language translator, the script guesses also the status of the translator – see thelast column of the table with languages above. The translator.py is called automatically when the doxygendocumentation is generated. You can also run the script manually whenever you feel that it can help you. Of course,you are not forced to use the results of the script. You can find the same information by looking at the adapter classand its base classes.How should I update my language translator? Firstly, you should be the language maintainer, or you shouldlet him/her know about the changes. The following text was written for the language maintainers as the primaryaudience.There are several approaches to be taken when updating your language. If you are not extremely busy, you shouldalways chose the most radical one.
When the update takes much more time than you expected, you can alwaysdecide use some suitable translator adapter to finish the changes later and still make your translator working.The most radical way of updating the language translator is to make your translator class derive directly fromthe abstract class Translator and provide translations for the methods that are required to be implemented – thecompiler will tell you if you forgot to implement some of them.
If you are in doubt, have a look at the TranslatorEnglish class to recognize the purpose of the implemented method. Looking at the previously used adapter classmay help you sometimes, but it can also be misleading because the adapter classes do implement also the obsoletemethods (see the previous trFiles() example).In other words, the up-to-date language translators do not need the TranslatorAdapter_x_y_z classes atall, and you do not need to implement anything else than the methods required by the Translator class (i.e.
the purevirtual methods of the Translator – they end with =0;).If everything compiles fine, try to run translator.py, and have a look at the translator report (ASCII file) at thedoxygen/doc directory. Even if your translator is marked as up-to-date, there still may be some remarks relatedto your source code. Namely, the obsolete methods–that are not used at all–may be listed in the section for yourlanguage. Simply, remove their code (and run the translator.py again).
Also, you will be informed when youforgot to change the base class of your translator class to some newer adapter class or directly to the Translatorclass.If you do not have time to finish all the updates you should still start with the most radical approach as describedabove. You can always change the base class to the translator adapter class that implements all of the not-yetimplemented methods.If you prefer to update your translator gradually, have a look at TranslatorEnglish (the translator_en.h file).
Inside, you will find the comments like new since 1.2.4 that separate always a number of methodsthat were implemented in the stated version. Do implement the group of methods that are placed below the commentthat uses the same version numbers as your translator adapter class. (For example, your translator class have touse the TranslatorAdapter_1_2_4, if it does not implement the methods below the comment new since1.2.4.
When you implement them, your class should use newer translator adapter.Run the translator.py script occasionally and give it your xx identification (from translator_xx.h) tocreate the translator report shorter (also produced faster) – it will contain only the information related to your translator. Once you reach the state when the base class should be changed to some newer adapter, you will see thenote in the translator report.Warning: Don’t forget to compile Doxygen to discover, whether it is compilable. The translator.py does notcheck if everything is correct with respect to the compiler.
Because of that, it may lie sometimes about the necessarybase class.The most obsolete language translators would lead to implementation of too complicated adapters. Because ofthat, doxygen developers may decide to derive such translators from the TranslatorEnglish class, which isby definition always up-to-date.When doing so, all the missing methods will be replaced by the English translation.Generated by DoxygenThis means that not-178Internationalizationimplemented methods will always return the English result.