paperless-ngx/docs/development.md
shamoon f674183593 Squashed commit of the following:
commit 80ff5677eacec9271f342525155c250d9245c54c
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Mon Dec 4 06:40:17 2023 -0800

    Fix: bulk edit object permissions should use permissions object (#4797)

commit 62c417cd5189be0b93e3c0529326609f9d1e4f40
Author: Trenton Holmes <797416+stumpylog@users.noreply.github.com>
Date:   Sun Dec 3 19:09:02 2023 -0800

    Fixes the 0023 migration to include the new help text and verbose name

commit f27f25aa03d032ad7ca6a5f2ba41f83bd00c0bd7
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sun Dec 3 15:35:30 2023 -0800

    Enhancement: support assigning custom fields via consumption templates (#4727)

commit 285a4b5aef0aa4676ee66751a381e77a9e9fcdcf
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sun Dec 3 12:57:43 2023 -0800

    Fix: empty strings for consumption template fields should be treated as None (#4762)

commit 47a2ded30d7e77f2a264b187821af001232ce3d5
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sat Dec 2 16:52:48 2023 -0800

    Fix: use default permissions for objects created via dropdown (#4778)

commit 5b502b1e1a34528b59a0af0a01e73a1f9e7c0656
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Sat Dec 2 16:18:06 2023 -0800

    Use the original image file for the checksum, not the maybe alpha removed version (#4781)

commit aff56077a8ac4d4ec78860d52b824961fada847b
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sat Dec 2 08:26:42 2023 -0800

    Feature: update user profile (#4678)

commit 6e371ac5ac2227a6bdef5e15483f5b478ba78c4d
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Sat Dec 2 08:26:19 2023 -0800

    Enhancement: Allow excluding mail attachments by name (#4691)

    * Adds new filtering to exclude attachments from processing

    * Frontend use include / exclude mail rule filename filters

    ---------

    Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>

commit 1b69b89d2dd4ec021aa6e3bceb175340cdd4e0ff
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sat Dec 2 08:24:17 2023 -0800

    Chore: Remove unneeded .env entry, revert crowdin action rm, reduce frequency

commit 5a20c8e512a7c8a45c26eed5f9e0cf3b1bb04661
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sat Dec 2 07:56:56 2023 -0800

    Fix version checker GitHub api url (#4773)

commit 4ca1503beb1c65eb4f77ac992b4b3ea74fbc6fd4
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Sat Dec 2 07:47:57 2023 -0800

    Fix: Limit global drag-drop to events with files (#4767)

commit 20f27fe32ffe144813d6c69e3326bf230a2da52a
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Fri Dec 1 18:05:43 2023 -0800

    Remove the pngx .env file for crowdin action

commit 1a50d6bb8624a3dd419cadb48e4ee5416fd46ce6
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 2 02:04:16 2023 +0000

    Bump the actions group with 2 updates (#4745)

    Bumps the actions group with 2 updates: [actions/github-script](https://github.com/actions/github-script) and [stumpylog/image-cleaner-action](https://github.com/stumpylog/image-cleaner-action).

    Updates `actions/github-script` from 6 to 7
    - [Release notes](https://github.com/actions/github-script/releases)
    - [Commits](https://github.com/actions/github-script/compare/v6...v7)

    Updates `stumpylog/image-cleaner-action` from 0.3.0 to 0.4.0
    - [Release notes](https://github.com/stumpylog/image-cleaner-action/releases)
    - [Changelog](https://github.com/stumpylog/image-cleaner-action/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/stumpylog/image-cleaner-action/compare/v0.3.0...v0.4.0)

    ---
    updated-dependencies:
    - dependency-name: actions/github-script
      dependency-type: direct:production
      update-type: version-update:semver-major
      dependency-group: actions
    - dependency-name: stumpylog/image-cleaner-action
      dependency-type: direct:production
      update-type: version-update:semver-minor
      dependency-group: actions
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 0b16c2db0372535d18e75267f0a26e4d7f4c812a
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Fri Dec 1 17:54:00 2023 -0800

    Update crowdin action triggers

commit 76ac8883865e123bb48f80336cc0658f7d913249
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Fri Dec 1 17:44:33 2023 -0800

    Chore: Implement crowdin GHA (#4706)

commit 7cfa05d7f2c63d2a1c25eb4e0b54ad3a52726a59
Author: Paperless-ngx Bot [bot] <99855517+paperlessngx-bot@users.noreply.github.com>
Date:   Fri Dec 1 17:44:05 2023 -0800

    New Crowdin updates (#4729)

commit e3496d04858337a193b623fabc8cc49ec0dc08cf
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 2 01:07:13 2023 +0000

    Bump the frontend-eslint-dependencies group in /src-ui with 3 updates (#4756)

    Bumps the frontend-eslint-dependencies group in /src-ui with 3 updates: [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin), [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) and [eslint](https://github.com/eslint/eslint).

    Updates `@typescript-eslint/eslint-plugin` from 6.9.1 to 6.13.1
    - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
    - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
    - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.13.1/packages/eslint-plugin)

    Updates `@typescript-eslint/parser` from 6.9.1 to 6.13.1
    - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
    - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
    - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.13.1/packages/parser)

    Updates `eslint` from 8.52.0 to 8.55.0
    - [Release notes](https://github.com/eslint/eslint/releases)
    - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/eslint/eslint/compare/v8.52.0...v8.55.0)

    ---
    updated-dependencies:
    - dependency-name: "@typescript-eslint/eslint-plugin"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: frontend-eslint-dependencies
    - dependency-name: "@typescript-eslint/parser"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: frontend-eslint-dependencies
    - dependency-name: eslint
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: frontend-eslint-dependencies
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit d2c33c00746ecc4ceba35a1ce5339354fdbf20ea
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 2 00:58:27 2023 +0000

    Bump the frontend-jest-dependencies group in /src-ui with 2 updates (#4744)

    Bumps the frontend-jest-dependencies group in /src-ui with 2 updates: [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) and [jest-preset-angular](https://github.com/thymikee/jest-preset-angular).

    Updates `@types/jest` from 29.5.7 to 29.5.10
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

    Updates `jest-preset-angular` from 13.1.2 to 13.1.4
    - [Release notes](https://github.com/thymikee/jest-preset-angular/releases)
    - [Changelog](https://github.com/thymikee/jest-preset-angular/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/thymikee/jest-preset-angular/compare/v13.1.2...v13.1.4)

    ---
    updated-dependencies:
    - dependency-name: "@types/jest"
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: frontend-jest-dependencies
    - dependency-name: jest-preset-angular
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: frontend-jest-dependencies
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 9c5caecafadc6f28e414117ba7be329243863608
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 2 00:49:46 2023 +0000

    Bump @playwright/test from 1.39.0 to 1.40.1 in /src-ui (#4749)

    Bumps [@playwright/test](https://github.com/microsoft/playwright) from 1.39.0 to 1.40.1.
    - [Release notes](https://github.com/microsoft/playwright/releases)
    - [Commits](https://github.com/microsoft/playwright/compare/v1.39.0...v1.40.1)

    ---
    updated-dependencies:
    - dependency-name: "@playwright/test"
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 64651d5a8424488ad4878bb61098376c550d892e
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 2 00:38:35 2023 +0000

    Bump wait-on from 7.0.1 to 7.2.0 in /src-ui (#4747)

    Bumps [wait-on](https://github.com/jeffbski/wait-on) from 7.0.1 to 7.2.0.
    - [Release notes](https://github.com/jeffbski/wait-on/releases)
    - [Commits](https://github.com/jeffbski/wait-on/compare/v7.0.1...v7.2.0)

    ---
    updated-dependencies:
    - dependency-name: wait-on
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 4493236879bcc70aa3e4b6be769a543d9ada239d
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Dec 1 16:28:50 2023 -0800

    Bump @types/node from 20.8.10 to 20.10.2 in /src-ui (#4748)

    Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.8.10 to 20.10.2.
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

    ---
    updated-dependencies:
    - dependency-name: "@types/node"
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit ce643942ea4f2635a13c22e34a933b254647d560
Author: omahs <73983677+omahs@users.noreply.github.com>
Date:   Fri Dec 1 15:55:03 2023 +0100

    Documentation: Fix typos (#4737)

commit 46d216b02f35abb5fdbed0539984b8d262192e01
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Thu Nov 30 23:14:59 2023 -0800

    Remove project actions in favor of GH workflows

commit 133d43ae3057bceb56cbedaf96742ce62c0d7930
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Thu Nov 30 19:08:03 2023 -0800

    Enhancement: auto-refresh logs & tasks (#4680)

commit 27155cb7e3230a6909ff9b339e41bf423fb08e64
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Thu Nov 30 17:12:14 2023 -0800

    Fixes the image cleaner not running for the registry cache (#4732)

commit 69be86e16c956e2129baef318e76a5f4cadf8b7a
Author: Trenton Holmes <797416+stumpylog@users.noreply.github.com>
Date:   Thu Nov 30 07:11:46 2023 -0800

    Resets version string to 2.0.1-dev

commit 65f6b0881ea2dce37a9c8b8ee079278e4fd81865
Author: Trenton Holmes <797416+stumpylog@users.noreply.github.com>
Date:   Thu Nov 30 07:11:00 2023 -0800

    Bumps version to 2.0.1

commit c2bede40c7094e46f49640790cf2267bd273dadd
Merge: 6575c6940 33c2398de
Author: Trenton Holmes <797416+stumpylog@users.noreply.github.com>
Date:   Thu Nov 30 07:10:29 2023 -0800

    Merge remote-tracking branch 'origin/dev'

commit 33c2398de949dd4ee97b08736e5964efab2fcc01
Author: Paperless-ngx Bot [bot] <99855517+paperlessngx-bot@users.noreply.github.com>
Date:   Thu Nov 30 07:08:10 2023 -0800

    New Crowdin updates (#4695)

commit 64cfc43891fbc7da692c138e73922d45b2e12c8c
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Thu Nov 30 07:00:54 2023 -0800

    Inreases the length to 5, allowing for commas as well as values (#4719)

commit 6575c69409afeb68f70fd602832e15c9d0701bc2
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Wed Nov 29 21:56:05 2023 -0800

    Fix: restore docs search

commit e3f4e0b77572a9a784f748a79aa78c25388fb77c
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Wed Nov 29 12:18:44 2023 -0800

    Adds new setting to control color conversions (#4709)

commit 5be89bfda5228e19351387351b27ece458528317
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Wed Nov 29 11:50:30 2023 -0800

    Changelog v2.0.0 - GHA (#4693)

    Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

commit e1b573adeb3f9b644fb51bd9359b51922df10732
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Wed Nov 29 11:28:27 2023 -0800

    Fix: Add a warning about a low image DPI which may cause OCR to fail (#4708)

commit 0913c7aa9efbd071bd5c423b5d5de5cf12617185
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Wed Nov 29 11:10:55 2023 -0800

    Fix: share links for URLs containing 'api' incorrect in dropdown (#4701)
2023-12-04 17:13:00 -08:00

467 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Development
This section describes the steps you need to take to start development
on Paperless-ngx.
Check out the source from GitHub. The repository is organized in the
following way:
- `main` always represents the latest release and will only see
changes when a new release is made.
- `dev` contains the code that will be in the next release.
- `feature-X` contains bigger changes that will be in some release, but
not necessarily the next one.
When making functional changes to Paperless-ngx, _always_ make your changes
on the `dev` branch.
Apart from that, the folder structure is as follows:
- `docs/` - Documentation.
- `src-ui/` - Code of the front end.
- `src/` - Code of the back end.
- `scripts/` - Various scripts that help with different parts of
development.
- `docker/` - Files required to build the docker image.
## Contributing to Paperless-ngx
Maybe you've been using Paperless-ngx for a while and want to add a feature
or two, or maybe you've come across a bug that you have some ideas how
to solve. The beauty of open source software is that you can see what's
wrong and help to get it fixed for everyone!
Before contributing please review our [code of
conduct](https://github.com/paperless-ngx/paperless-ngx/blob/main/CODE_OF_CONDUCT.md)
and other important information in the [contributing
guidelines](https://github.com/paperless-ngx/paperless-ngx/blob/main/CONTRIBUTING.md).
## Code formatting with pre-commit hooks
To ensure a consistent style and formatting across the project source,
the project utilizes Git [`pre-commit`](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
hooks to perform some formatting and linting before a commit is allowed.
That way, everyone uses the same style and some common issues can be caught
early on.
Once installed, hooks will run when you commit. If the formatting isn't
quite right or a linter catches something, the commit will be rejected.
You'll need to look at the output and fix the issue. Some hooks, such
as the Python formatting tool `black`, will format failing
files, so all you need to do is `git add` those files again
and retry your commit.
## General setup
After you forked and cloned the code from GitHub you need to perform a
first-time setup.
!!! note
Every command is executed directly from the root folder of the project unless specified otherwise.
1. Install prerequisites + pipenv as mentioned in
[Bare metal route](setup.md#bare_metal).
2. Copy `paperless.conf.example` to `paperless.conf` and enable debug
mode within the file via `PAPERLESS_DEBUG=true`.
3. Create `consume` and `media` directories:
```bash
$ mkdir -p consume media
```
4. Install the Python dependencies:
```bash
$ pipenv install --dev
```
!!! note
Using a virtual environment is highly recommended. You can spawn one via `pipenv shell`.
Make sure you're using Python 3.10.x or lower. Otherwise you might
get issues with building dependencies. You can use
[pyenv](https://github.com/pyenv/pyenv) to install a specific
Python version.
5. Install pre-commit hooks:
```bash
$ pre-commit install
```
6. Apply migrations and create a superuser for your development instance:
```bash
# src/
$ python3 manage.py migrate
$ python3 manage.py createsuperuser
```
7. You can now either ...
- install redis or
- use the included `scripts/start_services.sh` to use docker to fire
up a redis instance (and some other services such as tika,
gotenberg and a database server) or
- spin up a bare redis container
```
$ docker run -d -p 6379:6379 --restart unless-stopped redis:latest
```
8. Continue with either back-end or front-end development or both :-).
## Back end development
The back end is a [Django](https://www.djangoproject.com/) application.
[PyCharm](https://www.jetbrains.com/de-de/pycharm/) as well as [Visual Studio Code](https://code.visualstudio.com)
work well for development, but you can use whatever you want.
Configure the IDE to use the `src/`-folder as the base source folder.
Configure the following launch configurations in your IDE:
- `python3 manage.py runserver`
- `python3 manage.py document_consumer`
- `celery --app paperless worker -l DEBUG` (or any other log level)
To start them all:
```bash
# src/
$ python3 manage.py runserver & \
python3 manage.py document_consumer & \
celery --app paperless worker -l DEBUG
```
You might need the front end to test your back end code.
This assumes that you have AngularJS installed on your system.
Go to the [Front end development](#front-end-development) section for further details.
To build the front end once use this command:
```bash
# src-ui/
$ npm install
$ ng build --configuration production
```
### Testing
- Run `pytest` in the `src/` directory to execute all tests. This also
generates a HTML coverage report. When runnings test, `paperless.conf`
is loaded as well. However, the tests rely on the default
configuration. This is not ideal. But for now, make sure no settings
except for DEBUG are overridden when testing.
!!! note
The line length rule E501 is generally useful for getting multiple
source files next to each other on the screen. However, in some
cases, its just not possible to make some lines fit, especially
complicated IF cases. Append `# noqa: E501` to disable this check
for certain lines.
## Front end development
The front end is built using AngularJS. In order to get started, you need Node.js (version 14.15+) and
`npm`.
!!! note
The following commands are all performed in the `src-ui`-directory. You will need a running back end (including an active session) to connect to the back end API. To spin it up refer to the commands under the section [above](#back-end-development).
1. Install the Angular CLI. You might need sudo privileges to perform this command:
```bash
$ npm install -g @angular/cli
```
2. Make sure that it's on your path.
3. Install all necessary modules:
```bash
$ npm install
```
4. You can launch a development server by running:
```bash
$ ng serve
```
This will automatically update whenever you save. However, in-place
compilation might fail on syntax errors, in which case you need to
restart it.
By default, the development server is available on `http://localhost:4200/` and is configured to access the API at
`http://localhost:8000/api/`, which is the default of the backend. If you enabled `DEBUG` on the back end, several security overrides for allowed hosts, CORS and X-Frame-Options are in place so that the front end behaves exactly as in production.
### Testing and code style
The front end code (.ts, .html, .scss) use `prettier` for code
formatting via the Git `pre-commit` hooks which run automatically on
commit. See [above](#code-formatting-with-pre-commit-hooks) for installation instructions. You can also run this via the CLI with a
command such as
```bash
$ git ls-files -- '*.ts' | xargs pre-commit run prettier --files
```
Front end testing uses Jest and Playwright. Unit tests and e2e tests,
respectively, can be run non-interactively with:
```bash
$ ng test
$ npx playwright test
```
Playwright also includes a UI which can be run with:
```bash
$ npx playwright test --ui
```
### Building the frontend
In order to build the front end and serve it as part of Django, execute:
```bash
$ ng build --configuration production
```
This will build the front end and put it in a location from which the
Django server will serve it as static content. This way, you can verify
that authentication is working.
## Localization
Paperless-ngx is available in many different languages. Since Paperless-ngx
consists both of a Django application and an AngularJS front end, both
these parts have to be translated separately.
### Front end localization
- The AngularJS front end does localization according to the [Angular
documentation](https://angular.io/guide/i18n).
- The source language of the project is "en_US".
- The source strings end up in the file `src-ui/messages.xlf`.
- The translated strings need to be placed in the
`src-ui/src/locale/` folder.
- In order to extract added or changed strings from the source files,
call `ng extract-i18n`.
Adding new languages requires adding the translated files in the
`src-ui/src/locale/` folder and adjusting a couple files.
1. Adjust `src-ui/angular.json`:
```json
"i18n": {
"sourceLocale": "en-US",
"locales": {
"de": "src/locale/messages.de.xlf",
"nl-NL": "src/locale/messages.nl_NL.xlf",
"fr": "src/locale/messages.fr.xlf",
"en-GB": "src/locale/messages.en_GB.xlf",
"pt-BR": "src/locale/messages.pt_BR.xlf",
"language-code": "language-file"
}
}
```
2. Add the language to the available options in
`src-ui/src/app/services/settings.service.ts`:
```typescript
getLanguageOptions(): LanguageOption[] {
return [
{code: "en-us", name: $localize`English (US)`, englishName: "English (US)", dateInputFormat: "mm/dd/yyyy"},
{code: "en-gb", name: $localize`English (GB)`, englishName: "English (GB)", dateInputFormat: "dd/mm/yyyy"},
{code: "de", name: $localize`German`, englishName: "German", dateInputFormat: "dd.mm.yyyy"},
{code: "nl", name: $localize`Dutch`, englishName: "Dutch", dateInputFormat: "dd-mm-yyyy"},
{code: "fr", name: $localize`French`, englishName: "French", dateInputFormat: "dd/mm/yyyy"},
{code: "pt-br", name: $localize`Portuguese (Brazil)`, englishName: "Portuguese (Brazil)", dateInputFormat: "dd/mm/yyyy"}
// Add your new language here
]
}
```
`dateInputFormat` is a special string that defines the behavior of
the date input fields and absolutely needs to contain "dd", "mm"
and "yyyy".
3. Import and register the Angular data for this locale in
`src-ui/src/app/app.module.ts`:
```typescript
import localeDe from '@angular/common/locales/de'
registerLocaleData(localeDe)
```
### Back end localization
A majority of the strings that appear in the back end appear only when
the admin is used. However, some of these are still shown on the front
end (such as error messages).
- The django application does localization according to the [Django
documentation](https://docs.djangoproject.com/en/3.1/topics/i18n/translation/).
- The source language of the project is "en_US".
- Localization files end up in the folder `src/locale/`.
- In order to extract strings from the application, call
`python3 manage.py makemessages -l en_US`. This is important after
making changes to translatable strings.
- The message files need to be compiled for them to show up in the
application. Call `python3 manage.py compilemessages` to do this.
The generated files don't get committed into git, since these are
derived artifacts. The build pipeline takes care of executing this
command.
Adding new languages requires adding the translated files in the
`src/locale/`-folder and adjusting the file
`src/paperless/settings.py` to include the new language:
```python
LANGUAGES = [
("en-us", _("English (US)")),
("en-gb", _("English (GB)")),
("de", _("German")),
("nl-nl", _("Dutch")),
("fr", _("French")),
("pt-br", _("Portuguese (Brazil)")),
# Add language here.
]
```
## Building the documentation
The documentation is built using material-mkdocs, see their [documentation](https://squidfunk.github.io/mkdocs-material/reference/).
If you want to build the documentation locally, this is how you do it:
1. Have an active pipenv shell (`pipenv shell`) and install Python dependencies:
```bash
$ pipenv install --dev
```
2. Build the documentation
```bash
$ mkdocs build --config-file mkdocs.yml
```
_alternatively..._
3. Serve the documentation. This will spin up a
copy of the documentation at http://127.0.0.1:8000
that will automatically refresh every time you change
something.
```bash
$ mkdocs serve
```
## Building the Docker image
The docker image is primarily built by the GitHub actions workflow, but
it can be faster when developing to build and tag an image locally.
Building the image works as with any image:
```
docker build --file Dockerfile --tag paperless:local --progress simple .
```
## Extending Paperless-ngx
Paperless-ngx does not have any fancy plugin systems and will probably never
have. However, some parts of the application have been designed to allow
easy integration of additional features without any modification to the
base code.
### Making custom parsers
Paperless-ngx uses parsers to add documents. A parser is
responsible for:
- Retrieving the content from the original
- Creating a thumbnail
- _optional:_ Retrieving a created date from the original
- _optional:_ Creating an archived document from the original
Custom parsers can be added to Paperless-ngx to support more file types. In
order to do that, you need to write the parser itself and announce its
existence to Paperless-ngx.
The parser itself must extend `documents.parsers.DocumentParser` and
must implement the methods `parse` and `get_thumbnail`. You can provide
your own implementation to `get_date` if you don't want to rely on
Paperless-ngx' default date guessing mechanisms.
```python
class MyCustomParser(DocumentParser):
def parse(self, document_path, mime_type):
# This method does not return anything. Rather, you should assign
# whatever you got from the document to the following fields:
# The content of the document.
self.text = "content"
# Optional: path to a PDF document that you created from the original.
self.archive_path = os.path.join(self.tempdir, "archived.pdf")
# Optional: "created" date of the document.
self.date = get_created_from_metadata(document_path)
def get_thumbnail(self, document_path, mime_type):
# This should return the path to a thumbnail you created for this
# document.
return os.path.join(self.tempdir, "thumb.webp")
```
If you encounter any issues during parsing, raise a
`documents.parsers.ParseError`.
The `self.tempdir` directory is a temporary directory that is guaranteed
to be empty and removed after consumption finished. You can use that
directory to store any intermediate files and also use it to store the
thumbnail / archived document.
After that, you need to announce your parser to Paperless-ngx. You need to
connect a handler to the `document_consumer_declaration` signal. Have a
look in the file `src/paperless_tesseract/apps.py` on how that's done.
The handler is a method that returns information about your parser:
```python
def myparser_consumer_declaration(sender, **kwargs):
return {
"parser": MyCustomParser,
"weight": 0,
"mime_types": {
"application/pdf": ".pdf",
"image/jpeg": ".jpg",
}
}
```
- `parser` is a reference to a class that extends `DocumentParser`.
- `weight` is used whenever two or more parsers are able to parse a
file: The parser with the higher weight wins. This can be used to
override the parsers provided by Paperless-ngx.
- `mime_types` is a dictionary. The keys are the mime types your
parser supports and the value is the default file extension that
Paperless-ngx should use when storing files and serving them for
download. We could guess that from the file extensions, but some
mime types have many extensions associated with them and the Python
methods responsible for guessing the extension do not always return
the same value.