dmi_resource_open
Synopsis
#include <opendmi/locale.h>
typedef struct dmi_resource dmi_resource_t;
dmi_resource_t *dmi_resource_open(const char *package, const void *data);
Description
The dmi_resource_open function opens a resource package, a set of ICU4C
resource bundles holding the strings of a program in every language it is
translated to, so that the program can look its strings up the way the
library looks up printable names.
The package is embedded into the program rather than installed as a file.
Bundles of the package are built from ICU4C resource sources, one
<locale>.txt per locale and root.txt with the default strings, and are
packaged by pkgdata into a data object which is linked into the program,
e.g. by the add_resources() function of the OpenDMI build files. The data is
then reachable as the <package>_dat symbol:
extern const char opendmi_dat[];
dmi_resource_t *resource = dmi_resource_open("opendmi", opendmi_dat);
The package is opened with the locale set by dmi_set_locale, and is
reopened with the new one whenever the locale is changed. Locales with no
bundle of their own fall back to a less specific locale, and to the root
bundle at last, but never to the bundle of the locale of the environment. A
package with no root bundle is opened only with the locales it has bundles
for.
The package stays open until it is closed by dmi_resource_close. Strings
are looked up in it by dmi_resource_string, and messages are formatted by
dmi_resource_message.
Return value
Returns a resource handle, or nullptr if an argument is nullptr, if
ICU4C cannot be initialized or the data cannot be registered or opened, if
memory is exhausted, or if the library is built without ICU4C support.
Programs are expected to leave their strings untranslated, rather than fail,
when no handle is returned: the lookup functions accept a nullptr handle,
and find no strings in it.