Skip to content

A local-first personal finance app

Add i18n documentation (#431)

Julian Wachholz6772a1c7d13a
diff --git a/README.md b/README.md
index 8aee8013d4..447e0ab170 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Below are some basic standards on how the documentation should be formatted. Eve
When writing your documentation, please use the English language. At this time, the documentation team doesn't have any translators available to translate documents into other languages, but this is something we would like to do in the future.
-Docusaurus 2 provides translation using [i8n](https://docusaurus.io/docs/i18n/introduction). If this is something you would like to pursue, please feel free to open a PR.
+Docusaurus 2 provides translation using [i18n](https://docusaurus.io/docs/i18n/introduction). If this is something you would like to pursue, please feel free to open a PR.
### Documentation Structure
@@ -224,4 +224,4 @@ If you are using GitHub pages for hosting, this command is a convenient way to b
### Writing Good Release Notes
-For general guidelines, see [contributing](https://actualbudget.org/docs/contributing/#writing-good-release-notes) section of the documentation. The Documentation site is not versioned in the same manner as the rest of the project. The Documentation website is more of a living document. Merges into `master` will have the title and PR# as commit message, with the PR description as extended git commit description.
\ No newline at end of file
+For general guidelines, see [contributing](https://actualbudget.org/docs/contributing/#writing-good-release-notes) section of the documentation. The Documentation site is not versioned in the same manner as the rest of the project. The Documentation website is more of a living document. Merges into `master` will have the title and PR# as commit message, with the PR description as extended git commit description.
diff --git a/docs-sidebar.js b/docs-sidebar.js
index cf91dbfe57..ed7cda8dd2 100644
--- a/docs-sidebar.js
+++ b/docs-sidebar.js
@@ -302,6 +302,7 @@ const sidebars = {
'contributing/project-details/advice',
],
},
+ 'contributing/i18n',
'contributing/preview-builds',
'contributing/releasing',
'contributing/windows',
diff --git a/docs/contributing/i18n.md b/docs/contributing/i18n.md
new file mode 100644
index 0000000000..f60a8684dc
--- /dev/null
+++ b/docs/contributing/i18n.md
@@ -0,0 +1,73 @@
+# Internationalization
+
+Are you interested in bringing Actual to a broader audience by translating and localizing the app into new languages? Great! This guide will show you how to get started. Adding translations can be a great first step into contributing to open-source software.
+
+:::warning Community translations
+
+Currently, Actual Budget **is not yet ready** to receive community translations.
+
+:::
+
+## Current status
+
+Actual is currently being prepared for internationalization (i18n). This means that initially everything in the app was English, but we're slowly marking all texts for translation.
+
+## Marking for translation
+
+Developing translated software requires that every text shown to the user passes through a translation function. Actual uses [i18next](https://www.i18next.com/) to achieve this goal.
+
+Strings in Actual are translated by their natural English language version. The project does not use artificial keys to select the appropriate translated text from the message catalog.
+
+:::note Using natural language keys
+
+Consider the text `"Welcome to Actual Budget"`. When marking strings for translation using natural language, this string also becomes the key used to translate it into other languages. This is in contrast to a commonly used alternative of using artificial keys, which would look like `"text_welcome"`. Actual Budget **does not** use these keys.
+
+:::
+
+When preparing your translatable strings, please use complete units to translate. If there is a cohesive paragraph with multiple sentences, mark the entire paragraph as one translatable string. Do not split it into multiple texts.
+
+The translation framework provides two primary methods for translation:
+
+### `t()` function
+
+The `t()` function is the simplest form of translation, it accepts the text to be translated and an optional object with interpolation variables. We're using the `i18next` singleton instance. You can use the hook within React components to get a reference to it.
+
+```javascript
+import { useTranslation } from 'react-i18next';
+
+function MyComponent() {
+ const { t } = useTranslation('myNamespace');
+
+ return <p>{t('Hello World')}</p>;
+}
+```
+
+At runtime, it will select the translation from the currently active locale. You can also add variables to [interpolate](https://www.i18next.com/translation-function/interpolation):
+
+```javascript
+const withPlaceholder = t('Welcome home, {{name}}!', { name: 'Anita' });
+```
+
+For [pluralalization](https://www.i18next.com/translation-function/plurals), please use the plural form for the default text. The placeholder variable **must** be named `count`:
+
+```javascript
+const manyItems = t('You selected {{count}} items', { count: 4 });
+```
+
+i18next will take care of proper pluralization rules in the currently active language and provide multiple different forms if required.
+
+### `<Trans>` component
+
+When translating text with simple HTML tags or other React components, you will need to use the [`<Trans>` component](https://react.i18next.com/latest/trans-component).
+
+```javascript
+import { Trans, useTranslation } from 'react-i18next';
+
+function MyComponent() {
+ return (
+ <Trans>
+ Click <Link href={url}>here</Link> to become a millionaire.
+ </Trans>
+ );
+}
+```