-
Notifications
You must be signed in to change notification settings - Fork 530
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
How I use locales in Alpine #144
Comments
Unfortunately, the musl libc locale system doesn't appear to be very complete at the moment. There is a little bit of information on it at http://www.openwall.com/lists/musl/2014/08/01/1. But there are no tools in Alpine to generate locales or set up the Sorry :( Referencing #102 as well. |
Well, for this app I will use another distro :( |
Is there a reason that this was closed? It seems to me there is still no way to generate locales? |
I wrote some simple tool with many bugs. It contains locale executable and template for generate MUSL locale files; |
So there is now no easy way to install locale (cs_CZ.utf8) in container? I would need it for my PHP application to print translated dates. |
Install my tool, make a MO file for cs_CZ.utf8 (and make a PR). And use cs_CZ.utf8 as LANG and LC_ALL. |
I encountered the same issue too when using In your FROM alpine:3.6
# ---not shown here---
# Install language pack
RUN apk --no-cache add ca-certificates wget && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-bin-2.25-r0.apk && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-i18n-2.25-r0.apk && \
apk add glibc-bin-2.25-r0.apk glibc-i18n-2.25-r0.apk glibc-2.25-r0.apk
# Iterate through all locale and install it
# Note that locale -a is not available in alpine linux, use `/usr/glibc-compat/bin/locale -a` instead
COPY ./locale.md /locale.md
RUN cat locale.md | xargs -i /usr/glibc-compat/bin/localedef -i {} -f UTF-8 {}.UTF-8
# Set the lang, you can also specify it as as environment variable through docker-compose.yml
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
# --- not show here--- And this is how the
The |
I'm having some issues with localisation on alpine and i can see that i'm not the only one. @alextanhongpin I've tried what you suggested. I can now do C But when trying to change the locale (php command LANG= (here i tried changing it to following; da_DK.utf8, da_DK, da_DK.utf-8, da_DK.UTF-8, da_DK.UTF8 with no luck) Can anybody help? Is it even possible to make it work? |
You try to using glibc locales in musl app, it is strange. Do you tried my workaround? |
@rilian-la-te Yes i tried. Don't have cmake installed on my server. Tried on my mac as a proof of concept which resulted in some missing libraries which lead to a dead end. Might give it another try |
Sorry, I do not know autotools. You need to have argp and libintl to build it in Alpine. I can switch to meson, if python is more acceptable. |
Hi @rilian-la-te. I'm back at this problem. I successfully installed your tool but how do i generate the locale?
How do i make a MO file for e.g. da_DK.utf8 and what is PR? Can you give a few hints :D? |
PR is pull request. For making a MO file you need a PO file and gettext. PO file is a text file with MUSL localization. And you can use my musl-locales to get a locale program and auto install of PO (it will automatically makes it MO and install in right place and sets requiered environment variable) |
lol 🤣. Okay makes sense. I ran your musl-locales and got this output:
This means that the following languages were installed: ch_DE.UTF-8, de_CH.UTF-8,en_US.UTF-8, ru_RU.UTF-8. Right? When i try to setlocale to one of these locales, it does not work. If i do /usr/local/bin/locale -a (to list all enabled locales) it only outputs: I have tried setting the Any ideas to what i'm doing wrong? |
show me MUSL_LOCPATH |
|
It should be /usr/local/share/i18n/locales/musl |
set it so and try again |
Tried setting it to
Might just be an impossible task at this moment :( |
Based on the musl-locales tool by @rilian-la-te, I created a simple example image showing how to use musl locales with docker-alpine. It creates a single docker layer weighting around 150 kb, while containing a few example locales. They mostly aren't full-blown localizations, but at least allow you to use localized time and date functions. You can find it here: https://github.com/Auswaschbar/alpine-localized-docker |
This is awesome, thanks! I can see that C.UTF-8
en_US.UTF-8
ch_DE.UTF-8
de_DE.UTF-8
ru_RU.UTF-8
de_CH.UTF-8
en_GB.UTF-8
fr_FR.UTF-8 What would it take to add more languages? Do we just need to push new .PO files to the https://gitlab.com/rilian-la-te/musl-locales repo? |
Yes, just push it to me) And if you see untranslated strings, you just need to modify .pot file (it is handmade, not generated). |
Here is how I managed to install locales on alpine 3.9 (probably works on earlier versions too) |
Hi I used this gist ton install it on php:7.2.19-fpm-alpine3.9 image. Locales seem to be installed if I use usr/glibc-compat/bin/locale -a but they can't be used within php, strftime still returns english words even with setting setlocale() with another locale. |
@curunoir You're right, locales are installed, but php doesn't use them either. I'm trying to investigate why, will post back if I find anything. I also tested: EDIT: The gist I posted above does not seem to work. So I used rilian-la-te's solution above (has only following locales tho: Basically the steps are:
then using
To check for presence of the locales. And to be sure it works, you can type: Edit: Replaced github link with gitlab instead which is more up to date. |
@Herz3h I've been putting together an APKBUILD file for rilian-la-te's solution. Although the locales appear to work with the date command in a terminal, have you been able to figure out why they do not work in PHP with setlocale?
Output:
|
From #144 (comment)
While this is not wrong, I suggest to clone project from GitLab instead of Github, because it seems more updated there. For example, Gitlab repository has es_ES support. So use:
Edit: Linked comment was updated and now points to GitLab, so don't get confused if you see there the GitLab URL :) |
You're also welcome to use this APKBUILD file to build packages locally. I hope to eventually have it included in Alpine's package repositories.
|
Hi @Herz3h, do you have any update about your investigation? |
@edoardomistretta the steps I posted above (with musl) are the ones I currently use and it's working just fine. |
For anyone else stumbling upon this, musl-libc doesn't support LC_MONETARY yet. It is on their roadmap with no target date. |
Works with #144 (comment). |
Source: https://stackoverflow.com/a/63602822/5155484 apk --no-cache add \
musl-locales \
musl-locales-lang |
I suggest this one for PHP
It permits to run |
|
https://grrr.tech/posts/2020/add-locales-to-alpine-linux-docker-image/ |
Installing the
Last command gives me a list of 800+ locales. |
Thanks @FaimMedia this works for me. |
None of the solutions I found worked for me. |
musl - current statehttps://wiki.musl-libc.org/open-issues |
We are migrating all docker images to Alpine base, but a software need set locales in the system but locales not found and I don't know how install locales command with this images.
locale -a
orlocale-gen
The text was updated successfully, but these errors were encountered: