Problem with gettext

I've tried everything about these links but it still does not work:

and more...

I have tried to mimic phanbook settings and it did not work either.

in services.php

$di->set(
    'translation',
    function ()  use ($config, $di) {
    // force
    $code = 'en_US.UTF-8';

    if ($language->gettext) {
        $trans = new \Phalcon\Translate\Adapter\Gettext([
            'locale'        => $code,
            'directory'     => APP_DIR . '/lang',
            'defaultDomain' => 'messages',
            'category'      => LC_MESSAGES
        ]);

        var_dump($trans);
        echo "<br>";
        // para es que serĂ¡ el centro por ahora no usamos nada
        return $trans;
    }
}

the var_dump()

object(Phalcon\Translate\Adapter\Gettext)#201 (5) {
 ["_interpolator":protected]=> object(Phalcon\Translate\Interpolator\AssociativeArray)#200 (0) { }
 ["_directory":protected]=> string(46) "/usr/share/nginx/dev3.colindar.es/web/app/lang"
 ["_defaultDomain":protected]=> string(8) "messages"
 ["_locale":protected]=> string(11) "en_US.UTF-8"
 ["_category":protected]=> int(5)
}

I try to translate something like that (addFunction to volt done)

<p>{{ _("hola332") }} Peter</p>

I have the path APP_DIR . "/lang/LC_MESSAGES/en_US.UTF-8/messages.mo" and .po fine, translated and with permission.

locale:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

I do not know what else to try

@buryni Could you please provide po-file



2.0k

the messages.po

    msgid ""
    msgstr "Content-Type: text/plain; charset=utf-8 Language: us\n"

    #: views/superadmin/index.volt:26
    msgid "hola332"
    msgstr "Hello"

    #: views/superadmin/index.volt:61
    msgid "Proveedores"
    msgstr "Providers"

the mo file was generated with poedit and also by command line

@buryni Could you please provide po-file



48.3k
edited Dec '16

While you are setting up gettext PO usage it is a good idea to restart your PHP processes (FPM or Apache with mod_php) after each change. It can be highly confusing because each PHP process will store its own gettext cache and so on one reload you could get a fresh PHP process/thread and on the next you will get an old PHP process/thread. In addition to this the gettext calls seem to silently fail (return the default string) when they are incorrectly setup and so overall its quite a pain in the ass, but it does work very well once you have all of the issues resolved.



2.0k
edited Dec '16

I use nginx and php-fpm 5.6.29, in a centos 7 with mariadb, and phalcon 2.0.13 -I must to update but I have a lot of work before :)-

I restarted nginx and php-fpm of course.



48.3k

Your software versions are fine.

I'm not pretty sure, but try to use PO-related header:

# SOME DESCRIPTIVE TITLE
# Copyright (C) YEAR Free Software Foundation, Inc.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <[email protected]>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2008-02-06 16:25-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"


2.0k
edited Dec '16

@sergeyklay I tried as you say and with these variants

    "Content-Type: text/plain; charset=UTF-8 Language: US\n"
    "Content-Type: text/plain; charset=UTF-8 Language: us\n"
    "Content-Type: text/plain; charset=UTF-8 Language: en\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Type: text/plain; charset=utf-8\n"

and compilling with msgfmt -o messages.mo messages.po

Still not working



48.3k

Do we need to create a skeleton project for gettext?



2.0k

Maybe because it still does not work for me :S



2.0k

Hi friends, I need help.

I've tried everything from scratch, even in a new VPS with ubuntu 16.04 + nginx + php7 + phalcon3.0.4 and I can not get gettext to work.

I am willing to pay for whoever can set it up.



48.3k

Have a look at my Webird project. Also be sure to continually restart your PHP processes each time that you make a change to ensure that the cache isn't being used. gettext was designed for desktop apps and it isn't a perfect fit for PHP and it is quite difficult to setup because the changes stick and you never know which PHP process is being used on a request. It appears that each process does its own caching (as of 2-3 years ago). Its cumbersome but restart every single time.