]>
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
;
19 private $currentLanguage;
21 private $languageNames = array(
22 'cs_CZ.utf8' => 'čeština',
23 'de_DE.utf8' => 'German',
24 'en_EN.utf8' => 'English',
25 'en_US.utf8' => 'English (US)',
26 'es_ES.utf8' => 'Español',
27 'fa_IR.utf8' => 'فارسی',
28 'fr_FR.utf8' => 'Français',
29 'it_IT.utf8' => 'Italiano',
30 'pl_PL.utf8' => 'Polski',
31 'pt_BR.utf8' => 'Português (Brasil)',
32 'ru_RU.utf8' => 'Pусский',
33 'sl_SI.utf8' => 'Slovenščina',
34 'uk_UA.utf8' => 'Українська',
37 public function __construct(Wallabag
$wallabag)
39 $this->wallabag
= $wallabag;
40 $pocheUser = Session
::getParam('poche_user');
41 $language = (is_null($pocheUser) ? LANG
: $pocheUser->getConfigValue('language'));
43 putenv('LC_ALL=' . $language);
44 setlocale(LC_ALL
, $language);
45 bindtextdomain($language, LOCALE
);
46 textdomain($language);
48 $this->currentLanguage
= $language;
51 public function getLanguage() {
52 return $this->currentLanguage
;
55 public function getInstalledLanguages() {
56 $handle = opendir(LOCALE
);
59 while (($language = readdir($handle)) !== false) {
60 # Languages are stored in a directory, so all directory names are languages
61 # @todo move language installation data to database
62 if (! is_dir(LOCALE
. '/' . $language) || in_array($language, array('..', '.', 'tools'))) {
68 if ($language === $this->getLanguage()) {
72 $languages[] = array('name' => (isset($this->languageNames
[$language]) ? $this->languageNames
[$language] : $language), 'value' => $language, 'current' => $current);
80 * Update language for current user
84 public function updateLanguage($newLanguage)
86 # we are not going to change it to the current language
87 if ($newLanguage == $this->getLanguage()) {
88 $this->wallabag
->messages
->add('w', _('still using the "' . $this->getLanguage() . '" language!'));
89 Tools
::redirect('?view=config');
92 $languages = $this->getInstalledLanguages();
93 $actualLanguage = false;
95 foreach ($languages as $language) {
96 if ($language['value'] == $newLanguage) {
97 $actualLanguage = true;
102 if (!$actualLanguage) {
103 $this->wallabag
->messages
->add('e', _('that language does not seem to be installed'));
104 Tools
::redirect('?view=config');
107 $this->wallabag
->store
->updateUserConfig($this->wallabag
->user
->getId(), 'language', $newLanguage);
108 $this->wallabag
->messages
->add('s', _('you have changed your language preferences'));
110 $currentConfig = $_SESSION['poche_user']->config
;
111 $currentConfig['language'] = $newLanguage;
113 $_SESSION['poche_user']->setConfig($currentConfig);
116 Tools
::redirect('?view=config');