Template-Axiom-Query (TAQ)

Locales

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

  1. language
  2. region
  3. script
  4. 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.

scope luxenberg (language="fr", region="LU")

template locale
(
name = scope.name,
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:

locale(name=luxenberg, language=fr, region=LU, locale=fr_LU)
Scope Attributes
AttributeDescription
nameScope name
localeString representation of the locale eg. "de_DE" for German
languageLanguage code of locale
countryCountry/region code of locale
scriptScript of locale
variantVariant of locale

Note that script and variant are likely to be blank.

euro-total.taq shows two scope attributes used to customize an invoice for 3 different European locales so that the text and percentage tax charged are correct for the location where the query is being executed. Here is the body of the "charge_plus_tax" flow. Look for scope.region and scope.locale

percent = map scope.region {
? "DE": 18.0
? "FR": 15.0
? "BE": 11.0 },
total_amount = amount * (1.0 + percent / 100),
flow lexicon(locale = scope.locale) {
totals += axiom {
Total = total + " " + total_amount.format(),
Tax = percent.format() + "% " + tax,
Locale = locale }
}