Class Phalcon\Translate\Adapter\Gettext

extends abstract class Phalcon\Translate\Adapter

implements Phalcon\Translate\AdapterInterface, ArrayAccess

Source on GitHub

  1. <?php
  2. use Phalcon\Translate\Adapter\Gettext;
  3. $adapter = new Gettext(
  4. [
  5. "locale" => "de_DE.UTF-8",
  6. "defaultDomain" => "translations",
  7. "directory" => "/path/to/application/locales",
  8. "category" => LC_MESSAGES,
  9. ]
  10. );

Allows translate using gettext

Methods

public getDirectory ()

public getDefaultDomain ()

public getLocale ()

public getCategory ()

public __construct (array $options)

Phalcon\Translate\Adapter\Gettext constructor

public query (mixed $index, [mixed $placeholders])

Returns the translation related to the given key.

  1. <?php
  2. $translator->query("你好 %name%!", ["name" => "Phalcon"]);

public exists (mixed $index)

Check whether is defined a translation key in the internal array

public nquery (mixed $msgid1, mixed $msgid2, mixed $count, [mixed $placeholders], [mixed $domain])

The plural version of gettext(). Some languages have more than one form for plural messages dependent on the count.

public setDomain (mixed $domain)

Changes the current domain (i.e. the translation file)

public resetDomain ()

Sets the default domain

public setDefaultDomain (mixed $domain)

Sets the domain default to search within when calls are made to gettext()

public setDirectory (mixed $directory)

Sets the path for a domain

  1. <?php
  2. // Set the directory path
  3. $gettext->setDirectory("/path/to/the/messages");
  4. // Set the domains and directories path
  5. $gettext->setDirectory(
  6. [
  7. "messages" => "/path/to/the/messages",
  8. "another" => "/path/to/the/another",
  9. ]
  10. );

public setLocale (mixed $category, mixed $locale)

Sets locale information

  1. <?php
  2. // Set locale to Dutch
  3. $gettext->setLocale(LC_ALL, "nl_NL");
  4. // Try different possible locale names for german
  5. $gettext->setLocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");

protected prepareOptions (array $options)

Validator for constructor

protected getOptionsDefault ()

Gets default options

public setInterpolator (Phalcon\Translate\InterpolatorInterface $interpolator) inherited from Phalcon\Translate\Adapter

public string t (string $translateKey, [array $placeholders]) inherited from Phalcon\Translate\Adapter

Returns the translation string of the given key

public string _ (string $translateKey, [array $placeholders]) inherited from Phalcon\Translate\Adapter

Returns the translation string of the given key (alias of method ‘t’)

public offsetSet (string $offset, string $value) inherited from Phalcon\Translate\Adapter

Sets a translation value

public offsetExists (mixed $translateKey) inherited from Phalcon\Translate\Adapter

Check whether a translation key exists

public offsetUnset (string $offset) inherited from Phalcon\Translate\Adapter

Unsets a translation from the dictionary

public string offsetGet (string $translateKey) inherited from Phalcon\Translate\Adapter

Returns the translation related to the given key

protected replacePlaceholders (mixed $translation, [mixed $placeholders]) inherited from Phalcon\Translate\Adapter

Replaces placeholders by the values passed