diff options
author | Nicolas Lœuillet <nicolas@loeuillet.org> | 2015-01-20 07:40:39 +0100 |
---|---|---|
committer | Nicolas Lœuillet <nicolas@loeuillet.org> | 2015-01-20 07:40:39 +0100 |
commit | 6ad93dff69d7c2beb2196e73f641e6484fccbeb7 (patch) | |
tree | 12430b858be2a41029fc11d1afa1fa2a120b96f9 /inc/poche/Language.class.php | |
parent | c78c1a3f08815aab99752026ccdf1dcf63cf43c1 (diff) | |
download | wallabag-6ad93dff69d7c2beb2196e73f641e6484fccbeb7.tar.gz wallabag-6ad93dff69d7c2beb2196e73f641e6484fccbeb7.tar.zst wallabag-6ad93dff69d7c2beb2196e73f641e6484fccbeb7.zip |
new folders
Diffstat (limited to 'inc/poche/Language.class.php')
-rw-r--r-- | inc/poche/Language.class.php | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/inc/poche/Language.class.php b/inc/poche/Language.class.php deleted file mode 100644 index 420f2fb9..00000000 --- a/inc/poche/Language.class.php +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * wallabag, self hostable application allowing you to not miss any content anymore | ||
4 | * | ||
5 | * @category wallabag | ||
6 | * @author Nicolas Lœuillet <nicolas@loeuillet.org> | ||
7 | * @copyright 2013 | ||
8 | * @license http://opensource.org/licenses/MIT see COPYING file | ||
9 | */ | ||
10 | |||
11 | class Language | ||
12 | { | ||
13 | protected $wallabag; | ||
14 | |||
15 | private $currentLanguage; | ||
16 | |||
17 | private $languageNames = array( | ||
18 | 'cs_CZ.utf8' => 'čeština', | ||
19 | 'de_DE.utf8' => 'German', | ||
20 | 'en_EN.utf8' => 'English', | ||
21 | 'en_US.utf8' => 'English (US)', | ||
22 | 'es_ES.utf8' => 'Español', | ||
23 | 'fa_IR.utf8' => 'فارسی', | ||
24 | 'fr_FR.utf8' => 'Français', | ||
25 | 'it_IT.utf8' => 'Italiano', | ||
26 | 'pl_PL.utf8' => 'Polski', | ||
27 | 'pt_BR.utf8' => 'Português (Brasil)', | ||
28 | 'ru_RU.utf8' => 'Pусский', | ||
29 | 'sl_SI.utf8' => 'Slovenščina', | ||
30 | 'uk_UA.utf8' => 'Українська', | ||
31 | ); | ||
32 | |||
33 | public function __construct(Poche $wallabag) | ||
34 | { | ||
35 | $this->wallabag = $wallabag; | ||
36 | $pocheUser = Session::getParam('poche_user'); | ||
37 | $language = (is_null($pocheUser) ? LANG : $pocheUser->getConfigValue('language')); | ||
38 | |||
39 | @putenv('LC_ALL=' . $language); | ||
40 | setlocale(LC_ALL, $language); | ||
41 | bindtextdomain($language, LOCALE); | ||
42 | textdomain($language); | ||
43 | |||
44 | $this->currentLanguage = $language; | ||
45 | } | ||
46 | |||
47 | public function getLanguage() { | ||
48 | return $this->currentLanguage; | ||
49 | } | ||
50 | |||
51 | public function getInstalledLanguages() { | ||
52 | $handle = opendir(LOCALE); | ||
53 | $languages = array(); | ||
54 | |||
55 | while (($language = readdir($handle)) !== false) { | ||
56 | # Languages are stored in a directory, so all directory names are languages | ||
57 | # @todo move language installation data to database | ||
58 | if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.', 'tools'))) { | ||
59 | continue; | ||
60 | } | ||
61 | |||
62 | $current = false; | ||
63 | |||
64 | if ($language === $this->getLanguage()) { | ||
65 | $current = true; | ||
66 | } | ||
67 | |||
68 | $languages[] = array('name' => (isset($this->languageNames[$language]) ? $this->languageNames[$language] : $language), 'value' => $language, 'current' => $current); | ||
69 | } | ||
70 | |||
71 | return $languages; | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Update language for current user | ||
77 | * | ||
78 | * @param $newLanguage | ||
79 | */ | ||
80 | public function updateLanguage($newLanguage) | ||
81 | { | ||
82 | # we are not going to change it to the current language | ||
83 | if ($newLanguage == $this->getLanguage()) { | ||
84 | $this->wallabag->messages->add('w', _('still using the "' . $this->getLanguage() . '" language!')); | ||
85 | Tools::redirect('?view=config'); | ||
86 | } | ||
87 | |||
88 | $languages = $this->getInstalledLanguages(); | ||
89 | $actualLanguage = false; | ||
90 | |||
91 | foreach ($languages as $language) { | ||
92 | if ($language['value'] == $newLanguage) { | ||
93 | $actualLanguage = true; | ||
94 | break; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | if (!$actualLanguage) { | ||
99 | $this->wallabag->messages->add('e', _('that language does not seem to be installed')); | ||
100 | Tools::redirect('?view=config'); | ||
101 | } | ||
102 | |||
103 | $this->wallabag->store->updateUserConfig($this->wallabag->user->getId(), 'language', $newLanguage); | ||
104 | $this->wallabag->messages->add('s', _('you have changed your language preferences')); | ||
105 | |||
106 | $currentConfig = $_SESSION['poche_user']->config; | ||
107 | $currentConfig['language'] = $newLanguage; | ||
108 | |||
109 | $_SESSION['poche_user']->setConfig($currentConfig); | ||
110 | |||
111 | Tools::emptyCache(); | ||
112 | Tools::redirect('?view=config'); | ||
113 | } | ||
114 | } | ||