1e9fd63ecSAdrien Destugues/*! 2e9fd63ecSAdrien Destugues\class BCatalog 3e9fd63ecSAdrien Destugues\ingroup locale 45393193dSAdrien Destugues\brief Class handling string localization. 5e9fd63ecSAdrien Destugues 6e9fd63ecSAdrien DestuguesBCatalog is the class that allows you to perform string localization. This means 7e9fd63ecSAdrien Destuguesyou give it a string in english, and it automatically returns the translation of 8e9fd63ecSAdrien Destuguesthis string in the user's specified language, if available. 9e9fd63ecSAdrien Destugues 10e9fd63ecSAdrien DestuguesMost of the time, you don't have to deal with BCatalog directly. You use the 11e9fd63ecSAdrien Destuguestranslation macros instead. However, there are some cases where you will have to 12e9fd63ecSAdrien Destuguesuse catalogs directly. These include : 13e9fd63ecSAdrien Destugues \item Tools for managing catalogs : if you want to add, remove or edit 14e9fd63ecSAdrien Destuguesentries in a catalog, you need to do it using the BCatalog class. 15e9fd63ecSAdrien Destugues \item Accessing catalogs other than your own : the macros only grant you 16e9fd63ecSAdrien Destuguesaccess to the catalog linked with your application. To access other catalogs 17e9fd63ecSAdrien Destugues(for example if you create a script interpreter and want to localize the 18e9fd63ecSAdrien Destuguesscripts), you will have to open a catalog associated with your script. 19e9fd63ecSAdrien Destugues 205393193dSAdrien Destugues\section macros Using the macros 21e9fd63ecSAdrien DestuguesYou don't have to do much in your program to handle catalogs. You must first 22e9fd63ecSAdrien Destuguesset the B_TRANSLATE_CONTEXT define to a string that identifies which part of the 23e9fd63ecSAdrien Destuguesapplication the strings you will translate are in. This allows the translators 24e9fd63ecSAdrien Destuguesto keep track of the strings in the catalog more easily, and find where they are 25e9fd63ecSAdrien Destuguesvisible in the application. then, all you have to do, is enclose any string you 26e9fd63ecSAdrien Destugueswant to make translatable in the B_TRANSLATE() macro. This macro has two uses, 27e9fd63ecSAdrien Destuguesit will allow your text to be replaced at run-time by the proper localized one, 28e9fd63ecSAdrien Destuguesbut it will also allow to build the base catalog, the one that you will send to 29e9fd63ecSAdrien Destuguesthe translator team, from your sourcecode. 30e9fd63ecSAdrien Destugues 315393193dSAdrien Destugues\section chaining Chaining of catalogs 32c6247544SAdrien DestuguesThe catalogs you get from the locale kit are designed to use a fallback system 33c6247544SAdrien Destuguesso that the user get strings in the language he's the more fluent with, 34c6247544SAdrien Destuguesdepending onwhat isavailable. 35c6247544SAdrien Destugues 36c6247544SAdrien DestuguesFor example, if the user set hislanguage preferences as french(France), spanish, 37c6247544SAdrien Destuguesenglish, when an application loads a catalog, the following rules are used : 38c6247544SAdrien Destugues \item Try to load a french(France) catalog. If it is found, this catalog 39c6247544SAdrien Destugueswill automatically include strings from the generic french catalog. 40c6247544SAdrien Destugues \item Try to load a generic french catalog. 41c6247544SAdrien Destugues \item Try to load a generic spanish catalog. 42c6247544SAdrien Destugues \item Try to load a generic english catalog. 43c6247544SAdrien Destugues \item If all of them failed, use the strings that ar ein the source code. 44c6247544SAdrien Destugues 45c6247544SAdrien DestuguesNote that french(France) will failback to french, but then directly to the 46c6247544SAdrien Destugueslanguage in the source code. This avoids mixing 3 or more languages in the same 47c6247544SAdrien Destuguesapplication if the catalogs are incomplete and avoids confusion. 48c6247544SAdrien Destugues 49e9fd63ecSAdrien Destugues*/ 50e9fd63ecSAdrien Destugues 51e9fd63ecSAdrien Destugues/*! 52c6247544SAdrien Destugues\fn BCatalog::BCatalog(const char* signature, const char* language = NULL, uint32 fingerprint = 0) 53c6247544SAdrien Destugues\brief Construct a catalog for the given application. 54e9fd63ecSAdrien Destugues 55e9fd63ecSAdrien DestuguesThis constructor builds a catalog for the application with the given mime 56e9fd63ecSAdrien Destuguessignature. In Haiku, the mime signature is used as a way to uniquely identify a 57e9fd63ecSAdrien Destuguescatalog and match it with the corresponding application. 58e9fd63ecSAdrien Destugues 59e9fd63ecSAdrien DestuguesIf you don't specify a language, the system default list will be used. 60e9fd63ecSAdrien DestuguesThe language is passed here as a 2 letter ISO code. 61e9fd63ecSAdrien Destugues 62e9fd63ecSAdrien DestuguesThe fingerprint is a way to check that the catalog that will be loaded matches 63e9fd63ecSAdrien Destuguesthe current version of the application. A catalog made for a different version 64e9fd63ecSAdrien Destuguesof the application can be loaded if you set the fingerprint to 0. This is 65e9fd63ecSAdrien Destuguesusually not a problem, it only means that some strings may not be translated 66e9fd63ecSAdrien Destuguesproperly. But if you want to provide different versions of your application, it 67e9fd63ecSAdrien Destuguesmay be useful to separate their catalogs. 68e9fd63ecSAdrien Destugues 69*e82e8f36SAdrien Destugues\param signature Mime-signature of the application for which to load a catalog. 70*e82e8f36SAdrien Destugues\param language The language of the catalog to load. If NULL, the user settings will be used. 71*e82e8f36SAdrien Destugues\param fingerprint The fingerprint version-info for the catalog to load. If 0, the fingerprint will 72*e82e8f36SAdrien Destuguesnot be checked,and any version of the catalog will be loaded. 73e9fd63ecSAdrien Destugues*/ 74e9fd63ecSAdrien Destugues 75e9fd63ecSAdrien Destugues/*! 76c6247544SAdrien Destugues\fn const char* BCatalog::GetString(const char* string, const char* context = NULL, const char* comment = NULL) 77c6247544SAdrien Destugues\brief Get a string from the catalog. 78e9fd63ecSAdrien Destugues 79e9fd63ecSAdrien DestuguesThis method access the data of the catalog and reeturns you the translated 80e9fd63ecSAdrien Destuguesversion of the string. You must pass it the context where the string is, as 81e9fd63ecSAdrien Destuguesthe same string may appear somewhere else and need a differnet translation. 82e9fd63ecSAdrien DestuguesThe comment is optional. It is meant as an help to translators, when the string 83e9fd63ecSAdrien Destuguesalone is not helpful enough or there are special things to note. The comment is 84e9fd63ecSAdrien Destuguesalso used as a way to uniquely identify a string, so if two identical strings 85e9fd63ecSAdrien Destuguesshare the same context, it is still possible to provide different translations. 86e9fd63ecSAdrien Destugues 87*e82e8f36SAdrien Destugues\returns The translated string, or the one passed as a parameter if no translation was found. 88*e82e8f36SAdrien Destugues\param string The string to translate. 89*e82e8f36SAdrien Destugues\param context The context where the string is located. 90*e82e8f36SAdrien Destugues\param comment Supplementary comment for translators. 91*e82e8f36SAdrien Destugues*/ 92*e82e8f36SAdrien Destugues 93*e82e8f36SAdrien Destugues/*! 94*e82e8f36SAdrien Destugues\fn const char* GetString(uint32 id) 95*e82e8f36SAdrien Destugues\brief Get a string by id from the catalog. 96*e82e8f36SAdrien Destugues 97e9fd63ecSAdrien DestuguesThe id based version of this method is slightly faster, as it doesn't have to 98e9fd63ecSAdrien Destuguescompute the hash from the 3 parameters. However, it will fail if there is an 99e9fd63ecSAdrien Destugueshash collision, so you should still fallback to the first one in case of 100e9fd63ecSAdrien Destuguesproblems. Also note that the hash value may be different from one catalog to 101e9fd63ecSAdrien Destuguesanother, depending on the file format they are stored in, so you shouldn't rely 102e9fd63ecSAdrien Destugueson this method unless you are sure you can keep all the catalog files under 103e9fd63ecSAdrien Destuguescontrol. 104e9fd63ecSAdrien Destugues 105*e82e8f36SAdrien Destugues\returns The translated string if found, or an empty string. 106*e82e8f36SAdrien Destugues\param id The identifier of the string. 107e9fd63ecSAdrien Destugues*/ 108e9fd63ecSAdrien Destugues 109c6247544SAdrien Destugues/*! 110c6247544SAdrien Destugues\fn const char* BCatalog::GetStringNoAutoCollate(const char* string, const char* context = NULL, const char* comment = NULL) 111c6247544SAdrien Destugues\fn const char* GetStringNoAutoCollate(uint32 id) 112c6247544SAdrien Destugues\brief Get a string from the catalog, without registering it for collectcatkeys. 113c6247544SAdrien Destugues 114c6247544SAdrien DestuguesThis function does exactly the same thing as GetString, except it will not be 115c6247544SAdrien Destuguesparsed by the collectcatkeys tool. This allows you, for example, to translate a 116c6247544SAdrien Destuguesstring constant that you declared at another place, without getting a warning 117c6247544SAdrien Destuguesmessage from collectcatkeys. 118c6247544SAdrien Destugues 119*e82e8f36SAdrien Destugues\returns The translated string, or the one passed as a parameter if no translation was found. 120*e82e8f36SAdrien Destugues\param string The string to translate. 121*e82e8f36SAdrien Destugues\param context The context where the string is located. 122*e82e8f36SAdrien Destugues\param comment Supplementary comment for translators. 123c6247544SAdrien Destugues*/ 124c6247544SAdrien Destugues 125c6247544SAdrien Destugues 126c6247544SAdrien Destugues/*! 127c6247544SAdrien Destugues\fn status_t BCatalog::GetData(const char* name, BMessage* msg) 128c6247544SAdrien Destugues\fn status_t BCatalog::GetData(uint32 id, BMessage* msg) 129c6247544SAdrien Destugues\brief Get custom data from the catalog. 130c6247544SAdrien Destugues 131c6247544SAdrien DestuguesThis function allows you to localize something else than raw text. This may 132c6247544SAdrien Destuguesinclude pictures, sounds, videos, or anything else. Note there is no support for 133c6247544SAdrien Destuguesgeneratinga catalog with such data inside, and the current format may not 134c6247544SAdrien Destuguessupport it. If you need to localize data that is not text, it is advised to 135c6247544SAdrien Destugueshandle it by yourself. 136c6247544SAdrien Destugues 137*e82e8f36SAdrien Destugues\returns An error code. 138*e82e8f36SAdrien Destugues\param name The name of the data to retrieve. 139*e82e8f36SAdrien Destugues\param msg The BMessage to fillin with the data. 140c6247544SAdrien Destugues*/ 141c6247544SAdrien Destugues 142c6247544SAdrien Destugues/*! 143c6247544SAdrien Destugues\fn status_t BCatalog::GetSignature(BString* sig) 144c6247544SAdrien Destugues\brief Get the catalog mime-signature. 145c6247544SAdrien Destugues 146c6247544SAdrien DestuguesThis function fills the sig string with the mime-signature associated to the 147c6247544SAdrien Destuguescatalog. 148c6247544SAdrien Destugues 149*e82e8f36SAdrien Destugues\param sig The string where to copy the signature. 150*e82e8f36SAdrien Destugues\returns An error code. 151c6247544SAdrien Destugues*/ 152c6247544SAdrien Destugues 153c6247544SAdrien Destugues/*! 154c6247544SAdrien Destugues\fn status_t BCatalog::GetLanguage(BString* lang) 155c6247544SAdrien Destugues\brief Get the catalog language. 156c6247544SAdrien Destugues 157c6247544SAdrien DestuguesThis function fills the lang string with the language name for the catalog. 158*e82e8f36SAdrien Destugues 159*e82e8f36SAdrien Destugues\param sig The string where to copy the language. 160*e82e8f36SAdrien Destugues\returns An error code. 161c6247544SAdrien Destugues*/ 162c6247544SAdrien Destugues 163c6247544SAdrien Destugues/*! 164c6247544SAdrien Destugues\fn status_t BCatalog::GetFingerprint(uint32* fp) 165c6247544SAdrien Destugues\brief Get the catalog fingerprint. 166c6247544SAdrien Destugues 167c6247544SAdrien DestuguesThis function setsfp to the fingerprint of the catalog. This allows you to check 168c6247544SAdrien Destugueswhich version of the sourcecode this catalog was generated from. 169*e82e8f36SAdrien Destugues 170*e82e8f36SAdrien Destugues\returns An error code. 171*e82e8f36SAdrien Destugues\param fp The integer to set to the fingerprint value. 172c6247544SAdrien Destugues*/ 173c6247544SAdrien Destugues 174c6247544SAdrien Destugues/*! 175c6247544SAdrien Destugues\fn status_t BCatalog::SetCatalog(const char* signature, uint32 fingerprint) 176c6247544SAdrien Destugues\brief Reload the string data. 177c6247544SAdrien Destugues 178c6247544SAdrien DestuguesThis function reloads the data for the given signature and fingerprint. 179*e82e8f36SAdrien Destugues 180*e82e8f36SAdrien Destugues\returns An error code. 181*e82e8f36SAdrien Destugues\param signature The signature of the catalog youwant to load 182*e82e8f36SAdrien Destugues\param fingerprint The fingerprint of the catalog you want to load. 183c6247544SAdrien Destugues*/ 184c6247544SAdrien Destugues 185c6247544SAdrien Destugues/*! 186c6247544SAdrien Destugues\fn status_t BCatalog::InitCheck() 187c6247544SAdrien Destugues\brief Check if the catalog is in an useable state. 188c6247544SAdrien Destugues 189c6247544SAdrien DestuguesThis function returns B_OK if the catalog is initialized properly. 190c6247544SAdrien Destugues*/ 191c6247544SAdrien Destugues 192c6247544SAdrien Destugues/*! 193c6247544SAdrien Destugues\fn int32 BCatalog::CountItems() 194c6247544SAdrien Destugues\brief Returns the number of items in the catalog. 195c6247544SAdrien Destugues 196c6247544SAdrien DestuguesThis function returns the number of strings in the catalog. 197c6247544SAdrien Destugues*/ 198c6247544SAdrien Destugues 199c6247544SAdrien Destugues/*! 200c6247544SAdrien Destugues\fn BCatalogaddOn* BCatalog::CatalogAddOn() 201c6247544SAdrien Destugues\brief Returns the internal storage for this catalog. 202c6247544SAdrien Destugues 203c6247544SAdrien DestuguesThis function returns the internal storage class used by this catalog. 204c6247544SAdrien DestuguesYou should not have to use it. 205c6247544SAdrien Destugues*/ 206