Using gettext in App Engine for PHP8

Hi,

Is it possible to use PHP's gettext system in PHP8? It works fine in PHP5.5 and PHP7.4 but in PHP 8.2 or PHP8.3 no text returned.

Obivously something different is required when running PHP8. Does anyone have an example on how it's supposed to be set up?

 

Solved Solved
2 3 166
1 ACCEPTED SOLUTION

It has been resolved. For those wonder, this is the order of calls to setup gettext in PHP8.

// e.g.
// $sLocale = 'sv_SE';
// $sTextDomain = 'sv'';
putenv("LANGUAGE=$sLocale");
putenv("LC_ALL=$sLocale");
setlocale(LC_ALL, $sLocale);
bindtextdomain($sTextDomain, "./Locale");
textdomain($sTextDomain);
bind_textdomain_codeset($sTextDomain, 'UTF-8');

View solution in original post

3 REPLIES 3

Greetings @John8543855,

Welcome to Google Cloud Community!

Yes, gettext is an enabled extension in the PHP 8 runtime for App Engine.

Make sure that your PHP runtime environment is configured based on your App Engine Environment. If you have a flexible environment, check out this documentation. If you have a standard environment, follow this documentation

If the above option doesn't work, you can contact Google Cloud Support to further look into your case. Let me know if it helped, thanks!

Thanks for the effort reply. I use standard environment. The documentation is the same for both PHP7 and PHP8. PHP7 works with gettext, PHP8 doesn't.

It has been resolved. For those wonder, this is the order of calls to setup gettext in PHP8.

// e.g.
// $sLocale = 'sv_SE';
// $sTextDomain = 'sv'';
putenv("LANGUAGE=$sLocale");
putenv("LC_ALL=$sLocale");
setlocale(LC_ALL, $sLocale);
bindtextdomain($sTextDomain, "./Locale");
textdomain($sTextDomain);
bind_textdomain_codeset($sTextDomain, 'UTF-8');