Skip to content

Commit bbbe2b6

Browse files
authored
fix: use static month names in getTimeRange to prevent OS locale leaking into sidebar (open-webui#22454)
getTimeRange returns month names that are used as i18n translation keys (consumed via \.t(chat.time_range) in the sidebar, search modal, etc.). The keys must be exact English strings like 'January', 'February', etc. Previously, toLocaleString('default', { month: 'long' }) was used to generate these keys. The 'default' locale defers to the browser's locale resolution, which in Firefox with intl.regional_prefs.use_os_locales=true picks up OS regional settings instead of the browser language. This caused German month names (e.g. 'Februar', 'Januar') to appear in the sidebar for users whose OS region is set to Germany, even when both browser and app language are set to English. Chrome was unaffected because it ignores OS regional settings for the 'default' locale. Since i18n has no translation key for 'Februar', the German string passed through untranslated. Replace toLocaleString with a static MONTH_NAMES array lookup to make the intent explicit and eliminate any browser/OS locale dependency.
1 parent 63a0bef commit bbbe2b6

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/lib/utils/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,22 @@ export const approximateToHumanReadable = (nanoseconds: number) => {
10941094
return results.reverse().join(' ');
10951095
};
10961096

1097+
// Month names used as i18n translation keys — must be English regardless of locale
1098+
const MONTH_NAMES = [
1099+
'January',
1100+
'February',
1101+
'March',
1102+
'April',
1103+
'May',
1104+
'June',
1105+
'July',
1106+
'August',
1107+
'September',
1108+
'October',
1109+
'November',
1110+
'December'
1111+
];
1112+
10971113
export const getTimeRange = (timestamp) => {
10981114
const now = new Date();
10991115
const date = new Date(timestamp * 1000); // Convert Unix timestamp to milliseconds
@@ -1119,7 +1135,7 @@ export const getTimeRange = (timestamp) => {
11191135
} else if (diffDays <= 30) {
11201136
return 'Previous 30 days';
11211137
} else if (nowYear === dateYear) {
1122-
return date.toLocaleString('default', { month: 'long' });
1138+
return MONTH_NAMES[dateMonth];
11231139
} else {
11241140
return date.getFullYear().toString();
11251141
}

0 commit comments

Comments
 (0)