This project is based on FastAPI Docker Boilerplate.
- Clone the repository
- Create a
.envfile based on.env.example:cp .env.example .env - Configure the environment variables in the
.envfile
python3 app/main.pydocker-compose up -ddocker-compose -f docker-compose.local.yml up -dProject settings are divided into components and environments (development/production). They are located in the app/config/components/ directory.
The main logic for combining settings is in the __init__.py file.
To switch between environments, change the ENVIRONMENT variable in the .env file.
The project uses Tortoise ORM and Aerich for managing migrations.
aerich init-dbThis will create a migrations folder in the db module. All models in __init__.py (db module) will be reflected in the migration.
aerich migrateaerich upgradeThe project supports internationalization using FastAPI-Babel and Pybabel. Translation files are managed using Make commands for easy maintenance.
-
Extract Translatable Strings
make translations-extract
This will scan your project and create/update the message template (POT) file.
-
Initialize a New Language
make translations-init LANG=xx
Replace
xxwith the language code (e.g.,rufor Russian,defor German). -
Compile Translation Messages
make translations-compile
Compiles the translation files for use in the application.
-
Update Existing Translations
make translations-update
Updates existing translation files with new strings found in the code.
-
Complete Translation Workflow
make translations-all LANG=xx
Runs the complete workflow for a new language: extract strings, initialize language, and compile messages.
/app/locales/: Directory containing all translation files/app/locales/messages.pot: Template file containing all translatable strings/app/locales/<lang>/LC_MESSAGES/: Language-specific translation files
The project uses FastAPI-Babel for handling translations. You can use the translation system in your code like this:
from fastapi_babel import _
# In your route or model:
message = _("Your message to translate")