locale kit: allow creating a catalog without entry_ref

The catalogs are loaded from separate files, so there is no need to have
an app entry_ref to load them, just a MIME type is enough.

The implementation is a bit simplified: only the default catalog format
is allowed (unlike when loading from entry_ref, where extra catalog
formats can be added in add-ons).

Unrelated cleanup: remove unused code to load catalogs from attributes
of an application. We considered this when designing the locale kit, but
using resources or separate files works better.

Use this in Cortex, where some strings are in a static library, so they
don't have an associated executable or library or add-on to identify
them. The code in Cortex is not complete localization, several parts
should use StringForRate, BStringFormat, etc.

Change-Id: I09be22b1f50891250c4497c51e1db8dcee279140
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3172
Reviewed-by: Kacper Kasper <[email protected]>
This commit is contained in:
Adrien Destugues
2020-09-01 18:14:57 +00:00
committed by Adrien Destugues
parent 5c5a5dbbcc
commit 41853a8bbf
9 changed files with 519 additions and 321 deletions
+47 -5
View File
@@ -8,8 +8,8 @@
* Oliver Tappe, [email protected]
*
* Corresponds to:
* headers/os/locale/Catalog.h hrev45083
* src/kits/locale/Catalog.cpp hrev45083
* headers/os/locale/Catalog.h hrev54533
* src/kits/locale/Catalog.cpp hrev54533
*/
@@ -109,7 +109,8 @@
different versions of your application, it may be useful to separate their
catalogs.
\param catalogOwner entry_ref for which to load a catalog.
\param catalogOwner entry_ref or application, add-on or library for which
to load a catalog.
\param language The language of the catalog to load. If \c NULL, the user
settings will be used.
\param fingerprint The fingerprint version-info for the catalog to load.
@@ -120,6 +121,29 @@
*/
/*!
\fn BCatalog::BCatalog(const char* signature, const char* language)
\brief Construct a BCatalog object for the given application \a signqture.
If you don't specify a language, the system default list will be used.
The language is passed here as a 2 letter ISO code.
This constructor is used to load catalogs that are not related to an
executable or library file (so there is no entry_ref usable to identify the
catalog). As it uses only the MIME signature, it cannot load catalogs from
application resources or a catalog file located next to the application.
Only the catalogs in the standard system directories (data/locale/catalogs)
are checked. Moreover, only the default catalog format is available, not
custom formats from catalog add-ons.
\param catalogOwner entry_ref for which to load a catalog.
\param language The language of the catalog to load. If \c NULL, the user
settings will be used.
\since Haiku R1
*/
/*!
\fn BCatalog::~BCatalog()
\brief Destroys the BCatalog object freeing memory used by it.
@@ -269,9 +293,10 @@
const char* language, uint32 fingerprint)
\brief Reload the string data.
This method reloads the data for the given signature and fingerprint.
This method reloads the data for the given file, language and fingerprint.
\param catalogOwner The \c entry_ref of the catalog that you want to load.
\param catalogOwner The \c entry_ref of the application, add-on or library
for which you want to load a catalog.
\param language The language of the catalog to load. If \c NULL, the user
settings will be used.
\param fingerprint The fingerprint of the catalog you want to load.
@@ -282,6 +307,23 @@
*/
/*!
\fn status_t BCatalog::SetTo(const char* signature,
const char* language, uint32 fingerprint)
\brief Reload the string data.
This method reloads the data for the given signature and language.
\param signature The MIME signature identifying the catalog to load.
\param language The language of the catalog to load. If \c NULL, the user
settings will be used.
\returns A status code, \c B_OK on success, \c B_ERROR on error.
\since Haiku R1
*/
/*!
\fn status_t BCatalog::InitCheck() const
\brief Check if the catalog is in a valid and usable state.