Back to Homepage

Translations Guide

docs/widgets/authoring/translations.md

1.12.33.8 KB
Original Source

All text and numerical content in widgets should be translated and localized. English is the default language, and other languages can be added via Crowdin.

Translations

Homepage uses the next-i18next library to handle translations. This library provides a set of hooks and utilities to help you localize your widgets, and Homepage has extended this library to support additional features.

=== "component.jsx"

```js
import { useTranslation } from "next-i18next";

import Container from "components/services/widget/container";
import Block from "components/services/widget/block";

export default function Component() {
  const { t } = useTranslation();

  return (
    <Container service={service}>
      <Block label="yourwidget.key1" />
      <Block label="yourwidget.key2" />
      <Block label="yourwidget.key3" />
    </Container>
  );
}
```

Set up translation strings

Homepage uses translated and localized strings for all text and numerical content in widgets. English is the default language, and other languages can be added via Crowdin. To add the English translations for your widget, follow these steps:

Open the public/locales/en/common.json file.

Add a new object for your widget to the bottom of the list, like this:

json
"yourwidget": {
  "key1": "Value 1",
  "key2": "Value 2",
  "key3": "Value 3"
}

!!! note

Even if you natively speak another language, you should only add English translations. You can then add translations in your native language via [Crowdin](https://crowdin.com/project/gethomepage), once your widget is merged.

Common Translations

Homepage provides a set of common translations that you can use in your widgets. These translations are used to format numerical content, dates, and other common elements.

Numbers

KeyTranslationDescription
common.bytes1,000 BFormat a number in bytes.
common.bits1,000 bitFormat a number in bits.
common.bbytes1 KiBFormat a number in binary bytes.
common.bbits1 KibitFormat a number in binary bits.
common.byterate1,000 B/sFormat a byte rate.
common.bibyterate1 KiB/sFormat a binary byte rate.
common.bitrate1,000 bit/sFormat a bit rate.
common.bibitrate1 Kibit/sFormat a binary bit rate.
common.percent50%Format a percentage.
common.number1,000Format a number.
common.ms1,000 msFormat a number in milliseconds.
common.date2024-01-01Format a date.
common.relativeDate1 day agoFormat a relative date.
common.duration1 day, 1 hourFormat an duration.

Text

KeyTranslationDescription
resources.cpuCPUCPU usage.
resources.memMEMMemory usage.
resources.totalTotalTotal resource.
resources.freeFreeFree resource.
resources.usedUsedUsed resource.
resources.loadLoadLoad value.
resources.tempTEMPTemperature value.
resources.maxMaxMaximum value.
resources.uptimeUPUptime.