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