10 months ago
Hi everyone,
I’m trying to deploy a FastAPI application on Railway, but I’m encountering issues with setting the Italian locale (it_IT.UTF-8). My goal is to ensure that date formats are displayed correctly in Italian.
Here’s what I’ve tried so far in my Dockerfile:
FROM python:3.9-slim
Install locales
RUN apt-get update && apt-get install -y locales && \
echo "itIT.UTF-8 UTF-8" > /etc/locale.gen && \ locale-gen itIT.UTF-8
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app
EXPOSE 8000
ENV LANG=itIT.UTF-8 ENV LANGUAGE=itIT:it
ENV LCALL=itIT.UTF-8
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
and in my main.py:
from fastapi import FastAPI
from datetime import datetime
import locale
app = FastAPI()
locale.setlocale(locale.LCTIME, 'itIT.UTF-8')
@app.get("/")
def read_root():
return {"message": "Hello World"}
@app.get("/convert-date/{datestr}") def convertdate(datestr: str): try: dateobj = datetime.strptime(datestr, "%d-%m-%Y") formatteddate = dateobj.strftime("Oggi è il %d %B %Y") return {"message": formatteddate}
except ValueError:
return {"error": "Formato data non valido. Usa il formato dd-mm-yyyy."}
Despite these settings, the deployment fails to configure the locale correctly, and I’m unable to achieve the desired date formatting in Italian. The application works locally on my development machine, but I can’t seem to get it running properly on Railway.
Has anyone successfully configured a non-default locale in Docker for a Railway deployment? Any help or suggestions would be greatly appreciated.
Thank you!
ⓘ Deployment information is only viewable by project members and Railway employees.
4 Replies
10 months ago
Hey, I'm not seeing any errors on your deployments, where you able to solve this?
10 months ago
I reverted the project to a simple "hello world" app. When I try to set the Italian locale (it_IT.UTF-8) it fails.
10 months ago
Have you tried looking for solutions on sites like stack overflow? this question wouldn't be specific in any way to the Railway platform.
10 months ago
Have you tried looking for solutions on sites like stack overflow? this question wouldn't be specific in any way to the Railway platform.
I don't even know how to formulate my question. I'm new to this. I've just watched a few videos and made a few python scripts that I would like to have as an api for my project. I've created an "hello world" fastapi app, no problem. I tried to convert a date from dd-mm-yyyy in another format using Italian locale and my deployment didn't work. The app obviously works fine on my local machine.