Skip to content

Translating the interface ​

PaperPic shows its buttons, hints and messages in English, and screen readers announce what changes, also in English. The labels option replaces any of these texts, so the component speaks the language of your app. No translations ship with the packages.

Replace some texts ​

Pass only the texts you want to change. The others keep their English text:

ts
const pic = new PaperPic(container, {
  src: '/receipt.jpg',
  labels: { apply: 'Save', finish: 'Enhance' },
})

Labels lists every key with its English text and where it appears.

Texts with a value ​

Five labels are functions, because their text includes a value: the zoom, the sensitivity of Clean up, a corner and its position, a selected corner, and the ruler of Adjust. Screen readers announce them. Format the numbers as your language does:

ts
const signed = new Intl.NumberFormat('es', { signDisplay: 'exceptZero' })

const labels: Partial<PaperPicLabels> = {
  zoomLevel: percent => `Zoom ${percent} %`,
  finishLevel: percent => `Sensibilidad ${percent} %`,
  cornerMoved: (corner, x, y) => `${corner}: ${x}, ${y}`,
  cornerSelected: corner => `${corner}: toca donde va`,
  adjustmentLevel: (name, value) => `${name} ${signed.format(value)}`,
}

Follow the language of your app ​

When your app changes language, pass the labels of the new language, and the viewer updates its texts at once. Keep one object of labels for each language, created once, so that each render passes the same object:

ts
function setLanguage(language: string) {
  pic.setOptions({ labels: translations[language] })
}

Here translations stands for your own object of labels for each language.

A starting point ​

This site shows the component in nine languages besides English. Their labels are in paperpic-labels.ts, and you can copy them into your app.

Released under the MIT License.