mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-07-23 00:28:04 +00:00
feat: translations support
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
- [17. Cookie consent code](#17-cookie-consent-code)
|
||||
- [18. Disable encoding and show only original file](#18-disable-encoding-and-show-only-original-file)
|
||||
- [19. Rounded corners on videos](#19-rounded-corners)
|
||||
- [20. Translations](#20-translations)
|
||||
|
||||
## 1. Welcome
|
||||
This page is created for MediaCMS administrators that are responsible for setting up the software, maintaining it and making modifications.
|
||||
@ -801,3 +802,41 @@ frontend/src/static/js/components/list-item/Item.scss
|
||||
frontend/src/static/js/components/media-page/MediaPage.scss
|
||||
```
|
||||
you now have to re-run the frontend build in order to see the changes (check docs/dev_exp.md)
|
||||
|
||||
|
||||
## 20. Translations
|
||||
|
||||
### 20.1 Set a default language
|
||||
|
||||
By default MediaCMS is available in a number of languages. To set the default language, edit `settings.py` and set LANGUAGE_CODE to the code of one of the languages.
|
||||
|
||||
### 20.2 Remove existing languages
|
||||
To limit the number of languages that are shown as available, remove them from the LANGUAGES list in `settings.py` or comment them. Only what is there is shown.
|
||||
|
||||
### 20.3 Improve existing translation
|
||||
To make improvements in existing translated content, in a language that is already translated, check the language by the code name in `files/frontend-translations/` and edit the corresponding file.
|
||||
|
||||
### 20.4 Add more content to existing translation
|
||||
Not all text is translated, so at any time you may find strings missing that need to be added to the translation. The idea here is that
|
||||
|
||||
a) you made the text as translatable, in the code
|
||||
b) you add the translated string
|
||||
|
||||
For a), you have to see if the string to be translated lives in the frontend directory (React app) or on the Django templates. There are examples for both.
|
||||
1. the Django templates, which is found in templates/ dir. Have a look on `templates/cms/about.html` to see an example of how it is done
|
||||
2. the frontend code (React), have a look how `translateString` is used in `frontend`
|
||||
|
||||
|
||||
After the string is marked as translatable, add the string to `files/frontend-translations/en.py` first, and then run
|
||||
|
||||
```
|
||||
python manage.py process_translations
|
||||
```
|
||||
|
||||
In order to populate the string in all the languages. NO PR will be accepted if this procedure is not followed. You don't have to translate the string to all supported languages, but the command has to run and populate the existing dictionaries with the new strings for all languages. This ensures that there is no missing string to be translated in any language.
|
||||
|
||||
After this command is run, translate the string to the language you want. If the string to be translated lives in Django templates, you don't have to re-build the frontend. If the change lives in the frontend, you will have to re-build in order to see the changes. The Makefile command `make build-frontend` can help with this.
|
||||
|
||||
|
||||
### 20.5 Add a new language and translate
|
||||
To add a new language: add the language in settings.py, then add the file in `files/frontend-translations/`. Make sure you copy the initial strings by copying `files/frontend-translations/en.py` to it.
|
@ -34,6 +34,14 @@ Check it on http://localhost:8088/
|
||||
### How to develop in Django
|
||||
Django starts at http://localhost and is reloading automatically. Making any change to the python code should refresh Django.
|
||||
|
||||
If Django breaks due to an error (eg SyntaxError, while editing the code), you might have to restart it
|
||||
|
||||
```
|
||||
docker-compose -f docker-compose-dev.yaml restart web
|
||||
```
|
||||
|
||||
|
||||
|
||||
### How to develop in React
|
||||
React is started on http://localhost:8088/ , code is located in frontend/ , so making changes there should have instant effect on the page. Keep in mind that React is loading data from Django, and that it has to be built so that Django can serve it.
|
||||
|
||||
@ -57,4 +65,25 @@ In order to make changes to React code, edit code on frontend/src and check it's
|
||||
3. Build frontend with `docker-compose -f docker-compose-dev.yaml exec frontend npm run dist`
|
||||
4. Copy static files to Django static folder with`cp -r frontend/dist/static/* static/`
|
||||
5. Restart Django - `docker-compose -f docker-compose-dev.yaml restart web` so that it uses the new static files
|
||||
6. Commit the changes
|
||||
6. Commit the changes
|
||||
|
||||
### Helper commands
|
||||
There is ongoing effort to provide helper commands, check the Makefile for what it supports. Eg
|
||||
|
||||
Bash into the web container:
|
||||
|
||||
```
|
||||
user@user:~/mediacms$ make admin-shell
|
||||
root@ca8c1096726b:/home/mediacms.io/mediacms# ./manage.py shell
|
||||
```
|
||||
|
||||
Build the frontend:
|
||||
|
||||
```
|
||||
user@user:~/mediacms$ make build-frontend
|
||||
docker-compose -f docker-compose-dev.yaml exec frontend npm run dist
|
||||
|
||||
> mediacms-frontend@0.9.1 dist /home/mediacms.io/mediacms/frontend
|
||||
> mediacms-scripts rimraf ./dist && mediacms-scripts build --config=./config/mediacms.config.js --env=dist
|
||||
...
|
||||
```
|
Reference in New Issue
Block a user