]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/Language.class.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
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_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' => 'Українська',
33 public function __construct(Poche
$wallabag)
35 $this->wallabag
= $wallabag;
36 $pocheUser = Session
::getParam('poche_user');
37 $language = (is_null($pocheUser) ? LANG
: $pocheUser->getConfigValue('language'));
39 @putenv('LC_ALL=' . $language);
40 setlocale(LC_ALL
, $language);
41 bindtextdomain($language, LOCALE
);
42 textdomain($language);
44 $this->currentLanguage
= $language;
47 public function getLanguage() {
48 return $this->currentLanguage
;
51 public function getInstalledLanguages() {
52 $handle = opendir(LOCALE
);
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'))) {
64 if ($language === $this->getLanguage()) {
68 $languages[] = array('name' => (isset($this->languageNames
[$language]) ? $this->languageNames
[$language] : $language), 'value' => $language, 'current' => $current);
76 * Update language for current user
80 public function updateLanguage($newLanguage)
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');
88 $languages = $this->getInstalledLanguages();
89 $actualLanguage = false;
91 foreach ($languages as $language) {
92 if ($language['value'] == $newLanguage) {
93 $actualLanguage = true;
98 if (!$actualLanguage) {
99 $this->wallabag
->messages
->add('e', _('that language does not seem to be installed'));
100 Tools
::redirect('?view=config');
103 $this->wallabag
->store
->updateUserConfig($this->wallabag
->user
->getId(), 'language', $newLanguage);
104 $this->wallabag
->messages
->add('s', _('you have changed your language preferences'));
106 $currentConfig = $_SESSION['poche_user']->config
;
107 $currentConfig['language'] = $newLanguage;
109 $_SESSION['poche_user']->setConfig($currentConfig);
112 Tools
::redirect('?view=config');