Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect translating by using Gettext #11311

Closed
sergeyklay opened this issue Jan 16, 2016 · 3 comments
Closed

Incorrect translating by using Gettext #11311

sergeyklay opened this issue Jan 16, 2016 · 3 comments
Labels
bug A bug report status: medium Medium

Comments

@sergeyklay
Copy link
Contributor

How to reproduce

  1. Create /tmp/test.php

    <?php
    _('Hello');
    _('Amazing %name%!');
  2. Next run xgettext /tmp/test.php (this creates a file called messages.po)

  3. Change the "Content-Type: text/plain; charset=CHARSET\n" in this file and replace CHARSET with UTF-8 in this case.

  4. Change the "Language: \n" in this file: "Language: uk\n"

  5. Next translate all strings:

    msgid "Hello"
    msgstr "Привіт"
    
    msgid "Amazing %name%!"
    msgstr "Чудовий %name%!"
    
  6. Save and use the command msgfmt -o messages.mo messages.po which will create a compiled .mo file called messages.mo

  7. Create locale dir mkdir -p /tmp/locale/uk_UA.utf8/LC_MESSAGES

  8. Place this file in this directory /tmp/locale/uk_UA.utf8/LC_MESSAGES/messages.mo

  9. Create test script /tmp/gettext.php:

    <?php

    use Phalcon\Translate\Adapter\Gettext;

    $translator = new Gettext(
        [
            'locale'        => 'uk_UA.utf8',
            'defaultDomain' => 'messages',
            'directory'     => '/tmp/locale',
        ]
    );


    echo $translator->query('Hello'), PHP_EOL;
    echo $translator->t('Amazing %name%!', ['name' => 'Phalcon']), PHP_EOL;
    echo $translator->_('Hello'), PHP_EOL;

Actual

Hello
Amazing Phalcon!
Hello

Expected

Привіт
Чудовий Phalcon!
Привіт
@Jurigag
Copy link
Contributor

Jurigag commented Jan 16, 2016

Are you sure its phalcon problem ? You should check http://php.net/manual/en/function.gettext.php it with php builded functions.

@sergeyklay
Copy link
Contributor Author

Fixed in 2.0.x

@silviomedice
Copy link

No forget to set category

    use Phalcon\Translate\Adapter\Gettext;

    $translator = new Gettext(
        [
            'locale'        => 'uk_UA.utf8',
            'defaultDomain' => 'messages',
            'directory'     => '/tmp/locale',
            'category'      => LC_MESSAGES
        ]
    );


    echo $translator->query('Hello'), PHP_EOL;
    echo $translator->t('Amazing %name%!', ['name' => 'Phalcon']), PHP_EOL;
    echo $translator->_('Hello'), PHP_EOL;

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

4 participants