@asafarim/shared-i18n 0.6.6 → 0.8.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/demo/dist/Icon Dropdown_Limited Languages.png +0 -0
- package/demo/dist/Select Dropdown_Text Only.png +0 -0
- package/demo/dist/assets/favicon-BZYZvBLo.svg +4 -0
- package/demo/dist/assets/index-BdjqKw_N.css +1 -0
- package/demo/dist/assets/index-C1Tq1uEr.js +191 -0
- package/demo/dist/favicon.svg +4 -0
- package/demo/dist/index.html +27 -0
- package/demo/dist/logo.svg +24 -0
- package/demo/node_modules/.bin/browserslist +21 -0
- package/demo/node_modules/.bin/browserslist.CMD +12 -0
- package/demo/node_modules/.bin/browserslist.ps1 +41 -0
- package/demo/node_modules/.bin/tsc +4 -4
- package/demo/node_modules/.bin/tsc.CMD +12 -0
- package/demo/node_modules/.bin/tsc.ps1 +41 -0
- package/demo/node_modules/.bin/tsserver +4 -4
- package/demo/node_modules/.bin/tsserver.CMD +12 -0
- package/demo/node_modules/.bin/tsserver.ps1 +41 -0
- package/demo/node_modules/.bin/vite +4 -4
- package/demo/node_modules/.bin/vite.CMD +12 -0
- package/demo/node_modules/.bin/vite.ps1 +41 -0
- package/demo/node_modules/.vite/deps/@asafarim_country-language-selector.js +848 -0
- package/demo/node_modules/.vite/deps/@asafarim_country-language-selector.js.map +7 -0
- package/demo/node_modules/.vite/deps/_metadata.json +76 -0
- package/demo/node_modules/.vite/deps/chunk-5WRI5ZAA.js +30 -0
- package/demo/node_modules/.vite/deps/chunk-5WRI5ZAA.js.map +7 -0
- package/demo/node_modules/.vite/deps/chunk-B3AHR5EX.js +1004 -0
- package/demo/node_modules/.vite/deps/chunk-B3AHR5EX.js.map +7 -0
- package/demo/node_modules/.vite/deps/chunk-E6BG6WAU.js +292 -0
- package/demo/node_modules/.vite/deps/chunk-E6BG6WAU.js.map +7 -0
- package/demo/node_modules/.vite/deps/chunk-MVARZQEG.js +280 -0
- package/demo/node_modules/.vite/deps/chunk-MVARZQEG.js.map +7 -0
- package/demo/node_modules/.vite/deps/i18next-browser-languagedetector.js +400 -0
- package/demo/node_modules/.vite/deps/i18next-browser-languagedetector.js.map +7 -0
- package/demo/node_modules/.vite/deps/i18next.js +2392 -0
- package/demo/node_modules/.vite/deps/i18next.js.map +7 -0
- package/demo/node_modules/.vite/deps/package.json +3 -0
- package/demo/node_modules/.vite/deps/react-dom.js +6 -0
- package/demo/node_modules/.vite/deps/react-dom.js.map +7 -0
- package/demo/node_modules/.vite/deps/react-dom_client.js +20217 -0
- package/demo/node_modules/.vite/deps/react-dom_client.js.map +7 -0
- package/demo/node_modules/.vite/deps/react-i18next.js +869 -0
- package/demo/node_modules/.vite/deps/react-i18next.js.map +7 -0
- package/demo/node_modules/.vite/deps/react.js +5 -0
- package/demo/node_modules/.vite/deps/react.js.map +7 -0
- package/demo/node_modules/.vite/deps/react_jsx-dev-runtime.js +278 -0
- package/demo/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
- package/demo/node_modules/.vite/deps/react_jsx-runtime.js +6 -0
- package/demo/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
- package/demo/package.json +27 -24
- package/demo/public/favicon.svg +4 -4
- package/demo/public/logo.svg +24 -24
- package/demo/src/App.tsx +129 -116
- package/demo/src/components/CountryLanguageDemo.tsx +140 -0
- package/demo/src/components/GetStartedSection.tsx +56 -56
- package/demo/src/components/KeyTable.tsx +29 -29
- package/demo/src/components/LanguageBar.tsx +102 -18
- package/demo/src/components/LanguageSwitcherDemo.module.css +114 -113
- package/demo/src/components/LanguageSwitcherDemo.tsx +256 -202
- package/demo/src/components/Logo.tsx +6 -6
- package/demo/src/components/OverviewSection.tsx +43 -43
- package/demo/src/components/Panel.tsx +15 -15
- package/demo/src/components/StatusCard.tsx +109 -109
- package/demo/src/index.css +644 -605
- package/demo/src/locales/de/demo.json +85 -0
- package/demo/src/locales/en/demo.json +85 -85
- package/demo/src/locales/fr/demo.json +85 -85
- package/demo/src/locales/it/demo.json +85 -0
- package/demo/src/locales/nl/demo.json +85 -85
- package/demo/src/main.tsx +29 -24
- package/demo/tsconfig.json +18 -18
- package/demo/tsconfig.node.json +10 -10
- package/demo/tsconfig.tsbuildinfo +1 -1
- package/demo/vite-env.d.ts +7 -7
- package/demo/vite.config.d.ts +2 -2
- package/demo/vite.config.js +10 -10
- package/dist/components/LanguageSwitcher.module.css +303 -303
- package/dist/locales/de/common.json +68 -0
- package/dist/locales/it/common.json +68 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +85 -84
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
useTranslation,
|
|
4
|
-
SUPPORTED_LANGUAGES,
|
|
5
|
-
LANGUAGE_NAMES,
|
|
6
|
-
LANGUAGE_COOKIE_NAME,
|
|
7
|
-
getLanguageFromCookie,
|
|
8
|
-
getInitialLanguage,
|
|
9
|
-
updateUserLanguagePreference,
|
|
10
|
-
isSupportedLanguage
|
|
11
|
-
} from '@asafarim/shared-i18n'
|
|
12
|
-
import Panel from './Panel'
|
|
13
|
-
|
|
14
|
-
export default function StatusCard() {
|
|
15
|
-
const { t, i18n } = useTranslation('demo')
|
|
16
|
-
const [cookieValue, setCookieValue] = useState<string | null>(null)
|
|
17
|
-
const [initialLang, setInitialLang] = useState<string>('')
|
|
18
|
-
const [syncResult, setSyncResult] = useState<{ type: 'success' | 'error'; message: string } | null>(null)
|
|
19
|
-
const [isSyncing, setIsSyncing] = useState(false)
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
setCookieValue(getLanguageFromCookie())
|
|
23
|
-
setInitialLang(getInitialLanguage())
|
|
24
|
-
}, [i18n.language])
|
|
25
|
-
|
|
26
|
-
const backendUrl = import.meta.env.VITE_IDENTITY_API_URL || 'not set'
|
|
27
|
-
|
|
28
|
-
const handleSync = async () => {
|
|
29
|
-
setIsSyncing(true)
|
|
30
|
-
setSyncResult(null)
|
|
31
|
-
try {
|
|
32
|
-
const currentLanguage = i18n.language
|
|
33
|
-
if (isSupportedLanguage(currentLanguage)) {
|
|
34
|
-
await updateUserLanguagePreference(currentLanguage)
|
|
35
|
-
} else {
|
|
36
|
-
throw new Error(`Unsupported language: ${currentLanguage}`)
|
|
37
|
-
}
|
|
38
|
-
setSyncResult({
|
|
39
|
-
type: 'success',
|
|
40
|
-
message: t('status.resultOk')
|
|
41
|
-
})
|
|
42
|
-
} catch (error) {
|
|
43
|
-
setSyncResult({
|
|
44
|
-
type: 'error',
|
|
45
|
-
message: `${t('status.resultFail')}: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
46
|
-
})
|
|
47
|
-
} finally {
|
|
48
|
-
setIsSyncing(false)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Panel title={t('status.heading')}>
|
|
54
|
-
<div className="status-grid">
|
|
55
|
-
<div className="status-card">
|
|
56
|
-
<h4>Current Language</h4>
|
|
57
|
-
<p>{i18n.language}</p>
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<div className="status-card">
|
|
61
|
-
<h4>{t('status.cookie')}</h4>
|
|
62
|
-
<p>
|
|
63
|
-
<strong>Name:</strong> {LANGUAGE_COOKIE_NAME}
|
|
64
|
-
</p>
|
|
65
|
-
<p>
|
|
66
|
-
<strong>Value:</strong> {cookieValue || '(not set)'}
|
|
67
|
-
</p>
|
|
68
|
-
</div>
|
|
69
|
-
|
|
70
|
-
<div className="status-card">
|
|
71
|
-
<h4>Initial Language</h4>
|
|
72
|
-
<p>{initialLang}</p>
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
<div className="status-card">
|
|
76
|
-
<h4>Supported Languages</h4>
|
|
77
|
-
<ul className="status-list">
|
|
78
|
-
{SUPPORTED_LANGUAGES.map((lang: string) => (
|
|
79
|
-
<li key={lang}>
|
|
80
|
-
{lang}: {LANGUAGE_NAMES[lang as keyof typeof LANGUAGE_NAMES]}
|
|
81
|
-
</li>
|
|
82
|
-
))}
|
|
83
|
-
</ul>
|
|
84
|
-
</div>
|
|
85
|
-
|
|
86
|
-
<div className="status-card">
|
|
87
|
-
<h4>{t('status.backend')}</h4>
|
|
88
|
-
<p>{backendUrl}</p>
|
|
89
|
-
</div>
|
|
90
|
-
|
|
91
|
-
<div className="status-card">
|
|
92
|
-
<h4>Backend Sync</h4>
|
|
93
|
-
<button
|
|
94
|
-
className="sync-button"
|
|
95
|
-
onClick={handleSync}
|
|
96
|
-
disabled={isSyncing}
|
|
97
|
-
>
|
|
98
|
-
{isSyncing ? 'Syncing...' : t('status.simulate')}
|
|
99
|
-
</button>
|
|
100
|
-
{syncResult && (
|
|
101
|
-
<div className={`sync-result ${syncResult.type}`}>
|
|
102
|
-
{syncResult.message}
|
|
103
|
-
</div>
|
|
104
|
-
)}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
</Panel>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
useTranslation,
|
|
4
|
+
SUPPORTED_LANGUAGES,
|
|
5
|
+
LANGUAGE_NAMES,
|
|
6
|
+
LANGUAGE_COOKIE_NAME,
|
|
7
|
+
getLanguageFromCookie,
|
|
8
|
+
getInitialLanguage,
|
|
9
|
+
updateUserLanguagePreference,
|
|
10
|
+
isSupportedLanguage
|
|
11
|
+
} from '@asafarim/shared-i18n'
|
|
12
|
+
import Panel from './Panel'
|
|
13
|
+
|
|
14
|
+
export default function StatusCard() {
|
|
15
|
+
const { t, i18n } = useTranslation('demo')
|
|
16
|
+
const [cookieValue, setCookieValue] = useState<string | null>(null)
|
|
17
|
+
const [initialLang, setInitialLang] = useState<string>('')
|
|
18
|
+
const [syncResult, setSyncResult] = useState<{ type: 'success' | 'error'; message: string } | null>(null)
|
|
19
|
+
const [isSyncing, setIsSyncing] = useState(false)
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setCookieValue(getLanguageFromCookie())
|
|
23
|
+
setInitialLang(getInitialLanguage())
|
|
24
|
+
}, [i18n.language])
|
|
25
|
+
|
|
26
|
+
const backendUrl = import.meta.env.VITE_IDENTITY_API_URL || 'not set'
|
|
27
|
+
|
|
28
|
+
const handleSync = async () => {
|
|
29
|
+
setIsSyncing(true)
|
|
30
|
+
setSyncResult(null)
|
|
31
|
+
try {
|
|
32
|
+
const currentLanguage = i18n.language
|
|
33
|
+
if (isSupportedLanguage(currentLanguage)) {
|
|
34
|
+
await updateUserLanguagePreference(currentLanguage)
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error(`Unsupported language: ${currentLanguage}`)
|
|
37
|
+
}
|
|
38
|
+
setSyncResult({
|
|
39
|
+
type: 'success',
|
|
40
|
+
message: t('status.resultOk')
|
|
41
|
+
})
|
|
42
|
+
} catch (error) {
|
|
43
|
+
setSyncResult({
|
|
44
|
+
type: 'error',
|
|
45
|
+
message: `${t('status.resultFail')}: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
46
|
+
})
|
|
47
|
+
} finally {
|
|
48
|
+
setIsSyncing(false)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Panel title={t('status.heading')}>
|
|
54
|
+
<div className="status-grid">
|
|
55
|
+
<div className="status-card">
|
|
56
|
+
<h4>Current Language</h4>
|
|
57
|
+
<p>{i18n.language}</p>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div className="status-card">
|
|
61
|
+
<h4>{t('status.cookie')}</h4>
|
|
62
|
+
<p>
|
|
63
|
+
<strong>Name:</strong> {LANGUAGE_COOKIE_NAME}
|
|
64
|
+
</p>
|
|
65
|
+
<p>
|
|
66
|
+
<strong>Value:</strong> {cookieValue || '(not set)'}
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<div className="status-card">
|
|
71
|
+
<h4>Initial Language</h4>
|
|
72
|
+
<p>{initialLang}</p>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div className="status-card">
|
|
76
|
+
<h4>Supported Languages</h4>
|
|
77
|
+
<ul className="status-list">
|
|
78
|
+
{SUPPORTED_LANGUAGES.map((lang: string) => (
|
|
79
|
+
<li key={lang}>
|
|
80
|
+
{lang}: {LANGUAGE_NAMES[lang as keyof typeof LANGUAGE_NAMES]}
|
|
81
|
+
</li>
|
|
82
|
+
))}
|
|
83
|
+
</ul>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div className="status-card">
|
|
87
|
+
<h4>{t('status.backend')}</h4>
|
|
88
|
+
<p>{backendUrl}</p>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
<div className="status-card">
|
|
92
|
+
<h4>Backend Sync</h4>
|
|
93
|
+
<button
|
|
94
|
+
className="sync-button"
|
|
95
|
+
onClick={handleSync}
|
|
96
|
+
disabled={isSyncing}
|
|
97
|
+
>
|
|
98
|
+
{isSyncing ? 'Syncing...' : t('status.simulate')}
|
|
99
|
+
</button>
|
|
100
|
+
{syncResult && (
|
|
101
|
+
<div className={`sync-result ${syncResult.type}`}>
|
|
102
|
+
{syncResult.message}
|
|
103
|
+
</div>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</Panel>
|
|
108
|
+
)
|
|
109
|
+
}
|