Skip to content

Commit

Permalink
Fix profanity filter breaking if locale isn't set
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Oct 2, 2024
1 parent 79f87da commit 45d9245
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const apiUrl = inject(apiUrlKey);
const route = useRoute();
const routeName = typeof route.name === 'string' ? route.name : '';
const router = useRouter();
const lang = localStorage?.getItem('locale') ?? navigator.language;
const lang = localStorage?.getItem('locale') ?? navigator.language.split('-')[0];
const siteNotificationStore = useSiteNotificationStore();
const {
Expand All @@ -51,7 +51,9 @@ const {
} = siteNotificationStore;
// Handle input filters
const languageList = lang === 'en' ? ['en'] : [lang, 'en']
// The library will error if we supply it with an unsupported language
const supportedLanguages = ['en', 'de'];
const languageList = supportedLanguages.indexOf(lang) !== -1 && lang !== 'en' ? [lang, 'en'] : ['en'];
const profanity = new Profanity({ languages: languageList });
const hasProfanity = (input: string) => profanity.exists(input);
provide(hasProfanityKey, hasProfanity);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const messages = {
de, // German
en, // English
};
const loc = localStorage?.getItem('locale') ?? navigator.language;
const loc = localStorage?.getItem('locale') ?? navigator.language.split('-')[0];
const instance = createI18n({
legacy: false,
globalInjection: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const apiUrl = `${protocol}://${import.meta.env.VITE_API_URL}${port}`;
app.provide(apiUrlKey, apiUrl);
app.provide(bookingUrlKey, `${protocol}://${import.meta.env.VITE_BASE_URL}/appointments/all/`);

const loc = localStorage?.getItem('locale') ?? navigator.language;
const loc = localStorage?.getItem('locale') ?? navigator.language.split('-')[0];
app.use(i18ninstance);
useDayJS(app, loc);

Expand Down

0 comments on commit 45d9245

Please sign in to comment.