Skip to content
Astera Technology

Render documents with a supplied locale profile

Change labels and punctuation while retaining the source quantity.

Download complete case notes and answer keys ↓

Set the decision and its input

The supplied English and zh-HK profiles define labels, colon spacing and unit punctuation separately. A Chinese document with quantity zero must render 合共:0 件。 and lang=zh-HK. Merely setting the language attribute while retaining English output does not apply that profile.

Filled local test worksheet
CaseInput JSON
Base test{"locale":"zh-HK","quantity":0}
Download editable CSV ↓

Run the supplied comparison

The programme queries actual rendered text, the article language and the unchanged data value. The profiles are original supplied copy; no automatic translation equivalence is claimed.

Faulty and required outputs
PathOutput JSON
Faulty path{"lang":"zh-HK","text":"Total: 0 units.","quantity":"0"}
Required path{"lang":"zh-HK","text":"合共:0 件。","quantity":"0"}
Download editable CSV ↓
Node24.14.1 programme; Playwright1.63 Chromium required
import assert from 'node:assert/strict';
const smallWhole=(x,max)=>Number.isSafeInteger(x)&&x>=0&&x<=max;
import {createRequire} from 'node:module';
const htmlEscape=s=>String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
async function withPage(action,options={}){
  const require=createRequire(import.meta.url);const {chromium}=require('playwright');
  const browser=await chromium.launch({headless:true});
  try{const context=await browser.newContext(options);const page=await context.newPage();
    const requests=[];await page.route('**/*',route=>{requests.push(route.request().url());return route.abort();});
    return await action(page,context,requests);
  }finally{await browser.close();}
}

const run=async function run(i,corrected=true){
    const profiles={en:{label:'Total',colon:': ',unit:' units.'},'zh-HK':{label:'合共',colon:':',unit:' 件。'}};
    if(!Object.hasOwn(profiles,i.locale))return {held:true,reason:'profile-missing'};
    if(!smallWhole(i.quantity,1000))return {held:true,reason:'quantity-missing-or-invalid'};
    return withPage(async page=>{const p=profiles[corrected?i.locale:'en'];await page.setContent('<article lang="'+i.locale+'"><p>'+p.label+p.colon+i.quantity+p.unit+'</p><data value="'+i.quantity+'"></data></article>');
      return page.evaluate(()=>({lang:document.querySelector('article').lang,text:document.querySelector('p').textContent,quantity:document.querySelector('data').value}));});
  };
const cases=[{"input":{"locale":"zh-HK","quantity":0},"corrected":false,"expected":{"lang":"zh-HK","text":"Total: 0 units.","quantity":"0"}},{"input":{"locale":"zh-HK","quantity":0},"corrected":true,"expected":{"lang":"zh-HK","text":"合共:0 件。","quantity":"0"}},{"input":{"locale":"en","quantity":3},"corrected":true,"expected":{"lang":"en","text":"Total: 3 units.","quantity":"3"}},{"input":{"locale":"fr","quantity":3},"corrected":true,"expected":{"held":true,"reason":"profile-missing"}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Download runnable example ↓

Choose from the boundary evidence

English quantity three renders Total: 3 units. No French profile is supplied, so French output is held instead of falling back silently.

  1. Choose the supplied locale profile
  2. Render labels and value
  3. Inspect actual text and language

Hold a locale without its required profile.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
English profile{"locale":"en","quantity":3}{"lang":"en","text":"Total: 3 units.","quantity":"3"}
no supplied French profile{"locale":"fr","quantity":3}{"held":true,"reason":"profile-missing"}
Download editable CSV ↓

Does lang=zh-HK alone make the base document complete?

Show the worked answer

No. The actual label and punctuation must also use the Chinese profile. Quantity stays zero in both versions.

Related resources