]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/Language.class.php
6a1944c730f1169ec21ccd09fcf95d04cf709d3b
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
15 private $currentLanguage;
17 private $languageNames = array(
18 'cs_CZ.utf8' => 'čeština',
19 'de_DE.utf8' => 'German',
20 'en_EN.utf8' => 'English',
21 'en_GB.utf8' => 'English (GB)',
22 'en_US.utf8' => 'English (US)',
23 'es_ES.utf8' => 'Español',
24 'fa_IR.utf8' => 'فارسی',
25 'fr_FR.utf8' => 'Français',
26 'it_IT.utf8' => 'Italiano',
27 'pl_PL.utf8' => 'Polski',
28 'pt_BR.utf8' => 'Português (Brasil)',
29 'ru_RU.utf8' => 'Pусский',
30 'sl_SI.utf8' => 'Slovenščina',
31 'uk_UA.utf8' => 'Українська',
34 public function __construct(Poche
$wallabag)
36 $this->wallabag
= $wallabag;
37 $pocheUser = Session
::getParam('poche_user');
38 $language = (is_null($pocheUser) ? LANG
: $pocheUser->getConfigValue('language'));
40 @putenv('LC_ALL=' . $language);
41 setlocale(LC_ALL
, $language);
42 bindtextdomain($language, LOCALE
);
43 textdomain($language);
45 $this->currentLanguage
= $language;
48 public function getLanguage() {
49 return $this->currentLanguage
;
52 public function getInstalledLanguages() {
53 $handle = opendir(LOCALE
);
56 while (($language = readdir($handle)) !== false) {
57 # Languages are stored in a directory, so all directory names are languages
58 # @todo move language installation data to database
59 if (! is_dir(LOCALE
. '/' . $language) || in_array($language, array('..', '.', 'tools'))) {
65 if ($language === $this->getLanguage()) {
69 $languages[] = array('name' => (isset($this->languageNames
[$language]) ? $this->languageNames
[$language] : $language), 'value' => $language, 'current' => $current);
77 * Update language for current user
81 public function updateLanguage($newLanguage)
83 # we are not going to change it to the current language
84 if ($newLanguage == $this->getLanguage()) {
85 $this->wallabag
->messages
->add('w', _('still using the "' . $this->getLanguage() . '" language!'));
86 Tools
::redirect('?view=config');
89 $languages = $this->getInstalledLanguages();
90 $actualLanguage = false;
92 foreach ($languages as $language) {
93 if ($language['value'] == $newLanguage) {
94 $actualLanguage = true;
99 if (!$actualLanguage) {
100 $this->wallabag
->messages
->add('e', _('that language does not seem to be installed'));
101 Tools
::redirect('?view=config');
104 $this->wallabag
->store
->updateUserConfig($this->wallabag
->user
->getId(), 'language', $newLanguage);
105 $this->wallabag
->messages
->add('s', _('you have changed your language preferences'));
107 $currentConfig = $_SESSION['poche_user']->config
;
108 $currentConfig['language'] = $newLanguage;
110 $_SESSION['poche_user']->setConfig($currentConfig);
113 Tools
::redirect('?view=config');