demo · v135
OffscreenCanvas locale
Chrome 135 lets you set ctx.lang on a 2D rendering context — including OffscreenCanvas, which had no DOM lang attribute to inherit from. Pick a language and watch the same string render with the right CJK glyph variants.
ctx.lang: ?
main canvas (ctx.lang = above)
OffscreenCanvas (worker, ctx.lang)
the code
const ctx = canvas.getContext("2d");
ctx.lang = "zh-CN"; // NEW in Chrome 135
ctx.font = "24px sans-serif";
ctx.fillText("閨高直", 10, 50);
// Works on OffscreenCanvas in a worker too.
const off = new OffscreenCanvas(320, 120);
const octx = off.getContext("2d");
octx.lang = "ja-JP";
octx.fillText("閨高直", 10, 50);
see also
- Canvas lang — feature index
- ChromeStatus entry
- HTML spec