Review this generated invoice renderer.
Render an invoice with an already resolved locale, explicit order currency and time zone, a localized item-count message, safe customer text, and consistent document language and direction.
JavaScript
function renderInvoice(order, requestedLocale) {
const locale = requestedLocale || navigator.language;
const currency = locale.endsWith("-US") ? "USD" : "EUR";
const amount = order.total.toLocaleString(locale);
const placedAt = new Intl.DateTimeFormat(locale, {
dateStyle: "medium",
timeZone: order.timeZone,
}).format(new Date(order.placedAt));
const itemLabel =
order.items.length === 1
? `${order.items.length} item`
: `${order.items.length} items`;
const customer = order.customerName;
const html = `
<h2>${customer}</h2>
<p>${itemLabel}</p>
<p>${amount} ${currency}</p>
<time>${placedAt}</time>
`;
document.querySelector("#invoice").innerHTML = html;
document.documentElement.dir = locale.startsWith("ar") ? "rtl" : "ltr";
return html;
}
generated code is illustrative, not from any one model