We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



5.6k

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



5.6k
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.

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"


5.6k
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



5.6k

Maybe because it still does not work for me :S



5.6k

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.