1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/**
* MeshBay i18n — lightweight string localization.
*
* Usage:
* import { t, setLocale, getLocale, LOCALES } from './i18n.js';
* t('nav.logout') // "Logout"
* t('status.files', { n: 42 }) // "42 files"
*/
const LANG_KEY = 'mb_lang';
// ── English strings ─────────────────────────────────────────────────────────
const en = {
// Nav
'nav.toggle_menu': 'Toggle menu',
'nav.light_mode': 'Light mode',
'nav.dark_mode': 'Dark mode',
'nav.logout': 'Logout',
'nav.login': 'Login',
// Sidebar
'sidebar.my_groups': 'My Groups',
'sidebar.no_groups': 'No groups yet',
'sidebar.discover': 'Discover',
'sidebar.public_groups': 'Public groups',
// Login
'login.title': 'Login',
'login.username': 'Username',
'login.password': 'Password',
'login.submit': 'Login',
'login.loading': 'Logging in...',
'login.no_account': 'No account?',
'login.register_link': 'Register',
// Register
'register.title': 'Register',
'register.username': 'Username',
'register.email': 'Email',
'register.password': 'Password (min 8 chars)',
'register.confirm': 'Confirm password',
'register.submit': 'Register',
'register.loading': 'Creating account...',
'register.has_account': 'Already have an account?',
'register.login_link': 'Login',
'register.success_title': 'Account created',
'register.success_msg': 'You can now log in with your credentials.',
'register.go_login': 'Go to login',
'register.err_mismatch': 'Passwords do not match',
'register.err_min_len': 'Password must be at least 8 characters',
// Home
'home.welcome': 'Welcome to MeshBay',
'home.no_groups': 'You are not a member of any group yet.',
'home.browse_prefix': 'Browse ',
'home.browse_link': 'public groups',
'home.browse_suffix': ' or ask a group admin to invite you.',
'home.my_groups': 'My Groups',
// Explore
'explore.title': 'Public Groups',
'explore.search': 'Search groups...',
'explore.loading': 'Loading...',
'explore.empty': 'No public groups available.',
'explore.create_group': 'Create group',
'explore.join': 'Join',
'explore.member': 'Joined',
// Group page
'group.default_name': 'Group',
'group.tab_files': 'Files',
'group.tab_chat': 'Chat',
'group.tab_members': 'Members',
'group.filter': 'Filter files...',
'group.col_name': 'Name',
'group.col_size': 'Size',
'group.col_type': 'Type',
'group.col_date': 'Date',
'group.empty_filter': 'No files match the filter',
'group.empty_dir': 'This directory is empty',
'group.download': 'Download',
'group.play': 'Play',
'group.dl_failed': 'Download failed: {err}',
'group.offline_title': 'No nodes are currently online for this group.',
'group.offline_hint': 'Files will appear when a node hosting this group connects.',
'group.upload': 'Upload',
'group.uploading': 'Uploading...',
'group.err_transport': 'Transport module not loaded',
// Status
'status.idle': 'Idle',
'status.discovering': 'Finding nodes...',
'status.connecting': 'Connecting via WebRTC...',
'status.fetching': 'Fetching index...',
'status.files': '{n} files',
'status.offline': 'No nodes online',
'status.error': 'Connection failed',
// Chat
'chat.empty': 'No messages yet. Start the conversation!',
'chat.placeholder': 'Type a message...',
'chat.send': 'Send',
// Video player
'video.loading': 'Loading {name}...',
'video.close': 'Close (Esc)',
'video.err_transport': 'Transport not connected',
// Settings
'settings.title': 'Settings',
'settings.coming_soon': 'Coming soon.',
'settings.profile': 'Profile',
'settings.username': 'Username',
'settings.appearance': 'Appearance',
'settings.theme': 'Theme',
'settings.theme_light': 'Light',
'settings.theme_dark': 'Dark',
'settings.theme_system': 'System',
'settings.language': 'Language',
'settings.about': 'About',
'settings.version': 'Version',
'settings.protocol': 'Protocol',
'settings.role': 'Role',
'settings.groups': 'Group notifications',
'settings.notifications': 'Notifications',
// Sidebar
'sidebar.create_group': 'Create group',
'sidebar.settings': 'Settings',
'sidebar.admin': 'Admin',
// Admin panel
'admin.title': 'Administration',
'admin.tab_stats': 'Stats',
'admin.tab_users': 'Users',
'admin.tab_groups': 'Groups',
'admin.tab_logs': 'Logs',
'admin.tab_blocklist': 'Blocklist',
// Admin stats
'admin.stat_users': 'Users',
'admin.stat_groups': 'Groups',
'admin.stat_nodes': 'Nodes',
'admin.stat_online': 'Online Nodes',
// Admin users
'admin.users_search': 'Search users...',
'admin.col_username': 'Username',
'admin.col_role': 'Role',
'admin.col_status': 'Status',
'admin.col_created': 'Created',
'admin.col_actions': 'Actions',
'admin.col_email': 'Email',
'admin.col_groups': 'Groups',
'admin.no_users': 'No users found',
'admin.btn_suspend': 'Suspend',
'admin.btn_unsuspend': 'Unsuspend',
'admin.btn_details': 'Details',
'admin.user_detail': 'User details',
'admin.btn_close': 'Close',
'admin.self_note': '(you)',
// Admin groups
'admin.col_name': 'Name',
'admin.col_visibility': 'Visibility',
'admin.col_members': 'Members',
'admin.no_groups': 'No groups found',
// Admin logs
'admin.col_time': 'Time',
'admin.col_event': 'Event',
'admin.col_user': 'User',
'admin.col_ip': 'IP',
'admin.col_detail': 'Detail',
'admin.filter_all': 'All events',
'admin.no_logs': 'No logs found',
'admin.btn_load_more': 'Load more',
// Admin blocklist
'admin.col_hash': 'Hash',
'admin.col_reason': 'Reason',
'admin.col_date': 'Date',
'admin.col_added_by': 'Added by',
'admin.no_blocked': 'No blocked hashes',
'admin.add_hash': 'Add hash to blocklist',
'admin.hash_placeholder': 'blake3 hash (64 hex chars)',
'admin.reason_placeholder': 'Reason',
'admin.btn_block': 'Block',
'admin.btn_unblock': 'Unblock',
// Notifications
// Create group
'create_group.title': 'Create Group',
'create_group.name': 'Group name',
'create_group.visibility': 'Visibility',
'create_group.private': 'Private',
'create_group.public': 'Public',
'create_group.join_policy': 'Join policy',
'create_group.invite': 'Invite only',
'create_group.open': 'Open (anyone can join)',
'create_group.submit': 'Create',
'create_group.creating': 'Creating...',
// Members
'members.col_role': 'Role',
'members.admin': 'Admin',
'members.member': 'Member',
'members.invite_title': 'Invite member',
'members.username_placeholder': 'Username',
'members.invite_btn': 'Invite',
'notif.title': 'Notifications',
'notif.empty': 'No notifications',
'notif.mark_all_read': 'Mark all read',
// Sidebar
'sidebar.search': 'Search files',
// Status
'status.cached': '{n} cached files',
// Search
'search.title': 'Search Files',
'search.placeholder': 'Search across all groups...',
'search.no_results': 'No files match your search.',
'search.col_group': 'Group',
'search.result_count': '{n} files found',
'search.hint': 'Search file names across all cached group indexes.',
};
// ── Locale registry ─────────────────────────────────────────────────────────
const _strings = { en };
let _locale = 'en';
export const LOCALES = [
{ code: 'en', name: 'English' },
];
export function getLocale() { return _locale; }
export function setLocale(code) {
if (_strings[code]) {
_locale = code;
localStorage.setItem(LANG_KEY, code);
return true;
}
return false;
}
export function addLocale(code, strings) {
_strings[code] = strings;
}
export function t(key, params) {
let s = (_strings[_locale] && _strings[_locale][key])
|| _strings.en[key]
|| key;
if (params) {
for (const [k, v] of Object.entries(params)) {
s = s.replace(`{${k}}`, v);
}
}
return s;
}
// ── Init ────────────────────────────────────────────────────────────────────
function _init() {
const stored = localStorage.getItem(LANG_KEY);
if (stored && _strings[stored]) {
_locale = stored;
return;
}
const browserLang = (navigator.language || '').split('-')[0];
if (_strings[browserLang]) {
_locale = browserLang;
}
}
_init();
|