diff options
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php')
-rw-r--r-- | vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php new file mode 100644 index 00000000..c449f9c1 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php | |||
@@ -0,0 +1,115 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Intl\ResourceBundle; | ||
13 | |||
14 | /** | ||
15 | * Default implementation of {@link LanguageBundleInterface}. | ||
16 | * | ||
17 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
18 | */ | ||
19 | class LanguageBundle extends AbstractBundle implements LanguageBundleInterface | ||
20 | { | ||
21 | /** | ||
22 | * {@inheritdoc} | ||
23 | */ | ||
24 | public function getLanguageName($lang, $region = null, $locale = null) | ||
25 | { | ||
26 | if (null === $locale) { | ||
27 | $locale = \Locale::getDefault(); | ||
28 | } | ||
29 | |||
30 | if (null === ($languages = $this->readEntry($locale, array('Languages')))) { | ||
31 | return null; | ||
32 | } | ||
33 | |||
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]; | ||
38 | } | ||
39 | |||
40 | return $languages[$lang]; | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * {@inheritdoc} | ||
45 | */ | ||
46 | public function getLanguageNames($locale = null) | ||
47 | { | ||
48 | if (null === $locale) { | ||
49 | $locale = \Locale::getDefault(); | ||
50 | } | ||
51 | |||
52 | if (null === ($languages = $this->readEntry($locale, array('Languages')))) { | ||
53 | return array(); | ||
54 | } | ||
55 | |||
56 | if ($languages instanceof \Traversable) { | ||
57 | $languages = iterator_to_array($languages); | ||
58 | } | ||
59 | |||
60 | return $languages; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * {@inheritdoc} | ||
65 | */ | ||
66 | public function getScriptName($script, $lang = null, $locale = null) | ||
67 | { | ||
68 | if (null === $locale) { | ||
69 | $locale = \Locale::getDefault(); | ||
70 | } | ||
71 | |||
72 | $data = $this->read($locale); | ||
73 | |||
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]; | ||
78 | |||
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); | ||
83 | |||
84 | return $scriptName; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | // "af" (Afrikaans) has no "Scripts" block | ||
89 | if (!isset($data['Scripts'][$script])) { | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | return $data['Scripts'][$script]; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * {@inheritdoc} | ||
98 | */ | ||
99 | public function getScriptNames($locale = null) | ||
100 | { | ||
101 | if (null === $locale) { | ||
102 | $locale = \Locale::getDefault(); | ||
103 | } | ||
104 | |||
105 | if (null === ($scripts = $this->readEntry($locale, array('Scripts')))) { | ||
106 | return array(); | ||
107 | } | ||
108 | |||
109 | if ($scripts instanceof \Traversable) { | ||
110 | $scripts = iterator_to_array($scripts); | ||
111 | } | ||
112 | |||
113 | return $scripts; | ||
114 | } | ||
115 | } | ||