John Davidson

Can't get GETTEXT to work with PHP on MAMP server and Windows 10

0 comments
Message:


I want to use gettext and poedit with php for website translation. I can get poedit to work but gettext does not seem to work in my local web dev environment MAMP, at least I think that is the problem.


My specs:


OS: Windows 10
Gettext 0.21 with Libiconv 1.16 (installed with executable)
Dev Server: MAMP 4.2 (both apache and nginx server show the same error)
Dev Environment: PhpStorm (with MAMP local server set up)
PHP: 7.4 or 8.0 (both throw error)
Browser: Chrome and Firefox (both throw error)

MWE HTML:


<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1><?php gettext("Welcome") ?></h1>
</body>
</html>

Output:


Fatal error: Uncaught Error: Call to undefined function gettext() in C:\MAMP\htdocs\test\test.php:8 Stack trace: #0 {main} thrown in C:\MAMP\htdocs\test\test.php on line 8


I have reinstalled MAMP and updated gettext but the error persists. Am I missing something?


It would also interest me how you guys do translation professionally. Poedit is very convenient but is there an even better approach? So far I've only seen PHP or Laravel arrays, which are very unpleasant to work with, when you have large paragraphs with spans.


Edit:


Running phpinfo() shows gettext:


In Environment:


In PHP Variables:


Edit2:


php_gettext.dll can be found in php/ext dir and extention=gettext is activated in the php.ini.


Running php -r "echo gettext('hello');" in the php dir produces:


PHP Warning:  PHP Startup: Unable to load dynamic library 'gettext' (tried: C:\php\ext\gettext (Das angegebene Modul wurde nicht gefunden), C:\php\ext\php_gettext.dll (Das angegebene Modul wurde nicht gefunden)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'gettext' (tried: C:\php\ext\gettext (Das angegebene Modul wurde nicht gefunden), C:\php\ext\php_gettext.dll (Das angegebene Modul wurde nicht gefunden)) in Unknown on line 0
PHP Fatal error: Uncaught Error: Call to undefined function gettext() in Command line code:1
Stack trace:
#0 {main}
thrown in Command line code on line 1

Fatal error: Uncaught Error: Call to undefined function gettext() in Command line code:1
Stack trace:
#0 {main}
thrown in Command line code on line 1

I've extracted the extension_dir from php -i which is C:PHP/ext. This dir did not exist before. I've tested it by just moving C:\Program Files\gettext-iconv\lib\gettext inside there but no change. The gettext folder had no .so files in it, unlike what @cetver's answer said. After that I tried moving my whole PHP dist to C:PHP but this didn't change anything either.


Short: I moved gettext to the php extension dir but it didn't help.


Edit3:


Now I restarted my machine and it works!


phpinfo() shows gettext now and the site loads:



Take away:


Use C:PHP for your PHP dist.



My Answer:
I help you with something specific?

Rate this post

5 of 5 based on 4539 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us