Solar_Locale::fetch()

public string Solar_Locale::fetch ( string|object $spec , string $key , mixed $num = 1 , array $replace = NULL )

Returns the translated locale string for a class and key.

Parameters

  • (string|object) $spec: The class name (or object) for the translation.

  • (string) $key: The translation key.

  • (mixed) $num: Helps determine whether to get a singular or plural translation.

  • (array) $replace: An array of replacement values for the string.

Returns

  • (string) A translated locale string.

Description

Returns the translated locale string for a class and key.

Loads translations as needed.

You can also pass an array of replacement values. If the $replace array is sequential, this method will use it with vsprintf(); if the array is associative, this method will replace "{:key}" with the array value.

For example:

{{code: php

$locale = Solar_Registry('locale');

$page  = 2;
$pages = 10;

// given a class of 'Solar_Example' with a locale string
// TEXT_PAGES => 'Page %d of %d', uses vsprintf() internally:
$replace = array($page, $pages);
echo $locale->fetch('Solar_Example', 'TEXT_PAGES', $pages, $replace);
// echo "Page 2 of 10"

// given a class of 'Solar_Example' with a locale string
// TEXT_PAGES => 'Page {:page} of {:pages}', uses str_replace()
// internally:
$replace = array('page' => $page, 'pages' => $pages);
echo $locale->fetch('Solar_Example', 'TEXT_PAGES', $pages, $replace);
// echo "Page 2 of 10"

}}

See Also



Local