[QUESTION] FASTAPI I18N Internationalization
See original GitHub issueHi,
I have database translations. I follow this tutorial to implement in fastapi : https://sqlalchemy-utils.readthedocs.io/en/latest/internationalization.html
my endpoint:
@router.get("/", response_model=List[usrRole])
def read_roles(
db: Session = Depends(get_db),
skip: int = 0,
limit: int = 100,
current_user: DBUser = Depends(get_current_active_user),
language: str = Cookie(None),
):
my db_model :
# For testing purposes we define this as simple function which returns
# locale 'fi'. Usually you would define this function as something that
# returns the user's current locale.
def get_locale():
return 'fi' <<< **how to get language cookie here ....**
translation_hybrid = TranslationHybrid(
current_locale=get_locale,
default_locale='en'
)
class usrRole(Base):
__tablename__ = MODULE_NAME + 'role'
__table_args__ = ({ "schema": DATABASE_SCHEMA})
role_id = Column(Integer, primary_key=True, index=True)
name_translations = Column(HSTORE)
# translated column
name = translation_hybrid(name_translations)
All works fine but …only with ‘fi’ value 😃 How to get language cookie value in the db_model ?
Regards Frédérik
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
FastAPI I18n Step by Step | Phrase
Looking for ways to internationalize your FastAPI application using Python libraries? Our step-by-step FastAPI i18n tutorial can help!
Read more >python - fastapi-localization is not translating my API response
I have installed and implemented fastapi-localization just ...
Read more >Easy way to internationalize your apps with PyI18n
PyI18n is a simple and easy to use internationalization library written for ... Dict app: FastAPI = FastAPI() i18n: PyI18n = PyI18n(('pl', ...
Read more >fastapi-localization - PyPI
fastapi_localization - provides a simple language localization from Accept-Language header in your application. Installation $ pip install fastapi- ...
Read more >Help FastAPI - Get Help
First, make sure you understand the problem that the pull request is trying to solve. It might have a longer discussion in an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Be great if you could share with the rest of us. 😃
My solution:
Add the middleware to the fastapi app