1a33f8fbdSAdrien Destugues/* 2820dca4dSJohn Scipione * Copyright 2003-2010 Haiku, Inc. All rights reserved. 3a33f8fbdSAdrien Destugues * Distributed under the terms of the MIT License. 4a33f8fbdSAdrien Destugues * 5a33f8fbdSAdrien Destugues * Authors: 6a33f8fbdSAdrien Destugues * Axel Dörfler, axeld@pinc-software.de 7a33f8fbdSAdrien Destugues * John Scipione, jscipione@gmail.com 8a33f8fbdSAdrien Destugues * Oliver Tappe, zooey@hirschkaefer.de 9a33f8fbdSAdrien Destugues * 10a33f8fbdSAdrien Destugues * Corresponds to: 11820dca4dSJohn Scipione * headers/os/locale/LocaleRoster.h rev 42274 12820dca4dSJohn Scipione * src/kits/locale/LocaleRoster.cpp rev 42274 13820dca4dSJohn Scipione */ 14820dca4dSJohn Scipione 15820dca4dSJohn Scipione 16820dca4dSJohn Scipione/*! 17820dca4dSJohn Scipione \file LocaleRoster.h 18820dca4dSJohn Scipione \ingroup locale 19820dca4dSJohn Scipione \ingroup libbe 20820dca4dSJohn Scipione \brief Provides the BLocaleRoster class to access locale data. 21a33f8fbdSAdrien Destugues*/ 22a33f8fbdSAdrien Destugues 23a33f8fbdSAdrien Destugues 24e82e8f36SAdrien Destugues/*! 25e82e8f36SAdrien Destugues \class BLocaleRoster 26e82e8f36SAdrien Destugues \ingroup locale 27820dca4dSJohn Scipione \ingroup libbe 28820dca4dSJohn Scipione \brief Main class for accessing the Locale Kit data. 29e82e8f36SAdrien Destugues 30a33f8fbdSAdrien Destugues The Locale Roster is the central part of the locale kit. It is a global 31a33f8fbdSAdrien Destugues object (\c be_locale_roster) storing all the useful locale data. Other 32a33f8fbdSAdrien Destugues classes from the Locale Kit can be constructed on their own, but only the 33a33f8fbdSAdrien Destugues Locale Roster allows you to do so while taking account of the user's locale 34a33f8fbdSAdrien Destugues settings. 35*edc845a3SJohn Scipione 36*edc845a3SJohn Scipione \since Haiku R1 37e82e8f36SAdrien Destugues*/ 38e82e8f36SAdrien Destugues 39e82e8f36SAdrien Destugues 40e82e8f36SAdrien Destugues/*! 41a33f8fbdSAdrien Destugues \fn BLocaleRoster::BLocaleRoster() 42a33f8fbdSAdrien Destugues \brief Constructor. Does nothing. 43*edc845a3SJohn Scipione 44*edc845a3SJohn Scipione \since Haiku R1 45e82e8f36SAdrien Destugues*/ 46e82e8f36SAdrien Destugues 47e82e8f36SAdrien Destugues 48e82e8f36SAdrien Destugues/*! 49a33f8fbdSAdrien Destugues \fn BLocaleRoster::~BLocaleRoster() 50a33f8fbdSAdrien Destugues \brief Destructor. Does nothing. 51*edc845a3SJohn Scipione 52*edc845a3SJohn Scipione \since Haiku R1 53e82e8f36SAdrien Destugues*/ 54e82e8f36SAdrien Destugues 55a33f8fbdSAdrien Destugues 56a33f8fbdSAdrien Destugues/*! 57a33f8fbdSAdrien Destugues \fn BLocaleRoster* BLocaleRoster::Default() 58a33f8fbdSAdrien Destugues \brief Returns default BLocalRoster. 59*edc845a3SJohn Scipione 60*edc845a3SJohn Scipione \since Haiku R1 61a33f8fbdSAdrien Destugues*/ 62a33f8fbdSAdrien Destugues 63a33f8fbdSAdrien Destugues 64a33f8fbdSAdrien Destugues/*! 65a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::Refresh() 66a33f8fbdSAdrien Destugues \brief Refreshes the BLocalRoster. 67*edc845a3SJohn Scipione 68*edc845a3SJohn Scipione \since Haiku R1 69a33f8fbdSAdrien Destugues*/ 70a33f8fbdSAdrien Destugues 71a33f8fbdSAdrien Destugues 72e82e8f36SAdrien Destugues/*! 73e82e8f36SAdrien Destugues \fn status_t BLocaleRoster::GetDefaultTimeZone(BTimeZone* timezone) const 74e82e8f36SAdrien Destugues \brief Get the default timezone. 75*edc845a3SJohn Scipione 76*edc845a3SJohn Scipione \since Haiku R1 77e82e8f36SAdrien Destugues*/ 78e82e8f36SAdrien Destugues 79e82e8f36SAdrien Destugues 80e82e8f36SAdrien Destugues/*! 81a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetLanguage(const char* languagecode, 82a33f8fbdSAdrien Destugues BLanguage** _language) const 83a33f8fbdSAdrien Destugues \brief Instantiate a language from its code. 84*edc845a3SJohn Scipione 85*edc845a3SJohn Scipione \since Haiku R1 86e82e8f36SAdrien Destugues*/ 87e82e8f36SAdrien Destugues 88cae874d3SAdrien Destugues 89cae874d3SAdrien Destugues/*! 90cae874d3SAdrien Destugues \fn status_t BLocaleRoster::GetPreferredLanguages(BMessage* message) const 91cae874d3SAdrien Destugues \brief Return the list of user preferred languages. 92cae874d3SAdrien Destugues 93cae874d3SAdrien Destugues This function fills in the given message with one or more language string 94a33f8fbdSAdrien Destugues fields. They constitute the ordered list of user-selected languages to use 95a33f8fbdSAdrien Destugues for string translation. 96*edc845a3SJohn Scipione 97*edc845a3SJohn Scipione \since Haiku R1 98a33f8fbdSAdrien Destugues*/ 99a33f8fbdSAdrien Destugues 100a33f8fbdSAdrien Destugues 101a33f8fbdSAdrien Destugues/*! 102a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetAvailableLanguages(BMessage* message) const 103a33f8fbdSAdrien Destugues \brief Fills \c message with 'language'-fields containing the language 104a33f8fbdSAdrien Destugues ID(s) of all available languages. 105*edc845a3SJohn Scipione 106*edc845a3SJohn Scipione \since Haiku R1 107a33f8fbdSAdrien Destugues*/ 108a33f8fbdSAdrien Destugues 109a33f8fbdSAdrien Destugues 110a33f8fbdSAdrien Destugues/*! 111a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetAvailableCountries(BMessage* message) const 112a33f8fbdSAdrien Destugues \brief Fills in the passed in \a message with one or more 'country' 113a33f8fbdSAdrien Destugues string fields, containing the (ISO-639) code of each country. 114*edc845a3SJohn Scipione 115*edc845a3SJohn Scipione \since Haiku R1 116a33f8fbdSAdrien Destugues*/ 117a33f8fbdSAdrien Destugues 118a33f8fbdSAdrien Destugues 119a33f8fbdSAdrien Destugues/*! 120a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetAvailableTimeZones(BMessage* timeZones) const 121a33f8fbdSAdrien Destugues \brief Fills in the passed in \a timeZones message with all time zone 122a33f8fbdSAdrien Destugues strings for the locale. 123a33f8fbdSAdrien Destugues 124a33f8fbdSAdrien Destugues \returns A status code. 125a33f8fbdSAdrien Destugues \retval B_OK Everything went well. 126a33f8fbdSAdrien Destugues \retval B_BAD_VALUE A \c NULL \a timeZones message was passed in. 127a33f8fbdSAdrien Destugues \retval B_ERROR An error occurred trying to retrieve the localized time zone 128a33f8fbdSAdrien Destugues strings. 129*edc845a3SJohn Scipione 130*edc845a3SJohn Scipione \since Haiku R1 131a33f8fbdSAdrien Destugues*/ 132a33f8fbdSAdrien Destugues 133a33f8fbdSAdrien Destugues 134a33f8fbdSAdrien Destugues/*! 135a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetAvailableTimeZonesForCountry( 136a33f8fbdSAdrien Destugues BMessage* timeZones, const char* countryCode) const 137a33f8fbdSAdrien Destugues \brief Fills in the passed in \a timeZones message with one or more 138a33f8fbdSAdrien Destugues time zone strings containing the time zones for the 139a33f8fbdSAdrien Destugues country specified by \a countryCode for the locale. 140a33f8fbdSAdrien Destugues 141a33f8fbdSAdrien Destugues \returns A status code. 142a33f8fbdSAdrien Destugues \retval B_OK Everything went well. 143a33f8fbdSAdrien Destugues \retval B_BAD_VALUE A \c NULL \a timeZones message was passed in. 144a33f8fbdSAdrien Destugues \retval B_ERROR An error occurred trying to retrieve the localized time 145a33f8fbdSAdrien Destugues zones most likely due to an invalid \a countryCode. 146*edc845a3SJohn Scipione 147*edc845a3SJohn Scipione \since Haiku R1 148a33f8fbdSAdrien Destugues*/ 149a33f8fbdSAdrien Destugues 150a33f8fbdSAdrien Destugues 151a33f8fbdSAdrien Destugues/*! 152a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetFlagIconForCountry(BBitmap* flagIcon, 153a33f8fbdSAdrien Destugues const char* countryCode) 154a33f8fbdSAdrien Destugues \brief Sets \a flagIcon to the flag for the passed in \a countryCode. 155a33f8fbdSAdrien Destugues 156a33f8fbdSAdrien Destugues \returns A status code. 157a33f8fbdSAdrien Destugues \retval B_OK Everything went well. 158a33f8fbdSAdrien Destugues \retval B_BAD_VALUE A \c NULL or invalid \a countryCode was passed in. 159a33f8fbdSAdrien Destugues \retval B_ERROR Error locking the default RosterData. 160a33f8fbdSAdrien Destugues \retval B_NAME_NOT_FOUND The flag could not be found for the 161a33f8fbdSAdrien Destugues \a countryCode. 162*edc845a3SJohn Scipione 163*edc845a3SJohn Scipione \since Haiku R1 164a33f8fbdSAdrien Destugues*/ 165a33f8fbdSAdrien Destugues 166a33f8fbdSAdrien Destugues 167a33f8fbdSAdrien Destugues/*! 168a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetFlagIconForLanguage(BBitmap* flagIcon, 169a33f8fbdSAdrien Destugues const char* languageCode) 170a33f8fbdSAdrien Destugues \brief Sets \a flagIcon to the flag for the passed in \a languageCode. 171a33f8fbdSAdrien Destugues 172a33f8fbdSAdrien Destugues If a flag could not be located for the passed in \a languageCode then 173a33f8fbdSAdrien Destugues GetFlagIconForLanguage() attempts to locate the default country's flag for 174a33f8fbdSAdrien Destugues the \a languageCode instead. The default country flag for a language is 175a33f8fbdSAdrien Destugues usually set to the country of the languages origin such as Germany for 176a33f8fbdSAdrien Destugues German or Spain for Spanish. 177a33f8fbdSAdrien Destugues 178a33f8fbdSAdrien Destugues \returns A status code. 179a33f8fbdSAdrien Destugues \retval B_OK Everything went well. 180a33f8fbdSAdrien Destugues \retval B_BAD_VALUE A \c NULL or invalid \a languageCode was passed in. 181a33f8fbdSAdrien Destugues \retval B_ERROR Error locking the default RosterData. 182a33f8fbdSAdrien Destugues \retval B_NAME_NOT_FOUND The flag could not be found for the 183a33f8fbdSAdrien Destugues default country's flag for the \a languageCode. 184*edc845a3SJohn Scipione 185*edc845a3SJohn Scipione \since Haiku R1 186a33f8fbdSAdrien Destugues*/ 187a33f8fbdSAdrien Destugues 188a33f8fbdSAdrien Destugues 189a33f8fbdSAdrien Destugues/*! 190a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetAvailableCatalogs(BMessage* languageList, 191a33f8fbdSAdrien Destugues const char* sigPattern, const char* langPattern, 192a33f8fbdSAdrien Destugues int32 fingerprint) const 193a33f8fbdSAdrien Destugues \brief Get the available locales and catalogs. 194a33f8fbdSAdrien Destugues 195a33f8fbdSAdrien Destugues Fills the passed \a languageList message with one or more 'locale' string 196a33f8fbdSAdrien Destugues fields containing the locale names. 197a33f8fbdSAdrien Destugues 198a33f8fbdSAdrien Destugues The optional parameters can be used to filter the list and only get the 199a33f8fbdSAdrien Destugues locales for which a catalog is available for the given app (sigPattern, 200a33f8fbdSAdrien Destugues fingerprint), or the locales with a given language. 201a33f8fbdSAdrien Destugues 202a33f8fbdSAdrien Destugues \returns A status code. 203a33f8fbdSAdrien Destugues \retval B_OK Everything went well. 204a33f8fbdSAdrien Destugues \retval B_BAD_VALUE A \c NULL \a languageList message was passed in. 205a33f8fbdSAdrien Destugues \retval B_ERROR Error locking the default RosterData. 206*edc845a3SJohn Scipione 207*edc845a3SJohn Scipione \since Haiku R1 208a33f8fbdSAdrien Destugues*/ 209a33f8fbdSAdrien Destugues 210a33f8fbdSAdrien Destugues 211a33f8fbdSAdrien Destugues/*! 212a33f8fbdSAdrien Destugues \fn bool BLocaleRoster::IsFilesystemTranslationPreferred() const 213a33f8fbdSAdrien Destugues \brief Returns whether or not filesystem translation is preferred. 214a33f8fbdSAdrien Destugues 215a33f8fbdSAdrien Destugues \returns \c B_ERROR if there was an error locking the default RosterData. 216*edc845a3SJohn Scipione 217*edc845a3SJohn Scipione \since Haiku R1 218a33f8fbdSAdrien Destugues*/ 219a33f8fbdSAdrien Destugues 220a33f8fbdSAdrien Destugues 221a33f8fbdSAdrien Destugues/*! 222a33f8fbdSAdrien Destugues \fn status_t BLocaleRoster::GetLocalizedFileName(BString& localizedFileName, 223a33f8fbdSAdrien Destugues const entry_ref& ref, bool traverse) 224a33f8fbdSAdrien Destugues \brief Looks up a localized filename from a catalog. 225a33f8fbdSAdrien Destugues 226a33f8fbdSAdrien Destugues Attribute format: "signature:context:string" 227a33f8fbdSAdrien Destugues (no colon in any of signature, context and string) 228a33f8fbdSAdrien Destugues 229a33f8fbdSAdrien Destugues Lookup is done for the top preferred language only. 230a33f8fbdSAdrien Destugues Lookup fails if a comment is present in the catalog entry. 231a33f8fbdSAdrien Destugues 232a33f8fbdSAdrien Destugues \param localizedFileName A pre-allocated BString object for the result 233a33f8fbdSAdrien Destugues of the lookup. 234a33f8fbdSAdrien Destugues \param ref An entry_ref with an attribute holding data for catalog lookup. 235a33f8fbdSAdrien Destugues \param traverse Determines if symlinks should be traversed. 236a33f8fbdSAdrien Destugues 237a33f8fbdSAdrien Destugues \returns A status code. 238a33f8fbdSAdrien Destugues \retval B_OK: success 239a33f8fbdSAdrien Destugues \retval B_ENTRY_NOT_FOUND: failure. Attribute not found, entry not found 240a33f8fbdSAdrien Destugues in catalog, etc. 241*edc845a3SJohn Scipione 242*edc845a3SJohn Scipione \since Haiku R1 243a33f8fbdSAdrien Destugues*/ 244a33f8fbdSAdrien Destugues 245a33f8fbdSAdrien Destugues 246a33f8fbdSAdrien Destugues/*! 2476ec9625aSAdrien Destugues \fn BCatalog* BLocaleRoster::_GetCatalog(BCatalog* catalog, 2486ec9625aSAdrien Destugues vint32* catalogInitStatus) 249a33f8fbdSAdrien Destugues \brief Get the current image catalog. 250a33f8fbdSAdrien Destugues 2516ec9625aSAdrien Destugues This function initializes and returns the catalog for the calling image 2526ec9625aSAdrien Destugues (application, add-on, or shared library). Note that it doesn't allow to 2536ec9625aSAdrien Destugues specify a fingerprint. The language will be selected from the user 2546ec9625aSAdrien Destugues preferences. 255a33f8fbdSAdrien Destugues 2566ec9625aSAdrien Destugues This function is used by the Locale Kit macros. 2576ec9625aSAdrien Destugues 2586ec9625aSAdrien Destugues \warning This function needs the calling image to be linked with 2596ec9625aSAdrien Destugues liblocalestub.a 260a33f8fbdSAdrien Destugues 261a33f8fbdSAdrien Destugues \returns The catalog, if it was loaded successfully. 2626ec9625aSAdrien Destugues 263*edc845a3SJohn Scipione \param catalog The catalog to load. The pointer location is used to 264*edc845a3SJohn Scipione identify the image for which to load the catalog. 265*edc845a3SJohn Scipione \param catalogInitStatus the state of the catalog. This will be set to 266*edc845a3SJohn Scipione true on the first call for a given catalog, and if already true 267*edc845a3SJohn Scipione the function will do nothing on subsequent calls. 268*edc845a3SJohn Scipione 269*edc845a3SJohn Scipione \since Haiku R1 270cae874d3SAdrien Destugues*/ 271