dmi_set_locale
Description
The dmi_set_locale function sets the locale in which the library looks up
printable strings: names of values, structure types and lint rules, error
messages, and the other strings of the resource packages.
The locale is process-wide rather than a property of a context, since printable
names are looked up by functions which take no context, e.g.
dmi_name_lookup. Resource packages opened before the call are reopened
with the new locale, and the ones opened after it use it as well.
A locale with no translation of its own is not a failure: ICU4C falls back
to a less specific locale, e.g. ru for ru_RU, and strings with no
translation at all are left in English. The locale of the environment is not
fallen back to, so that the strings are never of a locale which has not been
asked for.
The name is copied, so the variable locale points to need not outlive the
call.
Translations are available only if the library is built with ICU4C support. Otherwise the function does nothing, and printable strings are always in English.
Lifetime of strings
Strings looked up for the previous locale are released by the call, so every
pointer returned before it by the functions which look up printable strings,
e.g. dmi_name_lookup, dmi_spec_name, dmi_error_message,
dmi_lint_rule_name, dmi_resource_string and dmi_get_locale,
becomes invalid. Strings which are to be kept across the call must be copied.
Thread safety
The function is not thread-safe, and must not be called while other threads
may use the library. The locale is meant to be set once, at the start of the
program, before the library is used, e.g. by dmi_locale_setup, which takes
it from the environment.
Return value
Returns true if the locale has been set, and false if the name cannot be
copied, if a resource package opened before the call cannot be reopened, or
if the library is built without ICU4C support.
A package which cannot be reopened gives no translated strings until the locale is set again.
The resources of the library itself are the exception: the library has translations for some locales only and leaves its strings in English for the others, so their absence is not a failure. They are opened by the first lookup, and are looked for again once the locale has changed.