packagist gettext/gettext v3.0
3.0

latest releases: 4.x-dev, v4.8.10, dev-master...
9 years ago
  • Plural forms are no longer considered when determining translation uniqueness (see #48, #49 ) This removes the plural argument in Gettext\Translations::find() and Gettext\Translations::is().

  • Gettext\Translations merges automatically duplicated translations. For example:

    $translations = new Gettext\Translations();
    
    //Create two equal translations:
    $t1 = new Gettext\Translation('my-context', '1 comment');
    $t2 = new Gettext\Translation('my-context', '1 comment');
    
    //Translate one of them
    $t1->setTranslation('1 comentario');
    
    //Add a reference to the other
    $t2->addReference('filename.php', 23);
    
    //Add both translations to the translations collection
    $translations[] = $t1;
    $translations[] = $t2;
    
    //Search for the translation:
    $found = $translations->find('my-context', '1 comment');
    
    //The translations are merged in one
    echo $found->getTranslation(); // 1 comentario
    var_dump($found->getReferences()); // array(array('filename.php', 23))

    The merge configuration can be changed in using Gettext\Translations::$mergeDefault static variable.

  • New Gettext\Translations::MERGE_LANGUAGE constant to apply the language and plural forms to the merged translations collection.

  • New Gettext\Translations::MERGE_PLURAL constant to merge plural translations into singular translations with the same id (active by default).

  • New methods Gettext\Translations::setPluralForms() and Gettext\Translations::getPluralForms() to add the Plural-Forms header and normalize all translations according with the plural count. For example:

    $translations = new Gettext\Translations();
    
    //Insert a translation with plural:
    $t = $translations->insert(null, '1 comment', '% comments');
    
    //The plural is not translated yet
    echo count($t->getPluralTranslation()); //0
    
    //Set the plural form
    $translations->setPluralForms(2, '(n != 1)');
    
    //Now we have the Plural-Forms header defined
    echo $translatons->getHeader('Plural-Forms'); // nplurals=2; plural=(n != 1);
    
    //And all translations with plurals have the plural translations defined:
    echo count($t->getPluralTranslation()); //1
    
    //To retrieve the plural forms:
    $forms = $t->getPluralForms();
  • Gettext\Translations::setLanguage() add automatically the plural forms, using this locale definitions. For example:

    $translations = new Gettext\Translations();
    
    //Set a locale definition
    $translations->setLanguage('gl');
    
    //Now we have the plural forms defined
    echo $translations->getHeader('Plural-Forms'); // nplurals=2; plural=(n != 1);
  • Removed the method Gettext\Translation::wipeReferences() and added the following methods to delete content:

    Gettext\Translation\deletePluralTranslation();
    Gettext\Translation\deleteReferences();
    Gettext\Translation\deleteComments();
    Gettext\Translation\deleteExtractedComments();
    Gettext\Translation\deleteFlags();
    
    Gettext\Translations\deleteHeader($name);
    Gettext\Translations\deleteHeaders();
  • The method Gettext\Translation::setPluralTranslation() does no longer accept null as second argument.

  • And many more bugfixes and improvements

Don't miss a new gettext release

NewReleases is sending notifications on new releases.