4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\ResourceBundle
;
15 * Default implementation of {@link LanguageBundleInterface}.
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 class LanguageBundle
extends AbstractBundle
implements LanguageBundleInterface
24 public function getLanguageName($lang, $region = null, $locale = null)
26 if (null === $locale) {
27 $locale = \Locale
::getDefault();
30 if (null === ($languages = $this->readEntry($locale, array('Languages')))) {
34 // Some languages are translated together with their region,
35 // i.e. "en_GB" is translated as "British English"
36 if (null !== $region && isset($languages[$lang.'_'.$region])) {
37 return $languages[$lang.'_'.$region];
40 return $languages[$lang];
46 public function getLanguageNames($locale = null)
48 if (null === $locale) {
49 $locale = \Locale
::getDefault();
52 if (null === ($languages = $this->readEntry($locale, array('Languages')))) {
56 if ($languages instanceof \Traversable
) {
57 $languages = iterator_to_array($languages);
66 public function getScriptName($script, $lang = null, $locale = null)
68 if (null === $locale) {
69 $locale = \Locale
::getDefault();
72 $data = $this->read($locale);
74 // Some languages are translated together with their script,
75 // e.g. "zh_Hans" is translated as "Simplified Chinese"
76 if (null !== $lang && isset($data['Languages'][$lang.'_'.$script])) {
77 $langName = $data['Languages'][$lang.'_'.$script];
79 // If the script is appended in braces, extract it, e.g. "zh_Hans"
80 // is translated as "Chinesisch (vereinfacht)" in locale "de"
81 if (strpos($langName, '(') !== false) {
82 list($langName, $scriptName) = preg_split('/[\s()]/', $langName, null, PREG_SPLIT_NO_EMPTY
);
88 // "af" (Afrikaans) has no "Scripts" block
89 if (!isset($data['Scripts'][$script])) {
93 return $data['Scripts'][$script];
99 public function getScriptNames($locale = null)
101 if (null === $locale) {
102 $locale = \Locale
::getDefault();
105 if (null === ($scripts = $this->readEntry($locale, array('Scripts')))) {
109 if ($scripts instanceof \Traversable
) {
110 $scripts = iterator_to_array($scripts);