gliderlabs / docker-alpine

Alpine Linux Docker image. Win at minimalism!
http://gliderlabs.viewdocs.io/docker-alpine
BSD 2-Clause "Simplified" License
5.71k stars 531 forks source link

How I use locales in Alpine #144

Closed yograterol closed 8 years ago

yograterol commented 8 years ago

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 or locale-gen

andyshinn commented 8 years ago

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 MUSL_LOCPATH variable. Some reference from Void Linux (also running musl libc) about no locale support at the moment at https://forum.voidlinux.eu/t/x86-64-musl-void-installer-cannot-set-locale/57.

Sorry :(

Referencing #102 as well.

yograterol commented 8 years ago

Well, for this app I will use another distro :(

ulope commented 8 years ago

Is there a reason that this was closed? It seems to me there is still no way to generate locales?

rilian-la-te commented 7 years ago

I wrote some simple tool with many bugs. It contains locale executable and template for generate MUSL locale files; https://github.com/rilian-la-te/musl-locales

aiphee commented 7 years ago

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.

rilian-la-te commented 7 years ago

Install my tool, make a MO file for cs_CZ.utf8 (and make a PR). Name it cs_CZ.utf8 and move to locale dir (configured at CMake).

And use cs_CZ.utf8 as LANG and LC_ALL.

alextanhongpin commented 7 years ago

I encountered the same issue too when using alpine:3.6. The following works for me.

In your Dockerfile:

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 locale.md looks like:

aa_DJ
aa_ER
aa_ET
af_ZA
am_ET
an_ES
ar_AE
ar_BH
ar_DZ
ar_EG
ar_IN
ar_IQ
ar_JO
ar_KW
ar_LB
ar_LY
ar_MA
ar_OM
ar_QA
ar_SA
ar_SD
ar_SY
ar_TN
ar_YE
as_IN
ast_ES
ayc_PE
az_AZ
be_BY
bem_ZM
ber_DZ
ber_MA
bg_BG
bho_IN
bn_BD
bn_IN
bo_CN
bo_IN
br_FR
brx_IN
bs_BA
byn_ER
ca_AD
ca_ES
ca_FR
ca_IT
crh_UA
csb_PL
cs_CZ
cv_RU
cy_GB
da_DK
de_AT
de_BE
de_CH
de_DE
de_LU
doi_IN
dv_MV
dz_BT
el_CY
el_GR
en_AG
en_AU
en_BW
en_CA
en_DK
en_GB
en_HK
en_IE
en_IN
en_NG
en_NZ
en_PH
en_SG
en_US
en_ZA
en_ZM
en_ZW
es_AR
es_BO
es_CL
es_CO
es_CR
es_CU
es_DO
es_EC
es_ES
es_GT
es_HN
es_MX
es_NI
es_PA
es_PE
es_PR
es_PY
es_SV
es_US
es_UY
es_VE
et_EE
eu_ES
fa_IR
ff_SN
fi_FI
fil_PH
fo_FO
fr_BE
fr_CA
fr_CH
fr_FR
fr_LU
fur_IT
fy_DE
fy_NL
ga_IE
gd_GB
gez_ER
gez_ET
gl_ES
gu_IN
gv_GB
ha_NG
he_IL
hi_IN
hne_IN
hr_HR
hsb_DE
ht_HT
hu_HU
hy_AM
ia_FR
id_ID
ig_NG
ik_CA
is_IS
it_CH
it_IT
iu_CA
iw_IL
ja_JP
ka_GE
kk_KZ
kl_GL
km_KH
kn_IN
kok_IN
ko_KR
ks_IN
ku_TR
kw_GB
ky_KG
lb_LU
lg_UG
li_BE
lij_IT
li_NL
lo_LA
lt_LT
lv_LV
mag_IN
mai_IN
mg_MG
mhr_RU
mi_NZ
mk_MK
ml_IN
mni_IN
mn_MN
mr_IN
ms_MY
mt_MT
my_MM
nb_NO
nds_DE
nds_NL
ne_NP
nhn_MX
niu_NU
niu_NZ
nl_AW
nl_BE
nl_NL
nn_NO
no_NO
nr_ZA
nso_ZA
oc_FR
om_ET
om_KE
or_IN
os_RU
pa_IN
pap_AN
pa_PK
pl_PL
ps_AF
pt_BR
pt_PT
ro_RO
ru_RU
ru_UA
rw_RW
sa_IN
sat_IN
sc_IT
sd_IN
se_NO
shs_CA
sid_ET
si_LK
sk_SK
sl_SI
so_DJ
so_ET
so_KE
so_SO
sq_AL
sq_MK
sr_ME
sr_RS
ss_ZA
st_ZA
sv_FI
sv_SE
sw_KE
sw_TZ
szl_PL
ta_IN
ta_LK
te_IN
tg_TJ
th_TH
ti_ER
ti_ET
tig_ER
tk_TM
tl_PH
tn_ZA
tr_CY
tr_TR
ts_ZA
tt_RU
ug_CN
uk_UA
unm_US
ur_IN
ur_PK
uz_UZ
ve_ZA
vi_VN
wa_BE
wae_CH
wal_ET
wo_SN
xh_ZA
yi_US
yo_NG
yue_HK
zh_CN
zh_HK
zh_SG
zh_TW
zu_ZA

The locale.md contains the list of locale I want to install in the alpine image. If you tried setting the LANG=zh_HK.UTF-8 and it doesn't work, it's because the locale is missing from the image.

nicolasbuch commented 6 years ago

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 locale -a which outputs:

C C.utf8 da_DK.utf8 de_DE.utf8 en_US.utf8 POSIX

But when trying to change the locale (php command setlocale) nothing changes. I have even tried modifying the ENV variable LC_ALL so that locale outputs:

LANG= LC_CTYPE="da_DK.utf8" LC_NUMERIC="da_DK.utf8" LC_TIME="da_DK.utf8" LC_COLLATE="da_DK.utf8" LC_MONETARY="da_DK.utf8" LC_MESSAGES="da_DK.utf8" LC_PAPER="da_DK.utf8" LC_NAME="da_DK.utf8" LC_ADDRESS="da_DK.utf8" LC_TELEPHONE="da_DK.utf8" LC_MEASUREMENT="da_DK.utf8" LC_IDENTIFICATION="da_DK.utf8" LC_ALL=da_DK.utf8

(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?

rilian-la-te commented 6 years ago

You try to using glibc locales in musl app, it is strange. Do you tried my workaround?

nicolasbuch commented 6 years ago

@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

rilian-la-te commented 6 years ago

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.

nicolasbuch commented 6 years ago

Hi @rilian-la-te. I'm back at this problem. I successfully installed your tool but how do i generate the locale?

Install my tool, make a MO file for cs_CZ.utf8 (and make a PR). Name it cs_CZ.utf8 and move to locale dir (configured at CMake). And use cs_CZ.utf8 as LANG and LC_ALL.

How do i make a MO file for e.g. da_DK.utf8 and what is PR? Can you give a few hints :D?

rilian-la-te commented 6 years ago

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)

nicolasbuch commented 6 years ago

PR is pull request.

lol 🤣. Okay makes sense. I ran your musl-locales and got this output:

Install the project... -- Install configuration: "" -- Installing: /usr/local/etc/profile.d/00locale.sh -- Installing: /usr/local/bin/locale -- Installing: /usr/local/share/locale/ch_DE/LC_MESSAGES/musl-locales.mo -- Installing: /usr/local/share/locale/de_CH/LC_MESSAGES/musl-locales.mo -- Installing: /usr/local/share/locale/en_US/LC_MESSAGES/musl-locales.mo -- Installing: /usr/local/share/locale/ru_RU/LC_MESSAGES/musl-locales.mo -- Installing: /usr/local/share/i18n/locales/musl/ch_DE.UTF-8 -- Installing: /usr/local/share/i18n/locales/musl/de_CH.UTF-8 -- Installing: /usr/local/share/i18n/locales/musl/en_US.UTF-8 -- Installing: /usr/local/share/i18n/locales/musl/ru_RU.UTF-8

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: C C.UTF-8

I have tried setting the MUSL_LOCPATH env variable as the musl documentation states http://www.openwall.com/lists/musl/2014/08/01/1 with no luck...

Any ideas to what i'm doing wrong?

rilian-la-te commented 6 years ago

show me MUSL_LOCPATH

nicolasbuch commented 6 years ago

show me MUSL_LOCPATH

usr/local/share/locale/

rilian-la-te commented 6 years ago

It should be /usr/local/share/i18n/locales/musl

rilian-la-te commented 6 years ago

set it so and try again And you should really install 00locale.sh in correct location to get locales after reboot

nicolasbuch commented 6 years ago

It should be /usr/local/share/i18n/locales/musl

Tried setting it to /usr/local/share/i18n/locales/musl. Still no luck.

/usr/local/bin/locale -a also still outputs C C.UTF-8

Might just be an impossible task at this moment :(

rilian-la-te commented 6 years ago

It should work. Try to export it forcefully and then run locale -a

nicolasbuch commented 6 years ago

It should work. Try to export it forcefully and then run locale -a

The environmental variable, MUSL_LOCPATH? I know it is set correctly. If i echo $MUSL_LOCPATH it outputs /usr/local/share/i18n/locales/musl.

Documentation also states;

In programs running with elevated privileges (setuid/setgid/etc.), the MUSL_LOCPATH environment variable is not honored. At present, this means there is no way to use the locale functionality with such programs. This deficiency will be addressed in a future release.

I'm running in docker. Doesn't that always run with elevated privileges?

rilian-la-te commented 6 years ago

I do not know, I test my programs in VirtualBox alpine installation.

edwardoliveira commented 6 years ago

We have been trying to work around the absence of locale support in Alpine for two months now. There is not really any way of installing support for other languages?

nicolasbuch commented 6 years ago

Unfortunately it does not seem like it at the moment. I spend days researching every way possible without any positive outcome.

Ended up solving it with a custom package (our problem was PHP localization which relies on system locales to work) which overrides the system locales.

I don’t know if you can do something like that , but I would try to look for workarounds until alpine supports locales

cypressious commented 6 years ago

https://github.com/dotnet/dotnet-docker/blob/master/samples/dotnetapp/Dockerfile.alpine-x64-globalization contains a workaround. Basically RUN apk update && apk add --no-cache icu-libs. This works for a .NET application, not sure if it's enough for other runtimes.

iget-master commented 6 years ago

Just an update for @alextanhongpin solution:

As said on the alpine-pkg-glibc package repo, the public signature address changed, so the updated script is:

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://alpine-pkgs.sgerrand.com/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---
bentcoder commented 5 years ago

Is it safe to ignore error below or is there a solution to it? Thanks for the code though.

# cat docker/php/locale.md  | xargs -i /usr/glibc-compat/bin/localedef -i {} -f UTF-8 {}.UTF-8

cannot open locale definition file `iw_IL': No such file or directory
cannot open locale definition file `no_NO': No such file or directory
cannot open locale definition file `pap_AN': No such file or directory
pl77 commented 5 years ago

Is it safe to ignore error below or is there a solution to it?

Just delete those three identifiers from the locale.md file if it concerns you. Likely they were deprecated or reassigned to different identifiers.

Auswaschbar commented 5 years ago

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

nicolasbuch commented 5 years ago

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 locale -a only outputs

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?

rilian-la-te commented 5 years ago

Yes, just push it to me) And if you see untranslated strings, you just need to modify .pot file (it is handmade, not generated).

Herz3h commented 5 years ago

Here is how I managed to install locales on alpine 3.9 (probably works on earlier versions too)

curunoir commented 5 years ago

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.

Herz3h commented 5 years ago

@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: LC_ALL=fr_FR.UTF-8 date on the command line and it outputs english date. Problem is not php I guess.

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: ch_DE de_DE en_US fr_FR ru_RU, more can be added with a PR look above posts for more info).

Basically the steps are:

ENV MUSL_LOCPATH=/usr/local/share/i18n/locales/musl
RUN apk add --update git cmake make musl-dev gcc gettext-dev libintl
RUN cd /tmp && git clone https://gitlab.com/rilian-la-te/musl-locales.git
RUN cd /tmp/musl-locales && cmake . && make && make install

then using

/usr/local/bin/locale -a

To check for presence of the locales.

And to be sure it works, you can type: LANG=fr_FR.UTF-8 date

Edit: Replaced github link with gitlab instead which is more up to date.

ktb83 commented 5 years ago

@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?

ktb:~$ date +%A
Wednesday
ktb:~$ date +%B
November
ktb:~$ LANG=es_ES.UTF-8 date +%A
miercoles
ktb:~$ LANG=es_ES.UTF-8 date +%B
noviembre
ktb:~$ LC_ALL=es_ES.UTF-8 date +%A
miercoles
ktb:~$ LC_ALL=es_ES.UTF-8 date +%B
noviembre
<?php
setlocale(LC_ALL, 'es_ES.UTF-8');
echo 'setlocale(LC_ALL, 0): ' . setlocale(LC_ALL, 0) . '<br>';

echo 'strftime("%A"): ' . strftime('%A') . '<br>';
echo 'strftime("%B"): ' . strftime('%B') . '<br><br>';
?>

Output:

setlocale(LC_ALL, 0): es_ES.UTF-8
strftime("%A"): Wednesday
strftime("%B"): November
rsanzante commented 5 years ago

From https://github.com/gliderlabs/docker-alpine/issues/144#issuecomment-505356435

Basically the steps are:

ENV MUSL_LOCPATH=/usr/local/share/i18n/locales/musl
RUN apk add --update git cmake make musl-dev gcc gettext-dev libintl
RUN cd /tmp && git clone https://github.com/rilian-la-te/musl-locales.git
RUN cd /tmp/musl-locales && cmake . && make && make install

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:

ENV MUSL_LOCPATH=/usr/local/share/i18n/locales/musl
RUN apk add --update git cmake make musl-dev gcc gettext-dev libintl
RUN cd /tmp && git clone https://gitlab.com/rilian-la-te/musl-locales.git
RUN cd /tmp/musl-locales && cmake . && make && make install

Edit: Linked comment was updated and now points to GitLab, so don't get confused if you see there the GitLab URL :)

ktb83 commented 5 years ago

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.

# Maintainer: KTB <ktb83dev@gmail.com>
pkgname=musl-locales
pkgver=8633379e
pkgrel=0
arch="all"
url="https://gitlab.com/rilian-la-te/musl-locales"
pkgdesc="Locales support for musl"
license="MIT AND LGPL-3.0-only"
makedepends="cmake make musl-dev gcc gettext-dev libintl"
subpackages="$pkgname-lang $pkgname-doc"
source="https://gitlab.com/rilian-la-te/$pkgname/-/archive/$pkgver/$pkgname-$pkgver.tar.gz"
options="!check" # no test suite/unit tests

build() {
    cmake . -DCMAKE_INSTALL_PREFIX=/usr
    make
}

package() {
    DESTDIR="$pkgdir" make install
    install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    install -Dm644 LICENSE.MIT "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.MIT
}

sha512sums="a58db2e598b8e0edd960332b912d3c87d0e542f1e82958e826f74a68ab6d8d2fca4c7c75d4eb6745da867e882ff8395d6cb69226937bcfed9d1be3c36a2c416f  musl-locales-8633379e.tar.gz"
ktb83 commented 5 years ago

It looks like the IntlDateFormatter class from the PHP Intl extension can be used on Alpine which relies on ICU:

echo IntlDateFormatter::formatObject(
    new DateTime(), // DateTime object
    "eeee MMMM dd, yyyy '@' hh:mm:ss",  // ICU Date format
    'en_US'  // Locale
) . '<br>';

echo IntlDateFormatter::formatObject(
    new DateTime(), // DateTime object
    "eeee MMMM dd, yyyy '@' hh:mm:ss",  // ICU Date format
    'fr_FR'  // Locale
) . '<br>';

echo IntlDateFormatter::formatObject(
    new DateTime(), // DateTime object
    "eeee MMMM dd, yyyy '@' hh:mm:ss",  // ICU Date format
    'es_ES'  // Locale
) . '<br>';

Output:

Sunday November 17, 2019 @ 11:58:48
dimanche novembre 17, 2019 @ 11:58:48
domingo noviembre 17, 2019 @ 11:58:48

I just installed apache2 php7 php7-apache2 php7-intl and enabled the Intl extension in php.ini. Screenshot_2019-11-17_07-31-39 Screenshot_2019-11-17_09-06-34 Firefox_Screenshot_2019-11-17T12-25-10 014Z

edoeel commented 4 years ago

@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: LC_ALL=fr_FR.UTF-8 date on the command line and it outputs english date. Problem is not php I guess.

Hi @Herz3h, do you have any update about your investigation?

Herz3h commented 4 years ago

@edoardomistretta the steps I posted above (with musl) are the ones I currently use and it's working just fine.

btd1337 commented 4 years ago

This is my Postgres-Alpine locale:

Captura de tela de 2020-05-17 22-13-04

This is my Postgres db settings:

Captura de tela de 2020-05-17 22-14-35

Why my monetary values aren't in pt_BR format?

Captura de tela de 2020-05-17 22-16-36

The amounts should be as: R$ 100,00

What remains to be done for this to work?

hoshsadiq commented 4 years ago

For anyone else stumbling upon this, musl-libc doesn't support LC_MONETARY yet. It is on their roadmap with no target date.

Renrhaf commented 3 years ago

Works with https://github.com/gliderlabs/docker-alpine/issues/144#issuecomment-505356435. Thanks @Herz3h, @rilian-la-te, @Auswaschbar <3

williamdes commented 3 years ago

Source: https://stackoverflow.com/a/63602822/5155484 This works fine:

apk --no-cache add \
    musl-locales \
    musl-locales-lang
FedericoHeichou commented 3 years ago

I suggest this one for PHP

ENV MUSL_LOCPATH="/usr/share/i18n/locales/musl"
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community musl-locales musl-locales-lang \
    && cd "$MUSL_LOCPATH" \
    && for i in *.UTF-8; do cp -a "$i" "${i%%.UTF-8}"; done

It permits to run setlocale(LC_TIME, 'it_IT'); without .UTF-8 too

QGB commented 2 years ago
# apk add --no-cache locales locales-all
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  locales (missing):
    required by: world[locales]
  locales-all (missing):
    required by: world[locales-all]
williamdes commented 2 years ago
# apk add --no-cache locales locales-all
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  locales (missing):
    required by: world[locales]
  locales-all (missing):
    required by: world[locales-all]

https://grrr.tech/posts/2020/add-locales-to-alpine-linux-docker-image/ https://gist.github.com/alextanhongpin/aa55c082a47b9a1b0060a12d85ae7923

FaimMedia commented 1 year ago

Installing the icu-data-full package in Alpine (v3.17+) seems to do the trick to get it working with PHP:

FROM php:8.1-cli-alpine

ENV LC_ALL nl_NL.UTF-8
ENV LANG nl_NL.UTF-8

RUN apk update && apk add libintl icu icu-dev icu-data-full musl-locales musl-locales-lang

RUN docker-php-ext-install -j$(nproc) intl pcntl

RUN locale -a

RUN date

RUN cat /etc/os-release

RUN php -r "echo \\Locale::getDefault() . PHP_EOL;";
RUN php -r "echo (new \\IntlDateFormatter('nl_NL.UTF-8', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Europe/Amsterdam'))->format(new \\DateTime()) . PHP_EOL;"

RUN php -r "print_r(\\ResourceBundle::getLocales(''));"

Last command gives me a list of 800+ locales.

feeh27 commented 1 year ago

Installing the icu-data-full package in Alpine (v3.17+) seems to do the trick to get it working with PHP:

FROM php:8.1-cli-alpine

ENV LC_ALL nl_NL.UTF-8
ENV LANG nl_NL.UTF-8

RUN apk update && apk add libintl icu icu-dev icu-data-full musl-locales musl-locales-lang

RUN docker-php-ext-install -j$(nproc) intl pcntl

RUN locale -a

RUN date

RUN cat /etc/os-release

RUN php -r "echo \\Locale::getDefault() . PHP_EOL;";
RUN php -r "echo (new \\IntlDateFormatter('nl_NL.UTF-8', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Europe/Amsterdam'))->format(new \\DateTime()) . PHP_EOL;"

RUN php -r "print_r(\\ResourceBundle::getLocales(''));"

Last command gives me a list of 800+ locales.

Thanks @FaimMedia this works for me.

marqu3s commented 1 year ago

This is my Postgres-Alpine locale:

None of the solutions I found worked for me. Do you have a working solution for alpine:latest docker image that works for php?