-
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
2,303 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.PHONY: admin-shell build-frontend | ||
|
||
admin-shell: | ||
@container_id=$$(docker-compose ps -q web); \ | ||
if [ -z "$$container_id" ]; then \ | ||
echo "Web container not found"; \ | ||
exit 1; \ | ||
else \ | ||
docker exec -it $$container_id /bin/bash; \ | ||
fi | ||
|
||
build-frontend: | ||
docker-compose -f docker-compose-dev.yaml exec frontend npm run dist | ||
cp -r frontend/dist/static/* static/ | ||
docker-compose -f docker-compose-dev.yaml restart web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
> [email protected] dist /home/mediacms.io/mediacms/frontend | ||
> mediacms-scripts rimraf ./dist && mediacms-scripts build --config=./config/mediacms.config.js --env=dist | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import importlib | ||
import os | ||
|
||
from django.conf import settings | ||
|
||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
files = os.listdir(current_dir) | ||
translation_strings = {} | ||
replacement_strings = {} | ||
|
||
|
||
def check_language_code(language_code): | ||
# helper function | ||
if language_code not in [pair[0] for pair in settings.LANGUAGES]: | ||
return False | ||
if language_code in ['en', 'en-us', 'en-gb']: | ||
return False | ||
return True | ||
|
||
|
||
for translation_file in files: | ||
# the language code is zh-hans but the file is zh_hans.py | ||
|
||
language_code_file = translation_file.split('.')[0] | ||
language_code = language_code_file.replace('_', '-') | ||
if not check_language_code(language_code): | ||
continue | ||
|
||
module_name = f"files.frontend_translations.{language_code_file}" | ||
tr_module = importlib.import_module(module_name) | ||
translation_strings[language_code] = tr_module.translation_strings | ||
replacement_strings[language_code] = tr_module.replacement_strings | ||
|
||
|
||
|
||
def get_translation(language_code): | ||
# get list of translations per language | ||
if not check_language_code(language_code): | ||
return {} | ||
|
||
translation = translation_strings[language_code] | ||
|
||
return translation | ||
|
||
|
||
def get_translation_strings(language_code): | ||
# get list of replacement strings per language | ||
if not check_language_code(language_code): | ||
return {} | ||
|
||
translation = replacement_strings[language_code] | ||
|
||
return translation | ||
|
||
|
||
def translate_string(language_code, string): | ||
# translate a string to the given language | ||
if not check_language_code(language_code): | ||
return string | ||
|
||
return translation_strings[language_code].get(string, string) |
Oops, something went wrong.