Module locale

A properties bundle consists of multiple properties files that vary in the file name by an injection of a locale code before the file extension. Our convention is that each bundle must contain a properties file without injection. This file acts as a root for the bundle and as a fall-back for locales that are not found:

Examples:
code.properties:    The root and fall-back.
code_de.properties: The German member of the bundle.

The predicates sys_get_lang/2 and sys_get_lang/3 allow retrieving a locale properties file of a resource bundle. These predicates make use of the predicate absolute_resource_name/2 to resolve the root so that the same base name without an extension can be used for both Prolog text and resource bundles. The resource bundle itself has to be loaded in advanced via the predicate sys_load_resoruce/1.

Examples:
:- sys_load_resource('code').
test(Y) :- sys_get_lang('code',X), get_property(X,'foo',Y).
?- test(X).
X = bar

The retrieval of a locale properties file is relatively fast, since we cache locale properties files on a per resource bundle basis. But it still not yet as fast and flexible as predicate invocation, since we have not yet implemented a call-site cache and an auto loader for resource bundles. The predicates get_property/3 and get_property/4 allow retrieving a property value from a locale properties file.

The predicate atom_format/[3,4] allows formatting a list of arguments based on a template and a locale. The predicates message_make/[3,4] and error_make/[3,4] allow formatting a term based on properties file and a locale. The predicates get_error_properties/[1,2] and get_description_properties/[2,3] allow retrieving knowledgebase respective capability defined properties files.

The following locale predicates are provided:
sys_get_lang(S, P):
sys_get_lang(S, L, P):
The predicate unifies P with the properties from the bundle S for the current default locale. The ternary version of the predicate allows specifying the locale L.The resource bundle S has to be loaded in advance via sys_load_resource/1.
get_property(P, K, V):
get_property(P, K, D, V):
The predicate unifies V with the value for the key K from the properties P. The quaternary version of the predicate allows specifying a default value D.
atom_format(F, A, S):
atom_format(L, F, A, S):
The predicate formats the arguments A from the format F and unifies the result with S. The quaternary predicate allows specifying a locale L.
message_make(P, M, S):
message_make(L, P, M, S):
The predicate formats the message term M from the properties P and unifies the result with S. The quaternary predicate allows specifying a locale L.
error_make(P, E, S):
error_make(L, P, E, S):
The predicate formats the error term E without its context from the properties P and unifies the result with S. The quaternary predicate allows specifying a locale L.
get_error_properties(P):
get_error_properties(L, P):
The predicate unifies P with the error properties of the knowledge base. The binary predicate allows specifying a locale L. The error resource bundles have to be loaded in advance via sys_load_resource/1.
get_description_properties(C, P):
get_description_properties(L, C, P):
The predicate unifies P with the description properties of the given capability C. The ternary predicate allows specifying a locale L.

The following locale Prolog flags are provided:

sys_locale:
Legal values are atoms as return by the Java method Locale.toString(). The flag indicates the current default locale. The value can be changed by the end-user.

Comments