-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathloadRosViewMessages.ts
More file actions
95 lines (84 loc) · 2.77 KB
/
loadRosViewMessages.ts
File metadata and controls
95 lines (84 loc) · 2.77 KB
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
import enCommon from './messages/en/common.json';
import enLayout from './messages/en/layout.json';
import enNavbar from './messages/en/navbar.json';
import enPanels from './messages/en/panels.json';
import enPlayback from './messages/en/playback.json';
import enQuality from './messages/en/quality.json';
import enSidebar from './messages/en/sidebar.json';
import enWelcome from './messages/en/welcome.json';
import jaCommon from './messages/ja/common.json';
import jaLayout from './messages/ja/layout.json';
import jaNavbar from './messages/ja/navbar.json';
import jaPanels from './messages/ja/panels.json';
import jaPlayback from './messages/ja/playback.json';
import jaQuality from './messages/ja/quality.json';
import jaSidebar from './messages/ja/sidebar.json';
import jaWelcome from './messages/ja/welcome.json';
import zhCommon from './messages/zh/common.json';
import zhLayout from './messages/zh/layout.json';
import zhNavbar from './messages/zh/navbar.json';
import zhPanels from './messages/zh/panels.json';
import zhPlayback from './messages/zh/playback.json';
import zhQuality from './messages/zh/quality.json';
import zhSidebar from './messages/zh/sidebar.json';
import zhWelcome from './messages/zh/welcome.json';
/**
* Merges shard JSON files under `messages/<locale>/`.
*
* Panel UI message ids use dotted prefixes; see {@link PANEL_TYPE_MESSAGE_SLUG}
* in `@/features/panels/framework/panelMessageSlug` for `PanelType` → slug map
* and naming (`panels.<slug>.settings.*`, `panels.framework.*`, …).
*/
/** Flat ICU message map used by react-intl */
export type RosViewMessages = Record<string, string>;
const EN_SHARDS = [
enCommon,
enWelcome,
enNavbar,
enLayout,
enSidebar,
enQuality,
enPlayback,
enPanels,
] as const;
const ZH_SHARDS = [
zhCommon,
zhWelcome,
zhNavbar,
zhLayout,
zhSidebar,
zhQuality,
zhPlayback,
zhPanels,
] as const;
const JA_SHARDS = [
jaCommon,
jaWelcome,
jaNavbar,
jaLayout,
jaSidebar,
jaQuality,
jaPlayback,
jaPanels,
] as const;
function mergeFlatMessages(locale: string, ...parts: readonly Record<string, string>[]): RosViewMessages {
const out: Record<string, string> = {};
for (const part of parts) {
for (const [key, value] of Object.entries(part)) {
if (import.meta.env.DEV && Object.prototype.hasOwnProperty.call(out, key)) {
console.error(`[i18n] Duplicate message key "${key}" while merging locale "${locale}"`);
}
out[key] = value;
}
}
return out;
}
const MERGED = {
en: mergeFlatMessages('en', ...EN_SHARDS),
zh: mergeFlatMessages('zh', ...ZH_SHARDS),
ja: mergeFlatMessages('ja', ...JA_SHARDS),
} as const;
export type RosViewLocale = keyof typeof MERGED;
export function getRosViewMessages(lang: RosViewLocale): RosViewMessages {
return MERGED[lang] ?? MERGED.en;
}