-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change locale for folder structure for example #897
Comments
That is interesting use case. IIUC you want |
Hi @AndreyNikiforov
But as I mentioned, I am not that of an python expert. Edit: Or maybe. I think you can set environment variable LC_ALL to de_DE.UTF-8, but I think python still needs the code I posted originally. |
I had this in the past, but it was a mess and I am pretty sure that I did not understand everything properly. Furthermore, it does not work with the new version anymore. Not sure why though: FROM python:3.12-alpine
WORKDIR /app
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
RUN set -xe \
&& apk update \
&& apk add git curl binutils gcc libc-dev libffi-dev zlib-dev openssl-dev python3-dev cargo rust tzdata
RUN git clone https://github.com/icloud-photos-downloader/icloud_photos_downloader.git . && \
git checkout tags/v1.17.1 -b main && \
echo "import locale" >> /app/src/icloudpd/__init__.py && \
echo "locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')" >> /app/src/icloudpd/__init__.py
ENV MUSL_LOCPATH="/usr/share/i18n/locales/musl"
RUN apk add --no-cache musl-locales musl-locales-lang \
&& cd "$MUSL_LOCPATH" \
&& for i in de_DE.UTF-8; do cp -a "$i" "${i%%.UTF-8}"; done
RUN pip3 install -e .[dev]
RUN pyinstaller -y --collect-all keyrings.alt --hidden-import pkgutil --collect-all tzdata --onefile src/starters/icloudpd_ex.py
RUN adduser -D worker -u 1024
USER worker
RUN mkdir -p /home/worker/app
USER 0
RUN cp /app/dist/icloudpd_ex /home/worker/app && \
rm -R /app/dist/icloudpd_ex
USER worker
WORKDIR /home/worker
ENV PATH="/home/worker/.local/bin:${PATH}"
RUN python -m pip install --upgrade pip && \
pip install --user keyrings.alt keyring
ENV TZ Europe/Berlin \
LANG de_DE.UTF-8 \
LANGUAGE de_DE.UTF-8 \
LC_ALL de_DE.UTF-8
ENV PATH="/home/worker/app:${PATH}"
RUN cd /home/worker/app && ls -la
ENTRYPOINT ["/home/worker/app/icloudpd_ex"] It was a quick fix when the auth was not working and I just copy pasted a lot of stuff. |
What I have found: locale -a To Install all: sudo apt-get update
sudo apt-get install locales locales-all python test.py code: import datetime
from locale import LC_ALL, setlocale
setlocale(LC_ALL, '')
print(f"{datetime.datetime.now():%B}") to test different locales LANG=de_DE.UTF-8 python test.py @holomekc check that works as expected and I'll update |
FROM python:bookworm
RUN apt-get update && apt-get install locales locales-all -y
RUN locale
RUN echo 'import datetime\nfrom locale import LC_ALL, setlocale\n\nsetlocale(LC_ALL, "")\nprint(f"{datetime.datetime.now():%B}")' > test.py
RUN LANG=de_DE.UTF-8 python test.py
Yes this works. "Juli" is printed. I did not log the locale -a, because it prints a lot of different languages, but locale shows that currently locale C is configured, but due to the python script and the env it works fine. Would be great if you can include this. |
v1.22.0 has |
Thank you so much for the hard work! |
I want to be able to change the locale for the python process. The reason is to define folder patterns like this:
--folder-structure {:%Y/%m\ %B}
But at the moment this will create something like this:
.../2024/07 July
But I want the german translation
.../2024/07 Juli
I am a python noob so not 100% sure how and where. Otherwise, I could create a PR. I think though you need to add only this:
https://docs.python.org/3/library/locale.html#locale.setlocale
Although, I am not sure if it needs to be
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
The text was updated successfully, but these errors were encountered: