php gettext not translating at all on Network Solutions server

240 views Asked by At

I am having a strange problem with gettext on a server I am forced to use to redesign a website. The customer is used to having Network Solutions as provider so currently it's not an option to change providers. Anyway the problem is the following:

  • I thought it might not have gettext installed so I checked phpinfo and it is enabled.

    gettext GetText Support enabled

  • I also checked using

    if (!function_exists("gettext")) { echo "gettext is not installed\n"; } else { echo "gettext is supported\n"; }

The output says gettext is supported

I then thought perhaps the server is having issues with the native gettext so I tried using this one https://launchpad.net/php-gettext/. I uploaded it to the server and it's not working either.

The configuration in my header is

putenv("LC_ALL=".$locale.".utf8");
putenv("LANGUAGE=".$locale."utf8");
setlocale(LC_ALL, $locale.".utf8");
bindtextdomain($domain, "./locale");
bind_textdomain_codeset($domain, "UTF-8");
textdomain($domain);`

The $locale and $domain server are assigned before the functions.

The same code with gettext worked fine on my local apache server.

What could be the issue? As the site is not really that big I am considering using a database storage for the translations although I am not really into the idea but I am out of ideas why this is happening.

I have my locale file correctly located in ./locale/language_code/LC_MESSAGES/file.po and file.mo when I echo the return of the bindtextdomain it shows the full path to the locale.

Any suggestions?

2

There are 2 answers

0
Mihail Minkov On BEST ANSWER

After contacting Network Solutions via chat they told me that using their shared hosting you cannot use locales. There's also the problem with specific .htaccess syntax especially for their server which is a pain in the a**. I would definitely not recommend their hosting for shared servers. Anyway, thanks to @jacob-budin and @mike for helping.

12
Jacob Budin On

You're confusing locales with translation files. Locales are useful regional- and languaged-based constants for formatting text, dates, etc. appropriately for the end user. PHP's gettext functions will use the locale to seek the correct translation look-up files, but that's the only property they share.

When you use setlocale, you do not supply a file path, you supply a locale identifier. These quasi-constants vary from system to system (and may be absent), which may ultimately be part of your issue with Network Solutions, but PHP's examples are useful.

You can then use bindtextdomain to specify the translation directory path, and then call textdomain to specify the domain to be used in the current scope.

SitePoint has an article called "Localizing PHP Applications "The Right Way"" that may be helpful to you.