1e9fd63ecSAdrien Destugues/*! 2e9fd63ecSAdrien Destugues\class BCatalog 3e9fd63ecSAdrien Destugues\ingroup locale 4*5393193dSAdrien 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 20*5393193dSAdrien 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 31*5393193dSAdrien 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 69e9fd63ecSAdrien Destugues*/ 70e9fd63ecSAdrien Destugues 71e9fd63ecSAdrien Destugues/*! 72c6247544SAdrien Destugues\fn const char* BCatalog::GetString(const char* string, const char* context = NULL, const char* comment = NULL) 73e9fd63ecSAdrien Destugues\fn const char* GetString(uint32 id) 74c6247544SAdrien Destugues\brief Get a string from the catalog. 75e9fd63ecSAdrien Destugues 76e9fd63ecSAdrien DestuguesThis method access the data of the catalog and reeturns you the translated 77e9fd63ecSAdrien Destuguesversion of the string. You must pass it the context where the string is, as 78e9fd63ecSAdrien Destuguesthe same string may appear somewhere else and need a differnet translation. 79e9fd63ecSAdrien DestuguesThe comment is optional. It is meant as an help to translators, when the string 80e9fd63ecSAdrien Destuguesalone is not helpful enough or there are special things to note. The comment is 81e9fd63ecSAdrien Destuguesalso used as a way to uniquely identify a string, so if two identical strings 82e9fd63ecSAdrien Destuguesshare the same context, it is still possible to provide different translations. 83e9fd63ecSAdrien Destugues 84e9fd63ecSAdrien DestuguesThe id based version of this method is slightly faster, as it doesn't have to 85e9fd63ecSAdrien Destuguescompute the hash from the 3 parameters. However, it will fail if there is an 86e9fd63ecSAdrien Destugueshash collision, so you should still fallback to the first one in case of 87e9fd63ecSAdrien Destuguesproblems. Also note that the hash value may be different from one catalog to 88e9fd63ecSAdrien Destuguesanother, depending on the file format they are stored in, so you shouldn't rely 89e9fd63ecSAdrien Destugueson this method unless you are sure you can keep all the catalog files under 90e9fd63ecSAdrien Destuguescontrol. 91e9fd63ecSAdrien Destugues 92e9fd63ecSAdrien Destugues*/ 93e9fd63ecSAdrien Destugues 94c6247544SAdrien Destugues/*! 95c6247544SAdrien Destugues\fn const char* BCatalog::GetStringNoAutoCollate(const char* string, const char* context = NULL, const char* comment = NULL) 96c6247544SAdrien Destugues\fn const char* GetStringNoAutoCollate(uint32 id) 97c6247544SAdrien Destugues\brief Get a string from the catalog, without registering it for collectcatkeys. 98c6247544SAdrien Destugues 99c6247544SAdrien DestuguesThis function does exactly the same thing as GetString, except it will not be 100c6247544SAdrien Destuguesparsed by the collectcatkeys tool. This allows you, for example, to translate a 101c6247544SAdrien Destuguesstring constant that you declared at another place, without getting a warning 102c6247544SAdrien Destuguesmessage from collectcatkeys. 103c6247544SAdrien Destugues 104c6247544SAdrien Destugues*/ 105c6247544SAdrien Destugues 106c6247544SAdrien Destugues 107c6247544SAdrien Destugues/*! 108c6247544SAdrien Destugues\fn status_t BCatalog::GetData(const char* name, BMessage* msg) 109c6247544SAdrien Destugues\fn status_t BCatalog::GetData(uint32 id, BMessage* msg) 110c6247544SAdrien Destugues\brief Get custom data from the catalog. 111c6247544SAdrien Destugues 112c6247544SAdrien DestuguesThis function allows you to localize something else than raw text. This may 113c6247544SAdrien Destuguesinclude pictures, sounds, videos, or anything else. Note there is no support for 114c6247544SAdrien Destuguesgeneratinga catalog with such data inside, and the current format may not 115c6247544SAdrien Destuguessupport it. If you need to localize data that is not text, it is advised to 116c6247544SAdrien Destugueshandle it by yourself. 117c6247544SAdrien Destugues 118c6247544SAdrien Destugues*/ 119c6247544SAdrien Destugues 120c6247544SAdrien Destugues/*! 121c6247544SAdrien Destugues\fn status_t BCatalog::GetSignature(BString* sig) 122c6247544SAdrien Destugues\brief Get the catalog mime-signature. 123c6247544SAdrien Destugues 124c6247544SAdrien DestuguesThis function fills the sig string with the mime-signature associated to the 125c6247544SAdrien Destuguescatalog. 126c6247544SAdrien Destugues 127c6247544SAdrien Destugues*/ 128c6247544SAdrien Destugues 129c6247544SAdrien Destugues/*! 130c6247544SAdrien Destugues\fn status_t BCatalog::GetLanguage(BString* lang) 131c6247544SAdrien Destugues\brief Get the catalog language. 132c6247544SAdrien Destugues 133c6247544SAdrien DestuguesThis function fills the lang string with the language name for the catalog. 134c6247544SAdrien Destugues*/ 135c6247544SAdrien Destugues 136c6247544SAdrien Destugues/*! 137c6247544SAdrien Destugues\fn status_t BCatalog::GetFingerprint(uint32* fp) 138c6247544SAdrien Destugues\brief Get the catalog fingerprint. 139c6247544SAdrien Destugues 140c6247544SAdrien DestuguesThis function setsfp to the fingerprint of the catalog. This allows you to check 141c6247544SAdrien Destugueswhich version of the sourcecode this catalog was generated from. 142c6247544SAdrien Destugues*/ 143c6247544SAdrien Destugues 144c6247544SAdrien Destugues/*! 145c6247544SAdrien Destugues\fn status_t BCatalog::SetCatalog(const char* signature, uint32 fingerprint) 146c6247544SAdrien Destugues\brief Reload the string data. 147c6247544SAdrien Destugues 148c6247544SAdrien DestuguesThis function reloads the data for the given signature and fingerprint. 149c6247544SAdrien Destugues*/ 150c6247544SAdrien Destugues 151c6247544SAdrien Destugues/*! 152c6247544SAdrien Destugues\fn status_t BCatalog::InitCheck() 153c6247544SAdrien Destugues\brief Check if the catalog is in an useable state. 154c6247544SAdrien Destugues 155c6247544SAdrien DestuguesThis function returns B_OK if the catalog is initialized properly. 156c6247544SAdrien Destugues*/ 157c6247544SAdrien Destugues 158c6247544SAdrien Destugues/*! 159c6247544SAdrien Destugues\fn int32 BCatalog::CountItems() 160c6247544SAdrien Destugues\brief Returns the number of items in the catalog. 161c6247544SAdrien Destugues 162c6247544SAdrien DestuguesThis function returns the number of strings in the catalog. 163c6247544SAdrien Destugues*/ 164c6247544SAdrien Destugues 165c6247544SAdrien Destugues/*! 166c6247544SAdrien Destugues\fn BCatalogaddOn* BCatalog::CatalogAddOn() 167c6247544SAdrien Destugues\brief Returns the internal storage for this catalog. 168c6247544SAdrien Destugues 169c6247544SAdrien DestuguesThis function returns the internal storage class used by this catalog. 170c6247544SAdrien DestuguesYou should not have to use it. 171c6247544SAdrien Destugues*/ 172