Scopes is a big topic and continues here with an emphasis on scope locales. As stated previously, the locale provides context-sensitive formatting and parsing of numbers and currencies and is a feature of every scope.
Locale Attributes
The "locale" attribute is a string representation of the locale and will consist of from 2 to 4 components each of which is also an attribute as applicable. The 4 locale components attributes are
- language
- region
- script
- variant
The first two of the above attributes are normally sufficient to fully specify a locale. To assign a particular locale to a scope, use properties in the scope declaration following the name to represent the locale. For example, (language="de", region="DE") specifies the standard German locale.
All the attributes of the current scope are available using a scope attribute expression which is a 2-part name with "scope" as the first part and the attribute name as the second part. For example, the current locale is scope.locale.
Note that a "country" attribute is provided as an alternative attribute expression to "region" as usually the two are synonymous.
show-locale.taq demonstrates scope attributes 'name', 'language', 'region' and "locale" for a scope named "luxemberg". The scope has nothing other than two locale properties. A second query is included which executes in the global scope. In this case, the locale will default according to system settings.
template locale
(
language = scope.language,
region = scope.region,
locale = scope.locale
query<term> lux_locale(luxenberg.locale)
query<term> global_locale(locale)
The result for query "locale_query1" is:
Scope Cascade
euro-total2.taq improves on version 1 in two ways
- A context list holds all the locale-specific data
- A single cascade query replaces having a query for each locale
A context list allows all the data required by each scope to be encapsulated within the scope. There is no need to use scope attributes. The cascade query is appropriate for when only a single solution is required, otherwise use a chained query can be employed as demonstrated in the next section.
This is the axiom context list member of the German scope
{ 0.18, "Gesamtkosten", "Steuer" }
The "charge_plus_tax" template calculates a total amount including tax and then formats a statement in the language of the current scope. Query "item_query" performs the cascade feeding a "locale" axiom as input to each stage
german.locale : german.charge_plus_tax,
belgium_fr.locale : belgium_fr.charge_plus_tax)
Scope Chaining
scope-chain.taq demonstrates a sequence of records being processed by a template in 3 European locale scopes, This is achieved using a query chain where the final link aggregates the output from the preceding links.