Skip to content

Commit

Permalink
Refactor locale dropdown in BookSearchSettingTab
Browse files Browse the repository at this point in the history
  • Loading branch information
anpigon committed Mar 13, 2024
1 parent b5bf131 commit 9936c5d
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,18 @@ export class BookSearchSettingTab extends PluginSettingTab {
.addDropdown(dropDown => {
const defaultLocale = window.moment.locale();
dropDown.addOption(defaultLocale, `${languages[defaultLocale] || defaultLocale} (Default Locale)`);
window.moment
.locales()
.filter(locale => locale !== defaultLocale)
.forEach(locale => {
const localeName = languages[locale];
if (localeName) dropDown.addOption(locale, localeName);
});
const setValue = this.plugin.settings.localePreference;
if (setValue === 'default') {
dropDown.setValue(defaultLocale);
} else {
dropDown.setValue(setValue);
}
dropDown.onChange(async value => {
const newValue = value;
this.plugin.settings.localePreference = newValue;
await this.plugin.saveSettings();
window.moment.locales().forEach(locale => {
const localeName = languages[locale];
if (localeName && locale !== defaultLocale) dropDown.addOption(locale, localeName);
});
const localeValue = this.plugin.settings.localePreference;
dropDown
.setValue(localeValue === DEFAULT_SETTINGS.localePreference ? defaultLocale : localeValue)
.onChange(async value => {
const newValue = value;
this.plugin.settings.localePreference = newValue;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
Expand Down

0 comments on commit 9936c5d

Please sign in to comment.