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