Skip to content

The gettext Translate adapter does not translate a singular/plural phrase if the singular id equals the plural id #58

Closed
zfbot opened this Issue Apr 5, 2013 · 2 comments

3 participants

@zfbot
zfbot commented Apr 5, 2013

Jira Information

Original Issue: ZF-12528
Issue Type: Bug
Reporter: Tim Koop
Created: 02/21/13
Assignee:
Components: Zend_Translate

Description

In your php code, when you want to translate a phrase that could be singular or plural, you specify the singular id, the plural id, and the count. If the singular id exactly equals the plural id, it won't work because of a little bug in {{Zend_Translate_Adapter_Gettext}}.

Zend Translate uses an adapter called {{Zend_Translate_Adapter_Gettext}}. When this class reads in translation data in function {{_loadTranslationData()}}, from a .mo file, it does it mostly correctly:

The existing code: (starting from line 125 or so)

    if ((count($original) > 1) && (count($translate) > 1)) {
        $this->_data[$locale][$original[0]] = $translate;
        array_shift($original);
        foreach ($original as $orig) {
            $this->_data[$locale][$orig] = '';
        }
    } else {
        $this->_data[$locale][$original[0]] = $translate[0];
    }

This code works:

    if ((count($original) > 1) && (count($translate) > 1)) {
        $originalSingular = $original[0];
        foreach ($original as $orig) {
            $this->_data[$locale][$orig] = '';
        }
        $this->_data[$locale][$originalSingular] = $translate;
    } else {
        $this->_data[$locale][$original[0]] = $translate[0];
    }
@zfbot
zfbot commented Apr 5, 2013

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF-12528

Known GitHub users mentioned in the original message or comment:

@fisharebest

This is a duplicate of #66 - for which a patch is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.