Skip to content
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

Support for locale in the Alpine Images #350

Closed
henriquejsfj opened this issue Apr 9, 2024 · 6 comments
Closed

Support for locale in the Alpine Images #350

henriquejsfj opened this issue Apr 9, 2024 · 6 comments
Labels
review Issues with improvements proposals or fix a bug... but need to be checked first. support User asking for help.

Comments

@henriquejsfj
Copy link

Short story
I am facing issues with locale configuration using the pkpofficial/ojs:stable-3_4_0 image.
More specific, the issues are about date and time translations. (In my case, to pt_BR)

The code that belongs to PKP works nice, however, smarty translations which relies on PHP strftime not (although deprecated).

It seems that some stuff are misconfigured, I managed to configure until seeing in terminal a positive feedback like:
image

However, the smarty part still doesn't work. We can check it easily by going to the search page to see the month options or in the admin/systemInfo.

A workaround I managed to see working was to put in the beginning of the template files {{setlocale(LC_ALL, 'pt_BR.UTF-8')}}

Long explanation
From a time ago the Alpine docker images comes without icu-data-full which needs to be installed manually, see:
icu-data-full

This didn't helped me so much, so I did my homework and found it:
https://stackoverflow.com/questions/49042223/how-to-set-locale-in-docker-alpine

So, I put all this in my image built on top of the pkpofficial/ojs:stable-3_4_0 image and still nothing.

Then I had 2 goals:

  • Make date put the time in pt_BR
  • Make a simple test script work:
<?php

$intldate = IntlDateFormatter::create(null);
echo $intldate->format(time());
setlocale(LC_ALL, "pt_BR");
echo "<br>";
echo strftime("%A, %B de %G");

First line from $intldate->format(time()); was good but strftime("%A, %B de %G"); was always in english no matter what I put inside the setlocale. It was running even with random wrong locale like setlocale(LC_ALL, "jkasghdjkahgsdjk").

Okay, in the end I achieved the correct configuration after finding this:
https://www.nixcraft.com/t/how-to-change-date-command-output-language-locales-in-alpine-linux/4434/2

Was missing only the export MUSL_LOCPATH=/usr/share/i18n/locales/musl

However, after all this work the SMARTY date translation is still NOT WORKING!!!

My Dockerfile with locale configuration:

FROM pkpofficial/ojs:stable-3_4_0 as ojs-postgres
# FROM alpine:3.18 as ojs-postgres

# Workaround alpine iconv bug
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

RUN set -xe \
	&& apk add --no-cache php81-pecl-memcached \
	&& apk add --no-cache php81-pgsql \
	&& apk add --no-cache php81-pdo_pgsql \
	&& apk add --no-cache php81-mbstring \
	&& apk add --no-cache php81-iconv \
	&& apk add --no-cache icu-libs icu-data-full \
	&& apk add --no-cache musl musl-utils musl-locales lang \
	&& apk add --no-cache tzdata \
	&& cp /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime \
	&& echo "America/Sao_Paulo" >  /etc/timezone

ENV TZ America/Sao_Paulo
ENV LANG pt_BR.UTF-8
ENV LANGUAGE pt_BR.UTF-8
ENV LC_ALL pt_BR.UTF-8
ENV MUSL_LOCPATH /usr/share/i18n/locales/musl

RUN echo 'export LC_ALL=pt_BR.UTF-8' >> /etc/profile.d/locale.sh && \
  sed -i 's|LANG=C.UTF-8|LANG=pt_BR.UTF-8|' /etc/profile.d/locale.sh

Sorry bothering, I am new to PHP but I expected to have these images ready to run for different locale and I wish I had arrived with a solution.

@marcbria
Copy link
Collaborator

Hi @henriquejsfj

Sorry for the delay in my answer.
I'm overwelmed right now with this collateral project, so it's hard to me to keep this up to date.

I use es_ES myself and I don't recall any trouble with locales, but I will check it before next release.

But at first glance... my question would be, why changing the system l18n instead of doing the change at php level?
My rule of the thumb is "keep the OS in english and let your app be regional".
It helps when you get error messages... as English is the lingua franca in technical forums.

So, did you try changing the date format in OJS with the propper config.inc.php variables?

@marcbria marcbria added review Issues with improvements proposals or fix a bug... but need to be checked first. support User asking for help. labels Apr 24, 2024
@henriquejsfj
Copy link
Author

Very nice project @marcbria, using Ansible playbooks would be a great advance.

Thanks for your reply, I agree with "keep the OS in english and let your app be regional". Maybe all the configuration I made is not necessary nor is the solution, but I was trying to make smarty translation (strftime) work.

So, did you try changing the date format in OJS with the propper config.inc.php variables?

Yes, if that is:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Localization Settings ;
;;;;;;;;;;;;;;;;;;;;;;;;;

[i18n]

; Default locale
locale = pt_BR.UTF-8

; Database connection character set
connection_charset = utf8

I guess the default was locale = pt_BR and both did not work.

I use es_ES myself and I don't recall any trouble with locales, but I will check it before next release.

Could you check if the months in the search page are in Spanish? I guess that is the unique misbehaviour a common user may see.

If that is not ok we do have a problem, and I would be glad to help (if under my capabilities). If that is ok, I would close this issue and pull out my hair.

@henriquejsfj
Copy link
Author

@marcbria I just saw your URL checker, nice work!

However, I see in your Testdrive journal search page that the issue with month language persists. You may select any language and months are still in English.

@marcbria
Copy link
Collaborator

Wired...

In my dockerized OJS (3.3.0-14) they ARE fine:
https://revistes.uab.cat/fraseolex/search

Those are the most relevant variables in my config.ini.php:

[general]
time_zone = "Madrid"
date_format_trunc = "%d-%m"
date_format_short = "%d-%m-%Y"
date_format_long = "%B %e, %Y"
datetime_format_short = "%d-%m-%Y %I:%M %p"
datetime_format_long = "%B %e, %Y - %I:%M %p"
time_format = "%I:%M %p"
trust_x_forwarded_for = On
[i18n]
locale = es_ES
client_charset = utf-8
conection_charset = utf8
database_charset =  utf8mb4_general_ci
charset_normalization = utf-8
[finfo]
mime_database_path = /etc/magic.mime

Cheers,
m.

@henriquejsfj
Copy link
Author

Thanks @marcbria !

I tried with [i18n] options you provided, but unfortunately I did not managed to solve my issue.

In any case, seems the problem is in my side now 😞

@marcbria
Copy link
Collaborator

Please, keep us informed about your advances.
I really want to make this images easy an handy for everybody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Issues with improvements proposals or fix a bug... but need to be checked first. support User asking for help.
Projects
None yet
Development

No branches or pull requests

2 participants