Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / I18n / Translator / Loader / Ini.php
blob02a9ecac20e3717ca0017da60d74000b7e1a1433
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\I18n\Translator\Loader;
12 use Zend\Config\Reader\Ini as IniReader;
13 use Zend\I18n\Exception;
14 use Zend\I18n\Translator\Plural\Rule as PluralRule;
15 use Zend\I18n\Translator\TextDomain;
17 /**
18 * PHP INI format loader.
20 class Ini implements FileLoaderInterface
22 /**
23 * load(): defined by FileLoaderInterface.
25 * @see FileLoaderInterface::load()
26 * @param string $locale
27 * @param string $filename
28 * @return TextDomain|null
29 * @throws Exception\InvalidArgumentException
31 public function load($locale, $filename)
33 if (!is_file($filename) || !is_readable($filename)) {
34 throw new Exception\InvalidArgumentException(sprintf(
35 'Could not open file %s for reading',
36 $filename
37 ));
40 $messages = array();
41 $iniReader = new IniReader();
42 $messagesNamespaced = $iniReader->fromFile($filename);
44 $list = $messagesNamespaced;
45 if (isset($messagesNamespaced['translation'])) {
46 $list = $messagesNamespaced['translation'];
49 foreach ($list as $message) {
50 if (!is_array($message) || count($message) < 2) {
51 throw new Exception\InvalidArgumentException(
52 'Each INI row must be an array with message and translation'
55 if (isset($message['message']) && isset($message['translation'])) {
56 $messages[$message['message']] = $message['translation'];
57 continue;
59 $messages[array_shift($message)] = array_shift($message);
62 if (!is_array($messages)) {
63 throw new Exception\InvalidArgumentException(sprintf(
64 'Expected an array, but received %s',
65 gettype($messages)
66 ));
69 $textDomain = new TextDomain($messages);
71 if (array_key_exists('plural', $messagesNamespaced)
72 && isset($messagesNamespaced['plural']['plural_forms'])
73 ) {
74 $textDomain->setPluralRule(
75 PluralRule::fromString($messagesNamespaced['plural']['plural_forms'])
79 return $textDomain;