]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/Wallabag/Language.php
3 * wallabag, self hostable application allowing you to not miss any content anymore
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
8 * @license http://opensource.org/licenses/MIT see COPYING file
11 namespace Wallabag\Wallabag
;
17 private $currentLanguage;
19 private $languageNames = array(
20 'cs_CZ.utf8' => 'čeština',
21 'de_DE.utf8' => 'German',
22 'en_EN.utf8' => 'English',
23 'en_US.utf8' => 'English (US)',
24 'es_ES.utf8' => 'Español',
25 'fa_IR.utf8' => 'فارسی',
26 'fr_FR.utf8' => 'Français',
27 'it_IT.utf8' => 'Italiano',
28 'pl_PL.utf8' => 'Polski',
29 'pt_BR.utf8' => 'Português (Brasil)',
30 'ru_RU.utf8' => 'Pусский',
31 'sl_SI.utf8' => 'Slovenščina',
32 'uk_UA.utf8' => 'Українська',
35 public function __construct(Wallabag
$wallabag)
37 $this->wallabag
= $wallabag;
38 $pocheUser = Session
::getParam('poche_user');
39 $language = (is_null($pocheUser) ? LANG
: $pocheUser->getConfigValue('language'));
41 @putenv('LC_ALL=' . $language);
42 setlocale(LC_ALL
, $language);
43 bindtextdomain($language, LOCALE
);
44 textdomain($language);
46 $this->currentLanguage
= $language;
49 public function getLanguage() {
50 return $this->currentLanguage
;
53 public function getInstalledLanguages() {
54 $handle = opendir(LOCALE
);
57 while (($language = readdir($handle)) !== false) {
58 # Languages are stored in a directory, so all directory names are languages
59 # @todo move language installation data to database
60 if (! is_dir(LOCALE
. '/' . $language) || in_array($language, array('..', '.', 'tools'))) {
66 if ($language === $this->getLanguage()) {
70 $languages[] = array('name' => (isset($this->languageNames
[$language]) ? $this->languageNames
[$language] : $language), 'value' => $language, 'current' => $current);
78 * Update language for current user
82 public function updateLanguage($newLanguage)
84 # we are not going to change it to the current language
85 if ($newLanguage == $this->getLanguage()) {
86 $this->wallabag
->messages
->add('w', _('still using the "' . $this->getLanguage() . '" language!'));
87 Tools
::redirect('?view=config');
90 $languages = $this->getInstalledLanguages();
91 $actualLanguage = false;
93 foreach ($languages as $language) {
94 if ($language['value'] == $newLanguage) {
95 $actualLanguage = true;
100 if (!$actualLanguage) {
101 $this->wallabag
->messages
->add('e', _('that language does not seem to be installed'));
102 Tools
::redirect('?view=config');
105 $this->wallabag
->store
->updateUserConfig($this->wallabag
->user
->getId(), 'language', $newLanguage);
106 $this->wallabag
->messages
->add('s', _('you have changed your language preferences'));
108 $currentConfig = $_SESSION['poche_user']->config
;
109 $currentConfig['language'] = $newLanguage;
111 $_SESSION['poche_user']->setConfig($currentConfig);
114 Tools
::redirect('?view=config');