@agent-analytics/shared-ui 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/astro/Footer.astro +287 -59
- package/dist/eleventy/footer.njk +289 -15
- package/dist/eleventy/header.njk +250 -0
- package/dist/footer.js +279 -50
- package/dist/header.js +179 -0
- package/dist/index.js +1 -1
- package/dist/locales.js +154 -0
- package/dist/recipes.css +258 -20
- package/package.json +4 -1
package/dist/footer.js
CHANGED
|
@@ -1,54 +1,283 @@
|
|
|
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
|
-
|
|
1
|
+
import { DEFAULT_LOCALE, normalizeLocale, withLocaleUrl } from './locales.js';
|
|
2
|
+
|
|
3
|
+
const footerData = {
|
|
4
|
+
"en": {
|
|
5
|
+
"title": "Agent Analytics",
|
|
6
|
+
"description": "Agent-ready analytics for builders who ship fast.",
|
|
7
|
+
"copy": "Built for builders who ship fast. Open source under MIT.",
|
|
8
|
+
"logoAlt": "Agent Analytics",
|
|
9
|
+
"logoSrc": "/logo-v2.png",
|
|
10
|
+
"sections": [
|
|
11
|
+
{
|
|
12
|
+
"title": "Product",
|
|
13
|
+
"links": [
|
|
14
|
+
{
|
|
15
|
+
"href": "https://app.agentanalytics.sh",
|
|
16
|
+
"label": "Dashboard",
|
|
17
|
+
"trackingId": "footer_product_dashboard"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"href": "https://blog.agentanalytics.sh/",
|
|
21
|
+
"label": "Blog",
|
|
22
|
+
"trackingId": "footer_product_blog"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"href": "https://docs.agentanalytics.sh/",
|
|
26
|
+
"label": "API Docs",
|
|
27
|
+
"trackingId": "footer_product_docs"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"href": "https://github.com/Agent-Analytics/agent-analytics",
|
|
31
|
+
"label": "GitHub",
|
|
32
|
+
"external": true,
|
|
33
|
+
"trackingId": "footer_product_github"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"title": "Compare",
|
|
39
|
+
"links": [
|
|
40
|
+
{
|
|
41
|
+
"href": "https://agentanalytics.sh/compare/umami",
|
|
42
|
+
"label": "vs Umami",
|
|
43
|
+
"trackingId": "footer_compare_umami"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"href": "https://agentanalytics.sh/compare/mixpanel",
|
|
47
|
+
"label": "vs Mixpanel",
|
|
48
|
+
"trackingId": "footer_compare_mixpanel"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"href": "https://agentanalytics.sh/compare/amplitude",
|
|
52
|
+
"label": "vs Amplitude",
|
|
53
|
+
"trackingId": "footer_compare_amplitude"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"href": "https://agentanalytics.sh/compare/ga4",
|
|
57
|
+
"label": "vs GA4",
|
|
58
|
+
"trackingId": "footer_compare_ga4"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"href": "https://agentanalytics.sh/compare/heap",
|
|
62
|
+
"label": "vs Heap",
|
|
63
|
+
"trackingId": "footer_compare_heap"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"href": "https://agentanalytics.sh/compare/adobe-analytics",
|
|
67
|
+
"label": "vs Adobe Analytics",
|
|
68
|
+
"trackingId": "footer_compare_adobe_analytics"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"title": "Company",
|
|
74
|
+
"links": [
|
|
75
|
+
{
|
|
76
|
+
"href": "https://x.com/analytics_90590",
|
|
77
|
+
"label": "X",
|
|
78
|
+
"external": true,
|
|
79
|
+
"trackingId": "footer_company_x"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"href": "mailto:contact@agentanalytics.sh",
|
|
83
|
+
"label": "Contact",
|
|
84
|
+
"trackingId": "footer_company_contact"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"href": "mailto:support@agentanalytics.sh",
|
|
88
|
+
"label": "Support",
|
|
89
|
+
"trackingId": "footer_company_support"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"title": "Legal",
|
|
95
|
+
"links": [
|
|
96
|
+
{
|
|
97
|
+
"href": "https://agentanalytics.sh/privacy",
|
|
98
|
+
"label": "Privacy",
|
|
99
|
+
"trackingId": "footer_legal_privacy"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"href": "https://agentanalytics.sh/terms",
|
|
103
|
+
"label": "Terms",
|
|
104
|
+
"trackingId": "footer_legal_terms"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"href": "https://agentanalytics.sh/dpa",
|
|
108
|
+
"label": "DPA",
|
|
109
|
+
"trackingId": "footer_legal_dpa"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
]
|
|
35
114
|
},
|
|
36
|
-
{
|
|
37
|
-
"
|
|
38
|
-
"
|
|
115
|
+
"he": {
|
|
116
|
+
"title": "Agent Analytics",
|
|
117
|
+
"description": "אנליטיקה מותאמת לסוכנים עבור בונים שמשחררים מהר.",
|
|
118
|
+
"copy": "נבנה עבור בונים שמשחררים מהר. קוד פתוח תחת MIT.",
|
|
119
|
+
"logoAlt": "Agent Analytics",
|
|
120
|
+
"logoSrc": "/logo-v2.png",
|
|
121
|
+
"sections": [
|
|
122
|
+
{
|
|
123
|
+
"title": "מוצר",
|
|
124
|
+
"links": [
|
|
125
|
+
{
|
|
126
|
+
"href": "https://app.agentanalytics.sh",
|
|
127
|
+
"label": "לוח בקרה",
|
|
128
|
+
"trackingId": "footer_product_dashboard"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"href": "https://blog.agentanalytics.sh/he/",
|
|
132
|
+
"label": "בלוג",
|
|
133
|
+
"trackingId": "footer_product_blog"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"href": "https://docs.agentanalytics.sh/he/",
|
|
137
|
+
"label": "תיעוד API",
|
|
138
|
+
"trackingId": "footer_product_docs"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"href": "https://github.com/Agent-Analytics/agent-analytics",
|
|
142
|
+
"label": "GitHub",
|
|
143
|
+
"external": true,
|
|
144
|
+
"trackingId": "footer_product_github"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"title": "חברה",
|
|
150
|
+
"links": [
|
|
151
|
+
{
|
|
152
|
+
"href": "https://x.com/analytics_90590",
|
|
153
|
+
"label": "X",
|
|
154
|
+
"external": true,
|
|
155
|
+
"trackingId": "footer_company_x"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"href": "mailto:contact@agentanalytics.sh",
|
|
159
|
+
"label": "יצירת קשר",
|
|
160
|
+
"trackingId": "footer_company_contact"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"href": "mailto:support@agentanalytics.sh",
|
|
164
|
+
"label": "תמיכה",
|
|
165
|
+
"trackingId": "footer_company_support"
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"title": "משפטי",
|
|
171
|
+
"links": [
|
|
172
|
+
{
|
|
173
|
+
"href": "https://agentanalytics.sh/privacy",
|
|
174
|
+
"label": "פרטיות",
|
|
175
|
+
"trackingId": "footer_legal_privacy"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"href": "https://agentanalytics.sh/terms",
|
|
179
|
+
"label": "תנאים",
|
|
180
|
+
"trackingId": "footer_legal_terms"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"href": "https://agentanalytics.sh/dpa",
|
|
184
|
+
"label": "DPA",
|
|
185
|
+
"trackingId": "footer_legal_dpa"
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
]
|
|
39
190
|
},
|
|
40
|
-
{
|
|
41
|
-
"
|
|
42
|
-
"
|
|
191
|
+
"zh": {
|
|
192
|
+
"title": "Agent Analytics",
|
|
193
|
+
"description": "为快速交付的构建者打造的智能代理分析。",
|
|
194
|
+
"copy": "为快速交付的构建者打造。MIT 开源许可。",
|
|
195
|
+
"logoAlt": "Agent Analytics",
|
|
196
|
+
"logoSrc": "/logo-v2.png",
|
|
197
|
+
"sections": [
|
|
198
|
+
{
|
|
199
|
+
"title": "产品",
|
|
200
|
+
"links": [
|
|
201
|
+
{
|
|
202
|
+
"href": "https://app.agentanalytics.sh",
|
|
203
|
+
"label": "仪表盘",
|
|
204
|
+
"trackingId": "footer_product_dashboard"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"href": "https://blog.agentanalytics.sh/zh/",
|
|
208
|
+
"label": "博客",
|
|
209
|
+
"trackingId": "footer_product_blog"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"href": "https://docs.agentanalytics.sh/zh/",
|
|
213
|
+
"label": "API 文档",
|
|
214
|
+
"trackingId": "footer_product_docs"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"href": "https://github.com/Agent-Analytics/agent-analytics",
|
|
218
|
+
"label": "GitHub",
|
|
219
|
+
"external": true,
|
|
220
|
+
"trackingId": "footer_product_github"
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"title": "公司",
|
|
226
|
+
"links": [
|
|
227
|
+
{
|
|
228
|
+
"href": "https://x.com/analytics_90590",
|
|
229
|
+
"label": "X",
|
|
230
|
+
"external": true,
|
|
231
|
+
"trackingId": "footer_company_x"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"href": "mailto:contact@agentanalytics.sh",
|
|
235
|
+
"label": "联系我们",
|
|
236
|
+
"trackingId": "footer_company_contact"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"href": "mailto:support@agentanalytics.sh",
|
|
240
|
+
"label": "支持",
|
|
241
|
+
"trackingId": "footer_company_support"
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"title": "法律",
|
|
247
|
+
"links": [
|
|
248
|
+
{
|
|
249
|
+
"href": "https://agentanalytics.sh/privacy",
|
|
250
|
+
"label": "隐私",
|
|
251
|
+
"trackingId": "footer_legal_privacy"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"href": "https://agentanalytics.sh/terms",
|
|
255
|
+
"label": "条款",
|
|
256
|
+
"trackingId": "footer_legal_terms"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"href": "https://agentanalytics.sh/dpa",
|
|
260
|
+
"label": "DPA",
|
|
261
|
+
"trackingId": "footer_legal_dpa"
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
]
|
|
43
266
|
}
|
|
44
|
-
];
|
|
45
|
-
export const footerCopy = "Built for builders who ship fast. Open source under MIT.";
|
|
46
|
-
export const footerLogoSrc = "/favicon.png";
|
|
47
|
-
export const footerLogoAlt = "Agent Analytics";
|
|
48
|
-
|
|
49
|
-
export default {
|
|
50
|
-
copy: footerCopy,
|
|
51
|
-
links: footerLinks,
|
|
52
|
-
logoAlt: footerLogoAlt,
|
|
53
|
-
logoSrc: footerLogoSrc,
|
|
54
267
|
};
|
|
268
|
+
|
|
269
|
+
export const footerLocales = footerData;
|
|
270
|
+
export const footerLinks = footerData[DEFAULT_LOCALE].sections.flatMap((section) => section.links);
|
|
271
|
+
export const footerSections = footerData[DEFAULT_LOCALE].sections;
|
|
272
|
+
export const footerCopy = footerData[DEFAULT_LOCALE].copy;
|
|
273
|
+
export const footerDescription = footerData[DEFAULT_LOCALE].description;
|
|
274
|
+
export const footerLogoSrc = footerData[DEFAULT_LOCALE].logoSrc;
|
|
275
|
+
export const footerLogoAlt = footerData[DEFAULT_LOCALE].logoAlt;
|
|
276
|
+
export const footerTitle = footerData[DEFAULT_LOCALE].title;
|
|
277
|
+
|
|
278
|
+
export function getFooter(locale = DEFAULT_LOCALE) {
|
|
279
|
+
return footerData[normalizeLocale(locale)] ?? footerData[DEFAULT_LOCALE];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { DEFAULT_LOCALE, normalizeLocale, withLocaleUrl };
|
|
283
|
+
export default getFooter(DEFAULT_LOCALE);
|
package/dist/header.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { DEFAULT_LOCALE, localizePath, normalizeLocale, withLocaleUrl } from './locales.js';
|
|
2
|
+
|
|
3
|
+
const headerData = {
|
|
4
|
+
"en": {
|
|
5
|
+
"brand": {
|
|
6
|
+
"href": "/",
|
|
7
|
+
"logoAlt": "Agent Analytics",
|
|
8
|
+
"logoSrc": "/logo-v2.png",
|
|
9
|
+
"subtitle": "Agent-ready analytics",
|
|
10
|
+
"title": "AgentAnalytics"
|
|
11
|
+
},
|
|
12
|
+
"links": [
|
|
13
|
+
{
|
|
14
|
+
"href": "https://blog.agentanalytics.sh/",
|
|
15
|
+
"label": "Blog",
|
|
16
|
+
"trackingId": "nav_blog"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"href": "https://docs.agentanalytics.sh/",
|
|
20
|
+
"label": "Docs",
|
|
21
|
+
"trackingId": "nav_docs"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"href": "/#pricing",
|
|
25
|
+
"label": "Pricing",
|
|
26
|
+
"trackingId": "nav_pricing"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"cta": {
|
|
30
|
+
"href": "https://app.agentanalytics.sh",
|
|
31
|
+
"label": "Start free",
|
|
32
|
+
"trackingId": "nav_start_free"
|
|
33
|
+
},
|
|
34
|
+
"switcher": {
|
|
35
|
+
"label": "Language",
|
|
36
|
+
"options": [
|
|
37
|
+
{
|
|
38
|
+
"id": "en",
|
|
39
|
+
"label": "English",
|
|
40
|
+
"nativeLabel": "English",
|
|
41
|
+
"active": true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "he",
|
|
45
|
+
"label": "Hebrew",
|
|
46
|
+
"nativeLabel": "עברית",
|
|
47
|
+
"active": false
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"id": "zh",
|
|
51
|
+
"label": "Chinese",
|
|
52
|
+
"nativeLabel": "简体中文",
|
|
53
|
+
"active": false
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"he": {
|
|
59
|
+
"brand": {
|
|
60
|
+
"href": "/he/",
|
|
61
|
+
"logoAlt": "Agent Analytics",
|
|
62
|
+
"logoSrc": "/logo-v2.png",
|
|
63
|
+
"subtitle": "אנליטיקה מותאמת לסוכנים",
|
|
64
|
+
"title": "AgentAnalytics"
|
|
65
|
+
},
|
|
66
|
+
"links": [
|
|
67
|
+
{
|
|
68
|
+
"href": "https://blog.agentanalytics.sh/he/",
|
|
69
|
+
"label": "בלוג",
|
|
70
|
+
"trackingId": "nav_blog"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"href": "https://docs.agentanalytics.sh/he/",
|
|
74
|
+
"label": "תיעוד",
|
|
75
|
+
"trackingId": "nav_docs"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"href": "/he/#pricing",
|
|
79
|
+
"label": "מחירים",
|
|
80
|
+
"trackingId": "nav_pricing"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"cta": {
|
|
84
|
+
"href": "https://app.agentanalytics.sh",
|
|
85
|
+
"label": "התחילו בחינם",
|
|
86
|
+
"trackingId": "nav_start_free"
|
|
87
|
+
},
|
|
88
|
+
"switcher": {
|
|
89
|
+
"label": "שפה",
|
|
90
|
+
"options": [
|
|
91
|
+
{
|
|
92
|
+
"id": "en",
|
|
93
|
+
"label": "English",
|
|
94
|
+
"nativeLabel": "English",
|
|
95
|
+
"active": false
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "he",
|
|
99
|
+
"label": "Hebrew",
|
|
100
|
+
"nativeLabel": "עברית",
|
|
101
|
+
"active": true
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "zh",
|
|
105
|
+
"label": "Chinese",
|
|
106
|
+
"nativeLabel": "简体中文",
|
|
107
|
+
"active": false
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"zh": {
|
|
113
|
+
"brand": {
|
|
114
|
+
"href": "/zh/",
|
|
115
|
+
"logoAlt": "Agent Analytics",
|
|
116
|
+
"logoSrc": "/logo-v2.png",
|
|
117
|
+
"subtitle": "面向智能代理的分析",
|
|
118
|
+
"title": "AgentAnalytics"
|
|
119
|
+
},
|
|
120
|
+
"links": [
|
|
121
|
+
{
|
|
122
|
+
"href": "https://blog.agentanalytics.sh/zh/",
|
|
123
|
+
"label": "博客",
|
|
124
|
+
"trackingId": "nav_blog"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"href": "https://docs.agentanalytics.sh/zh/",
|
|
128
|
+
"label": "文档",
|
|
129
|
+
"trackingId": "nav_docs"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"href": "/zh/#pricing",
|
|
133
|
+
"label": "价格",
|
|
134
|
+
"trackingId": "nav_pricing"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"cta": {
|
|
138
|
+
"href": "https://app.agentanalytics.sh",
|
|
139
|
+
"label": "免费开始",
|
|
140
|
+
"trackingId": "nav_start_free"
|
|
141
|
+
},
|
|
142
|
+
"switcher": {
|
|
143
|
+
"label": "语言",
|
|
144
|
+
"options": [
|
|
145
|
+
{
|
|
146
|
+
"id": "en",
|
|
147
|
+
"label": "English",
|
|
148
|
+
"nativeLabel": "English",
|
|
149
|
+
"active": false
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"id": "he",
|
|
153
|
+
"label": "Hebrew",
|
|
154
|
+
"nativeLabel": "עברית",
|
|
155
|
+
"active": false
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"id": "zh",
|
|
159
|
+
"label": "Chinese",
|
|
160
|
+
"nativeLabel": "简体中文",
|
|
161
|
+
"active": true
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const headerLocales = headerData;
|
|
169
|
+
export const headerBrand = headerData[DEFAULT_LOCALE].brand;
|
|
170
|
+
export const headerLinks = headerData[DEFAULT_LOCALE].links;
|
|
171
|
+
export const headerCta = headerData[DEFAULT_LOCALE].cta;
|
|
172
|
+
export const headerSwitcher = headerData[DEFAULT_LOCALE].switcher;
|
|
173
|
+
|
|
174
|
+
export function getHeader(locale = DEFAULT_LOCALE) {
|
|
175
|
+
return headerData[normalizeLocale(locale)] ?? headerData[DEFAULT_LOCALE];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { DEFAULT_LOCALE, localizePath, normalizeLocale, withLocaleUrl };
|
|
179
|
+
export default getHeader(DEFAULT_LOCALE);
|
package/dist/index.js
CHANGED
package/dist/locales.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export const DEFAULT_LOCALE = 'en';
|
|
2
|
+
export const SUPPORTED_LOCALES = ['en', 'he', 'zh'];
|
|
3
|
+
export const LOCALE_COOKIE_NAME = 'aa_locale';
|
|
4
|
+
export const LOCALE_COOKIE_DOMAIN = '.agentanalytics.sh';
|
|
5
|
+
export const LOCALE_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
6
|
+
|
|
7
|
+
export const LOCALE_META = Object.freeze({
|
|
8
|
+
en: {
|
|
9
|
+
id: 'en',
|
|
10
|
+
label: 'English',
|
|
11
|
+
nativeLabel: 'English',
|
|
12
|
+
lang: 'en',
|
|
13
|
+
dir: 'ltr',
|
|
14
|
+
},
|
|
15
|
+
he: {
|
|
16
|
+
id: 'he',
|
|
17
|
+
label: 'Hebrew',
|
|
18
|
+
nativeLabel: 'עברית',
|
|
19
|
+
lang: 'he',
|
|
20
|
+
dir: 'rtl',
|
|
21
|
+
},
|
|
22
|
+
zh: {
|
|
23
|
+
id: 'zh',
|
|
24
|
+
label: 'Chinese',
|
|
25
|
+
nativeLabel: '简体中文',
|
|
26
|
+
lang: 'zh-CN',
|
|
27
|
+
dir: 'ltr',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export function normalizeLocale(locale) {
|
|
32
|
+
if (!locale) return DEFAULT_LOCALE;
|
|
33
|
+
const value = String(locale).trim().toLowerCase();
|
|
34
|
+
if (value === 'iw') return 'he';
|
|
35
|
+
if (value === 'zh-cn' || value === 'zh-hans' || value === 'zh-sg') return 'zh';
|
|
36
|
+
if (SUPPORTED_LOCALES.includes(value)) return value;
|
|
37
|
+
return DEFAULT_LOCALE;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getLocaleMeta(locale) {
|
|
41
|
+
return LOCALE_META[normalizeLocale(locale)];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getLocalePrefix(locale) {
|
|
45
|
+
const normalized = normalizeLocale(locale);
|
|
46
|
+
return normalized === DEFAULT_LOCALE ? '' : `/${normalized}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function stripLocalePrefix(pathname = '/') {
|
|
50
|
+
const source = pathname || '/';
|
|
51
|
+
return source.replace(/^\/(?:he|zh)(?=\/|$)/, '') || '/';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function localizePath(locale, pathname = '/') {
|
|
55
|
+
const [pathAndQuery, hash = ''] = String(pathname || '/').split('#');
|
|
56
|
+
const [pathOnly, query = ''] = pathAndQuery.split('?');
|
|
57
|
+
const normalizedPath = stripLocalePrefix(
|
|
58
|
+
pathOnly.startsWith('/') ? pathOnly : `/${pathOnly}`
|
|
59
|
+
);
|
|
60
|
+
const prefix = getLocalePrefix(locale);
|
|
61
|
+
const localizedPath =
|
|
62
|
+
prefix === ''
|
|
63
|
+
? normalizedPath
|
|
64
|
+
: normalizedPath === '/'
|
|
65
|
+
? `${prefix}/`
|
|
66
|
+
: `${prefix}${normalizedPath}`;
|
|
67
|
+
|
|
68
|
+
const search = query ? `?${query}` : '';
|
|
69
|
+
const fragment = hash ? `#${hash}` : '';
|
|
70
|
+
return `${localizedPath}${search}${fragment}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function withLocaleUrl(baseUrl, locale, pathname = '/') {
|
|
74
|
+
return new URL(localizePath(locale, pathname), baseUrl).toString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function detectPreferredLocale(languages = []) {
|
|
78
|
+
for (const language of languages) {
|
|
79
|
+
const value = String(language || '').toLowerCase();
|
|
80
|
+
if (value.startsWith('he') || value.startsWith('iw')) return 'he';
|
|
81
|
+
if (value.startsWith('zh')) return 'zh';
|
|
82
|
+
}
|
|
83
|
+
return DEFAULT_LOCALE;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function readLocaleCookie(cookieString = '') {
|
|
87
|
+
const match = String(cookieString)
|
|
88
|
+
.split(';')
|
|
89
|
+
.map((part) => part.trim())
|
|
90
|
+
.find((part) => part.startsWith(`${LOCALE_COOKIE_NAME}=`));
|
|
91
|
+
|
|
92
|
+
if (!match) return null;
|
|
93
|
+
return normalizeLocale(match.slice(`${LOCALE_COOKIE_NAME}=`.length));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function resolveClientLocale(options = {}) {
|
|
97
|
+
const cookieValue =
|
|
98
|
+
options.cookieString ??
|
|
99
|
+
(typeof document !== 'undefined' ? document.cookie : '');
|
|
100
|
+
const fromCookie = readLocaleCookie(cookieValue);
|
|
101
|
+
if (fromCookie) return fromCookie;
|
|
102
|
+
|
|
103
|
+
const languages =
|
|
104
|
+
options.languages ??
|
|
105
|
+
(typeof navigator !== 'undefined'
|
|
106
|
+
? navigator.languages || [navigator.language]
|
|
107
|
+
: []);
|
|
108
|
+
|
|
109
|
+
return detectPreferredLocale(languages);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function getLocaleCookieDomain(
|
|
113
|
+
targetLocation = typeof location !== 'undefined' ? location : null
|
|
114
|
+
) {
|
|
115
|
+
const hostname = targetLocation?.hostname || '';
|
|
116
|
+
if (hostname === 'agentanalytics.sh' || hostname.endsWith('.agentanalytics.sh')) {
|
|
117
|
+
return LOCALE_COOKIE_DOMAIN;
|
|
118
|
+
}
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function buildLocaleCookie(locale, options = {}) {
|
|
123
|
+
const normalized = normalizeLocale(locale);
|
|
124
|
+
const domain = options.domain ?? getLocaleCookieDomain();
|
|
125
|
+
const maxAge = options.maxAge ?? LOCALE_COOKIE_MAX_AGE;
|
|
126
|
+
const secure =
|
|
127
|
+
options.secure ??
|
|
128
|
+
(typeof location !== 'undefined' ? location.protocol === 'https:' : true);
|
|
129
|
+
|
|
130
|
+
const parts = [
|
|
131
|
+
`${LOCALE_COOKIE_NAME}=${normalized}`,
|
|
132
|
+
'Path=/',
|
|
133
|
+
`Max-Age=${maxAge}`,
|
|
134
|
+
'SameSite=Lax',
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
if (domain) parts.push(`Domain=${domain}`);
|
|
138
|
+
if (secure) parts.push('Secure');
|
|
139
|
+
return parts.join('; ');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function writeLocaleCookie(locale, options = {}) {
|
|
143
|
+
if (typeof document === 'undefined') return normalizeLocale(locale);
|
|
144
|
+
document.cookie = buildLocaleCookie(locale, options);
|
|
145
|
+
return normalizeLocale(locale);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function setDocumentLocale(locale, targetDocument = typeof document !== 'undefined' ? document : null) {
|
|
149
|
+
if (!targetDocument?.documentElement) return getLocaleMeta(locale);
|
|
150
|
+
const meta = getLocaleMeta(locale);
|
|
151
|
+
targetDocument.documentElement.lang = meta.lang;
|
|
152
|
+
targetDocument.documentElement.dir = meta.dir;
|
|
153
|
+
return meta;
|
|
154
|
+
}
|