mirror of
https://github.com/edu4rdshl/gnome-shell.git
synced 2026-07-17 23:24:51 +00:00
Right now language changes aren't reflected until log out. This is hard to fix completely, but we can at least refresh the main UI elements without too much fuss. This commit adds a language manager class to listen for when a user's language configuration changes to then emit a 'language-changed' signal that bits of the UI can listen for to recreate themselves. Future commits will handle actually listening for the signal.
34 lines
995 B
JavaScript
34 lines
995 B
JavaScript
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
import AccountsService from 'gi://AccountsService';
|
|
import Gio from 'gi://Gio';
|
|
import GLib from 'gi://GLib';
|
|
import * as Signals from './signals.js';
|
|
import * as Gettext from 'gettext';
|
|
|
|
export class LanguageManager extends Signals.EventEmitter {
|
|
constructor() {
|
|
super();
|
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
|
this._user = this._userManager.get_user(GLib.get_user_name());
|
|
|
|
this._user.connectObject('changed', this._onLanguageUpdated.bind(this));
|
|
}
|
|
|
|
_onLanguageUpdated() {
|
|
if (this.language === this._user.language)
|
|
return;
|
|
|
|
this.language = this._user.language;
|
|
this.emit('language-changed', this._user.language);
|
|
}
|
|
|
|
get language() {
|
|
return Gettext.setlocale(Gettext.LocaleCategory.ALL, null);
|
|
}
|
|
|
|
set language(newLanguage) {
|
|
Gettext.setlocale(Gettext.LocaleCategory.ALL, newLanguage)
|
|
}
|
|
}
|