euro-total.taq

$ java -jar taq.jar euro-total amount=“12.345,67 €”

Running query be_fr_item_query in global scope 
Parameters [euro-total, amount=12.345,67 €]
totals(Total=le total 13 703,69 EUR, Tax=11% impôt, Locale=fr_BE)

Running query de_item_query in global scope 
Parameters [euro-total, amount=12.345,67 €]
totals(Total=Gesamtkosten 14.567,89 EUR, Tax=18% Steuer, Locale=de_DE)

Running query fr_item_query in global scope 
Parameters [euro-total, amount=12.345,67 €]
totals(Total=le total 14 197,52 EUR, Tax=15% impôt, Locale=fr_FR)

Description

euro-total.taq demonstrates the role scopes can play in providing information about locale. Three queries are each assigned a specific locale to create a total amount invoice with language and regional adaptions. Here is how the French scope is declared

scope french (language=“fr”, region=“FR”)

Note that language and region are attributes that all scopes have and are accessed using a 2-part name notation that is distinct from that used for properties

scope.region,
scope.language,

The total amount includes a sales tax applicable to the region and is stated using the locale language.


export list<axiom> totals

scope french (language="fr", region="FR")

scope german (language="de", region="DE")

scope belgium_fr (language="fr", region="BE")

flow charge_plus_tax
{
double percent,
currency amount,
currency total_amount,
select lexicon
(locale, total, tax)
{
? "de_DE": "Gesamtkosten", "Steuer"
? "fr_FR": "le total", "impôt"
? "fr_BE": "le total", "impôt"
}
}
(
percent = map scope.region {
? "DE": 18.0
? "FR": 15.0
? "BE": 11.0 },
total_amount = amount * (1.0 + percent / 100),
locale = scope.locale,
flow lexicon(locale = scope.locale) {
totals += axiom {
Total = total + " " + total_amount.format(),
Tax = percent.format() + "% " + tax,
Locale = locale }
}
)

query de_item_query
( german.charge_plus_tax )
query fr_item_query
( french.charge_plus_tax )
query be_fr_item_query
( belgium_fr.charge_plus_tax )