@capillarytech/blaze-ui 5.11.4 → 5.11.7
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/CapLanguageProvider/CapLanguageProvider-use-cases.md +56 -0
- package/CapLanguageProvider/README.md +206 -0
- package/CapLanguageProvider/index.d.ts +4 -59
- package/CapLanguageProvider/index.d.ts.map +1 -1
- package/CapLanguageProvider/index.js +53 -46
- package/CapLanguageProvider/index.js.map +1 -1
- package/CapLanguageProvider/reducer.d.ts +3 -11
- package/CapLanguageProvider/reducer.d.ts.map +1 -1
- package/CapLanguageProvider/types.d.ts +120 -0
- package/CapLanguageProvider/types.d.ts.map +1 -0
- package/CapNavigation/index.js +2 -6
- package/CapNavigation/index.js.map +1 -1
- package/CapUserProfile/index.js +2 -6
- package/CapUserProfile/index.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +53 -38
- package/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Test Cases: CapLanguageProvider (Antd v3→v6)
|
|
2
|
+
|
|
3
|
+
## Role
|
|
4
|
+
Senior frontend engineer documenting ESSENTIAL test cases for Storybook stories and migration validation.
|
|
5
|
+
|
|
6
|
+
## Input
|
|
7
|
+
- **Component**: CapLanguageProvider
|
|
8
|
+
- **Complexity**: medium (≤20 test cases)
|
|
9
|
+
- **Source**: blaze-ui/components/CapLanguageProvider/
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
| ID | Use Case | Props/Config | Expected Visual/Behavior | Priority | Storybook Story | Notes |
|
|
14
|
+
|----|----------|--------------|-------------------------|----------|-----------------|-------|
|
|
15
|
+
| UC-001 | Basic rendering with children | children: ReactNode, actions: {getSupportedLocales, getLocizeMessage}, language: {locale: 'en'}, messages: {} | Component renders child content wrapped in ConfigProvider and IntlProvider. Calls getSupportedLocales on mount. | P0 | BasicRendering | Essential baseline test |
|
|
16
|
+
| UC-002 | All locale source variants | user.iso_lang: 'en_US' \| 'en-US' \| 'fr-FR', localStorage.locale: 'en_US' \| 'fr-FR', supportedLocales: [{locale, locize_locale}] | Locale loaded from user.iso_lang (priority 1), falls back to localStorage.locale (priority 2), defaults to 'en-US'. Correctly converts hyphen/underscore formats. | P0 | LocaleSources | Grouped all locale source scenarios |
|
|
17
|
+
| UC-003 | Locale format conversion | lang: 'en-US' \| 'en_US' \| 'fr-FR' \| 'fr_FR' | Converts to antd format (en_US), react-intl format (en), and locize format (en-US). Handles both hyphen and underscore separators. | P0 | LocaleConversion | Grouped all format conversion scenarios |
|
|
18
|
+
| UC-004 | Spinner visibility states | spinnerVisible: true \| false, language.localeLoading: 'REQUEST' \| 'IDLE' \| 'COMPLETE', supportedLocalesDetails.fetchSupportedLocalesStatus: 'REQUEST' \| 'IDLE' \| 'COMPLETE', isLoginPage: true \| false | Spinner shows when spinnerVisible=true AND not on login page AND (localeLoading='REQUEST' OR fetchSupportedLocalesStatus='REQUEST'). Hidden otherwise. | P1 | SpinnerStates | Grouped all spinner visibility conditions |
|
|
19
|
+
| UC-005 | Login page skip behavior | window.location.pathname includes '/login' | getSupportedLocales and getLocizeMessage called with isSkip=true. Spinner never shows on login page regardless of loading state. | P1 | LoginPageSkip | Critical for login UX |
|
|
20
|
+
| UC-006 | Messages prop variants | messages: {} \| {key: 'value'} \| undefined, language.messages: {} \| {key: 'value'} \| undefined | Uses language.messages if available, falls back to messages prop. Passes to IntlProvider. Empty object handled gracefully. | P1 | MessagesVariants | Grouped messages prop scenarios |
|
|
21
|
+
| UC-007 | Supported locales loading | supportedLocalesDetails: {} \| {supportedLocales: [], fetchSupportedLocalesStatus: 'REQUEST'/'IDLE'/'COMPLETE'} | Waits for supportedLocales before calling getLocizeMessage. Handles empty/missing supportedLocales array. | P1 | SupportedLocalesLoading | Critical for locale initialization |
|
|
22
|
+
| UC-008 | Locale update on user/supportedLocales change | user: {} → {iso_lang: 'en_US'}, supportedLocalesDetails: {} → {supportedLocales: [...]} | Calls updateLocale() when both user and supportedLocales become available. Updates antd locale, react-intl locale, moment locale, and dayjs locale. | P0 | LocaleUpdate | Core functionality |
|
|
23
|
+
| UC-009 | Antd locale dynamic import | antdLocale: 'en_US' \| 'fr_FR' \| 'invalid_locale' | Dynamically imports antd-v5/locale/{antdLocale}. On error, falls back to en_US. Updates state.locale with imported module. | P1 | AntdLocaleImport | Critical for antd localization |
|
|
24
|
+
| UC-010 | Moment and dayjs locale sync | locale: 'en-US' \| 'fr-FR' \| 'de-DE' | Calls moment.locale(locale) and dayjs.locale(locale) when locale updates. Keeps both libraries in sync. | P1 | MomentDayjsSync | Ensures date library consistency |
|
|
25
|
+
| UC-011 | Locize locale mapping | supportedLocales: [{locale: 'en_US', locize_locale: 'en-US'}, {locale: 'fr-FR', locize_locale: 'fr-FR'}] | Maps user locale to locize_locale from supportedLocales. Calls getLocizeMessage with correct locize locale. | P1 | LocizeMapping | Critical for translation loading |
|
|
26
|
+
| UC-012 | Styling props | className: string \| undefined | Applies className to CapSpin wrapper. Does not break layout when undefined. | P2 | StylingProps | Simple styling test |
|
|
27
|
+
| UC-013 | API configuration props | supportedLocalesApi: string \| undefined, locizeApi: string \| undefined | Passes supportedLocalesApi to getSupportedLocales, locizeApi to getLocizeMessage. Handles undefined gracefully. | P2 | ApiConfigProps | Grouped API config props |
|
|
28
|
+
| UC-014 | Empty/missing user data | user: {} \| undefined, localStorage.user: '' \| invalid JSON | Handles empty user object, missing iso_lang, invalid localStorage JSON. Falls back to localStorage.locale or default. | P1 | EmptyUserData | Edge case handling |
|
|
29
|
+
| UC-015 | Empty/missing supported locales | supportedLocalesDetails: {} \| {supportedLocales: []} \| {supportedLocales: undefined} | Handles empty/missing supportedLocales array. Does not call getLocizeMessage until supportedLocales available. | P1 | EmptySupportedLocales | Edge case handling |
|
|
30
|
+
| UC-016 | React.Children.only constraint | children: single child \| multiple children \| no children | Wraps children with React.Children.only(). Should handle single child correctly. Multiple children may cause error (expected behavior). | P2 | ChildrenOnly | React API constraint |
|
|
31
|
+
| UC-017 | IntlProvider configuration | locale: 'en' \| 'fr' \| 'de', messages: {}, key: locale | IntlProvider receives correct locale, messages, and key prop based on language.locale. Defaults to 'en' if locale missing. | P1 | IntlProviderConfig | Critical for i18n |
|
|
32
|
+
| UC-018 | ConfigProvider locale | state.locale: Locale object | ConfigProvider receives state.locale (antd Locale object). Updates when antd locale module loads. Defaults to enUS initially. | P1 | ConfigProviderLocale | Critical for antd i18n |
|
|
33
|
+
| UC-019 | Component lifecycle | componentDidMount, componentDidUpdate | Calls getSupportedLocales on mount. Calls updateLocale in componentDidUpdate when user and supportedLocales become available. Prevents duplicate calls. | P1 | ComponentLifecycle | Core lifecycle behavior |
|
|
34
|
+
| UC-020 | Migration parity (v3→v6) | ConfigProvider from antd-v5, IntlProvider from react-intl | ConfigProvider and IntlProvider behavior matches v3 expectations. Locale loading, message passing, and error handling work identically. | P0 | MigrationParity | Critical for migration validation |
|
|
35
|
+
|
|
36
|
+
## Summary
|
|
37
|
+
- **Total Test Cases**: 20 (within medium complexity limit)
|
|
38
|
+
- **P0 (Blocking)**: 4 cases
|
|
39
|
+
- **P1 (High)**: 13 cases
|
|
40
|
+
- **P2 (Medium)**: 3 cases
|
|
41
|
+
|
|
42
|
+
## Grouping Rationale
|
|
43
|
+
- **UC-002**: Grouped all locale source scenarios (user.iso_lang, localStorage, defaults)
|
|
44
|
+
- **UC-003**: Grouped all locale format conversion scenarios (hyphen/underscore handling)
|
|
45
|
+
- **UC-004**: Grouped all spinner visibility conditions (loading states, login page check)
|
|
46
|
+
- **UC-006**: Grouped messages prop scenarios (language.messages vs messages prop)
|
|
47
|
+
- **UC-012**: Grouped styling props (className)
|
|
48
|
+
- **UC-013**: Grouped API configuration props (supportedLocalesApi, locizeApi)
|
|
49
|
+
|
|
50
|
+
## Notes
|
|
51
|
+
- Component uses Redux connect (HOC pattern) - test with mocked store/actions
|
|
52
|
+
- Requires localStorage mocking for locale/user data tests
|
|
53
|
+
- Dynamic imports require jest.mock for antd locale modules
|
|
54
|
+
- Login page detection uses window.location.pathname - mock for tests
|
|
55
|
+
- Component syncs moment and dayjs locales - verify both libraries update
|
|
56
|
+
- React.Children.only constraint means only single child supported
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# CapLanguageProvider
|
|
2
|
+
|
|
3
|
+
A wrapper component that provides internationalization (i18n) support for Capillary applications by integrating Ant Design's ConfigProvider, React Intl's IntlProvider, and Locize translation management.
|
|
4
|
+
|
|
5
|
+
## Migration from Ant Design v3 to v6
|
|
6
|
+
|
|
7
|
+
This component has been migrated from Ant Design v3 to v6 with the following changes:
|
|
8
|
+
|
|
9
|
+
### Breaking Changes
|
|
10
|
+
|
|
11
|
+
**None** - The component maintains full backward compatibility. No API changes were required.
|
|
12
|
+
|
|
13
|
+
### Code Improvements
|
|
14
|
+
|
|
15
|
+
1. **Removed PropTypes**: All PropTypes have been removed and replaced with TypeScript interfaces in `types.ts`
|
|
16
|
+
2. **Type Safety**: Full TypeScript support with exported types for all interfaces
|
|
17
|
+
3. **Code Organization**: All type definitions moved to dedicated `types.ts` file
|
|
18
|
+
4. **Documentation**: Added comprehensive JSDoc comments for better developer experience
|
|
19
|
+
|
|
20
|
+
### What Stayed the Same
|
|
21
|
+
|
|
22
|
+
- All props and their behavior
|
|
23
|
+
- Redux integration pattern (connect HOC)
|
|
24
|
+
- Locale loading logic (user.iso_lang → localStorage.locale → default)
|
|
25
|
+
- Locale format conversion (hyphen/underscore handling)
|
|
26
|
+
- Spinner visibility logic
|
|
27
|
+
- Login page skip behavior
|
|
28
|
+
- Moment and dayjs locale synchronization
|
|
29
|
+
- Antd locale dynamic import with fallback
|
|
30
|
+
|
|
31
|
+
### What Changed
|
|
32
|
+
|
|
33
|
+
- **Removed**: PropTypes imports and static propTypes assignments
|
|
34
|
+
- **Added**: TypeScript types in `types.ts`
|
|
35
|
+
- **Improved**: Type safety with exported interfaces
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { CapLanguageProvider } from '@capillarytech/blaze-ui';
|
|
41
|
+
|
|
42
|
+
function App() {
|
|
43
|
+
return (
|
|
44
|
+
<CapLanguageProvider>
|
|
45
|
+
<YourApp />
|
|
46
|
+
</CapLanguageProvider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Props
|
|
52
|
+
|
|
53
|
+
| Prop | Type | Default | Description |
|
|
54
|
+
|------|------|---------|-------------|
|
|
55
|
+
| `user` | `UserData` | `undefined` | User data object containing `iso_lang` property |
|
|
56
|
+
| `actions` | `Actions` | `undefined` | Redux action creators (injected via connect) |
|
|
57
|
+
| `children` | `React.ReactNode` | `undefined` | Child component to wrap |
|
|
58
|
+
| `language` | `LanguageState` | `undefined` | Language state from Redux store |
|
|
59
|
+
| `messages` | `Record<string, string>` | `undefined` | Translation messages object |
|
|
60
|
+
| `supportedLocalesDetails` | `SupportedLocalesDetails` | `undefined` | Supported locales details from Redux |
|
|
61
|
+
| `className` | `string` | `undefined` | CSS class name for the spinner wrapper |
|
|
62
|
+
| `spinnerVisible` | `boolean` | `true` | Whether to show loading spinner |
|
|
63
|
+
| `supportedLocalesApi` | `string` | `undefined` | API endpoint for fetching supported locales |
|
|
64
|
+
| `locizeApi` | `string` | `undefined` | API endpoint for fetching Locize translations |
|
|
65
|
+
|
|
66
|
+
## Locale Loading Priority
|
|
67
|
+
|
|
68
|
+
The component loads locales in the following priority order:
|
|
69
|
+
|
|
70
|
+
1. **User ISO Language** (`user.iso_lang`) - Highest priority
|
|
71
|
+
2. **LocalStorage Locale** (`localStorage.getItem('locale')`) - Fallback
|
|
72
|
+
3. **Default** (`en-US`) - Final fallback
|
|
73
|
+
|
|
74
|
+
## Locale Format Conversion
|
|
75
|
+
|
|
76
|
+
The component automatically converts locale formats for different libraries:
|
|
77
|
+
|
|
78
|
+
- **Antd**: Uses underscore format (e.g., `en_US`, `fr_FR`)
|
|
79
|
+
- **React Intl**: Uses 2-letter format (e.g., `en`, `fr`)
|
|
80
|
+
- **Locize**: Uses the mapped `locize_locale` from `supportedLocales`
|
|
81
|
+
|
|
82
|
+
### Examples
|
|
83
|
+
|
|
84
|
+
| Input | Antd Format | React Intl Format | Locize Format |
|
|
85
|
+
|-------|-------------|------------------|---------------|
|
|
86
|
+
| `en_US` | `en_US` | `en` | `en-US` (from supportedLocales) |
|
|
87
|
+
| `en-US` | `en_US` | `en` | `en-US` (from supportedLocales) |
|
|
88
|
+
| `fr-FR` | `fr_FR` | `fr` | `fr-FR` (from supportedLocales) |
|
|
89
|
+
|
|
90
|
+
## Spinner Visibility
|
|
91
|
+
|
|
92
|
+
The spinner is shown when:
|
|
93
|
+
- `spinnerVisible` is `true` (default)
|
|
94
|
+
- Not on login page (`/login` path)
|
|
95
|
+
- AND (`language.localeLoading === 'REQUEST'` OR `supportedLocalesDetails.fetchSupportedLocalesStatus === 'REQUEST'`)
|
|
96
|
+
|
|
97
|
+
## Login Page Behavior
|
|
98
|
+
|
|
99
|
+
When the component detects it's on a login page (`/login` path):
|
|
100
|
+
- `getSupportedLocales` is called with `isSkip: true`
|
|
101
|
+
- `getLocizeMessage` is called with `isSkip: true`
|
|
102
|
+
- Spinner never shows, regardless of loading state
|
|
103
|
+
|
|
104
|
+
## Redux Integration
|
|
105
|
+
|
|
106
|
+
The component uses Redux connect HOC to inject:
|
|
107
|
+
- `language` state from `makeSelectLanguage()` selector
|
|
108
|
+
- `supportedLocalesDetails` state from `makeSelectSupportedLocalesDetails()` selector
|
|
109
|
+
- `actions` from `bindActionCreators(action, dispatch)`
|
|
110
|
+
|
|
111
|
+
## Date Library Synchronization
|
|
112
|
+
|
|
113
|
+
The component synchronizes locale settings for both Moment.js and Day.js:
|
|
114
|
+
- `moment.locale(locale)` - Sets Moment.js locale
|
|
115
|
+
- `dayjs.locale(locale)` - Sets Day.js locale
|
|
116
|
+
|
|
117
|
+
Both libraries are kept in sync when the locale changes.
|
|
118
|
+
|
|
119
|
+
## TypeScript Support
|
|
120
|
+
|
|
121
|
+
All types are exported from the component:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import type {
|
|
125
|
+
CapLanguageProviderProps,
|
|
126
|
+
SupportedLocale,
|
|
127
|
+
UserData,
|
|
128
|
+
LanguageState,
|
|
129
|
+
Actions,
|
|
130
|
+
SupportedLocalesDetails,
|
|
131
|
+
} from '@capillarytech/blaze-ui';
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Examples
|
|
135
|
+
|
|
136
|
+
### Basic Usage
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { CapLanguageProvider } from '@capillarytech/blaze-ui';
|
|
140
|
+
|
|
141
|
+
function App() {
|
|
142
|
+
return (
|
|
143
|
+
<CapLanguageProvider>
|
|
144
|
+
<YourApp />
|
|
145
|
+
</CapLanguageProvider>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### With Custom Messages
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { CapLanguageProvider } from '@capillarytech/blaze-ui';
|
|
154
|
+
|
|
155
|
+
const messages = {
|
|
156
|
+
'app.title': 'My Application',
|
|
157
|
+
'app.welcome': 'Welcome!',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
function App() {
|
|
161
|
+
return (
|
|
162
|
+
<CapLanguageProvider messages={messages}>
|
|
163
|
+
<YourApp />
|
|
164
|
+
</CapLanguageProvider>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### With Custom Spinner ClassName
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import { CapLanguageProvider } from '@capillarytech/blaze-ui';
|
|
173
|
+
|
|
174
|
+
function App() {
|
|
175
|
+
return (
|
|
176
|
+
<CapLanguageProvider className="custom-spinner-wrapper">
|
|
177
|
+
<YourApp />
|
|
178
|
+
</CapLanguageProvider>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### With API Endpoints
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
import { CapLanguageProvider } from '@capillarytech/blaze-ui';
|
|
187
|
+
|
|
188
|
+
function App() {
|
|
189
|
+
return (
|
|
190
|
+
<CapLanguageProvider
|
|
191
|
+
supportedLocalesApi="/api/supported-locales"
|
|
192
|
+
locizeApi="/api/locize"
|
|
193
|
+
>
|
|
194
|
+
<YourApp />
|
|
195
|
+
</CapLanguageProvider>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Notes
|
|
201
|
+
|
|
202
|
+
- The component requires a single child element (uses `React.Children.only()`)
|
|
203
|
+
- Locale loading happens asynchronously via Redux actions
|
|
204
|
+
- Antd locale modules are dynamically imported with fallback to `en_US` on error
|
|
205
|
+
- The component logs locale information to console in development
|
|
206
|
+
- Moment.js and Day.js locales are synchronized automatically
|
|
@@ -1,70 +1,15 @@
|
|
|
1
|
-
import enUS from 'antd-v5/locale/en_US';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
1
|
import React from 'react';
|
|
4
|
-
type
|
|
5
|
-
interface SupportedLocale {
|
|
6
|
-
locale: string;
|
|
7
|
-
locize_locale?: string;
|
|
8
|
-
}
|
|
9
|
-
interface UserData {
|
|
10
|
-
iso_lang?: string;
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
}
|
|
13
|
-
interface LanguageState {
|
|
14
|
-
locale?: string;
|
|
15
|
-
localeLoading?: string;
|
|
16
|
-
messages?: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
interface Actions {
|
|
19
|
-
getSupportedLocales: (params: {
|
|
20
|
-
supportedLocalesApi?: string;
|
|
21
|
-
isSkip?: boolean;
|
|
22
|
-
}) => void;
|
|
23
|
-
getLocizeMessage: (params: {
|
|
24
|
-
locale: string;
|
|
25
|
-
isSkip?: boolean;
|
|
26
|
-
locizeApi?: string;
|
|
27
|
-
}) => void;
|
|
28
|
-
}
|
|
29
|
-
interface CapLanguageProviderProps {
|
|
30
|
-
user?: UserData;
|
|
31
|
-
actions?: Actions;
|
|
32
|
-
children?: React.ReactNode;
|
|
33
|
-
language?: LanguageState;
|
|
34
|
-
messages?: Record<string, string>;
|
|
35
|
-
supportedLocalesDetails?: {
|
|
36
|
-
supportedLocales?: SupportedLocale[];
|
|
37
|
-
fetchSupportedLocalesStatus?: string;
|
|
38
|
-
};
|
|
39
|
-
className?: string;
|
|
40
|
-
spinnerVisible?: boolean;
|
|
41
|
-
supportedLocalesApi?: string;
|
|
42
|
-
locizeApi?: string;
|
|
43
|
-
}
|
|
44
|
-
interface CapLanguageProviderState {
|
|
45
|
-
locale: Locale;
|
|
46
|
-
userLoaded: boolean;
|
|
47
|
-
supportedLocaleLoaded: boolean;
|
|
48
|
-
localeLoaded: boolean;
|
|
49
|
-
}
|
|
2
|
+
import type { Actions, CapLanguageProviderProps, CapLanguageProviderState, LanguageState, SupportedLocale, SupportedLocalesDetails, UserData } from './types';
|
|
50
3
|
export declare class CapLanguageProvider extends React.PureComponent<CapLanguageProviderProps, CapLanguageProviderState> {
|
|
51
|
-
static propTypes: {
|
|
52
|
-
user: PropTypes.Validator<UserData | undefined>;
|
|
53
|
-
actions: PropTypes.Validator<Actions | undefined>;
|
|
54
|
-
children: PropTypes.Validator<React.ReactNode>;
|
|
55
|
-
language: PropTypes.Validator<LanguageState | undefined>;
|
|
56
|
-
messages: PropTypes.Validator<Record<string, string> | undefined>;
|
|
57
|
-
supportedLocalesDetails: PropTypes.Validator<CapLanguageProviderProps["supportedLocalesDetails"]>;
|
|
58
|
-
className: PropTypes.Requireable<string>;
|
|
59
|
-
spinnerVisible: PropTypes.Requireable<boolean>;
|
|
60
|
-
};
|
|
61
4
|
constructor(props: CapLanguageProviderProps);
|
|
62
5
|
componentDidUpdate(): void;
|
|
63
6
|
checkLoginPage(): boolean;
|
|
7
|
+
loadDefaultLocale(): void;
|
|
64
8
|
componentDidMount(): void;
|
|
65
9
|
updateLocale(): void;
|
|
66
|
-
render():
|
|
10
|
+
render(): React.ReactElement;
|
|
67
11
|
}
|
|
68
12
|
declare const _default: React.ComponentType<Partial<CapLanguageProviderProps>>;
|
|
69
13
|
export default _default;
|
|
14
|
+
export type { CapLanguageProviderProps, SupportedLocale, UserData, LanguageState, Actions, SupportedLocalesDetails, };
|
|
70
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../components/CapLanguageProvider/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../components/CapLanguageProvider/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,OAAO,KAAK,EACV,OAAO,EACP,wBAAwB,EACxB,wBAAwB,EAGxB,aAAa,EAEb,eAAe,EACf,uBAAuB,EACvB,QAAQ,EACT,MAAM,SAAS,CAAC;AA0BjB,qBAAa,mBAAoB,SAAQ,KAAK,CAAC,aAAa,CAC1D,wBAAwB,EACxB,wBAAwB,CACzB;gBACa,KAAK,EAAE,wBAAwB;IAU3C,kBAAkB;IAWlB,cAAc,IAAI,OAAO;IAIzB,iBAAiB,IAAI,IAAI;IAoBzB,iBAAiB,IAAI,IAAI;IAOzB,YAAY,IAAI,IAAI;IAwEpB,MAAM,IAAI,KAAK,CAAC,YAAY;CAgC7B;wBAe2D,KAAK,CAAC,aAAa,CAC7E,OAAO,CAAC,wBAAwB,CAAC,CAClC;AAFD,wBAEE;AAEF,YAAY,EACV,wBAAwB,EACxB,eAAe,EACf,QAAQ,EACR,aAAa,EACb,OAAO,EACP,uBAAuB,GACxB,CAAC"}
|
|
@@ -1335,14 +1335,6 @@ module.exports = require("dayjs/plugin/duration");
|
|
|
1335
1335
|
|
|
1336
1336
|
/***/ }),
|
|
1337
1337
|
|
|
1338
|
-
/***/ 43363:
|
|
1339
|
-
/***/ ((module) => {
|
|
1340
|
-
|
|
1341
|
-
"use strict";
|
|
1342
|
-
module.exports = require("prop-types");
|
|
1343
|
-
|
|
1344
|
-
/***/ }),
|
|
1345
|
-
|
|
1346
1338
|
/***/ 43403:
|
|
1347
1339
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1348
1340
|
|
|
@@ -2117,9 +2109,7 @@ const languageProviderReducer = function (state, action) {
|
|
|
2117
2109
|
case types.GET_LOCIZE_MESSAGE_REQUEST:
|
|
2118
2110
|
return state.set('localeLoading', types.REQUEST);
|
|
2119
2111
|
case types.GET_LOCIZE_MESSAGE_SUCCESS:
|
|
2120
|
-
return state.set('localeLoading', types.COMPLETE)
|
|
2121
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2122
|
-
.set('messages', (0, _immutable.fromJS)(action.data || {})).set('locale', action.locale || types.DEFAULT_LOCALE);
|
|
2112
|
+
return state.set('localeLoading', types.COMPLETE).set('messages', (0, _immutable.fromJS)(action.data || {})).set('locale', action.locale || types.DEFAULT_LOCALE);
|
|
2123
2113
|
case types.GET_LOCIZE_MESSAGE_FAILURE:
|
|
2124
2114
|
return state.set('localeLoading', types.COMPLETE).set('messages', (0, _immutable.fromJS)({}));
|
|
2125
2115
|
case types.GET_LOCIZE_MESSAGE_SKIP:
|
|
@@ -2127,9 +2117,7 @@ const languageProviderReducer = function (state, action) {
|
|
|
2127
2117
|
case types.GET_SUPPORTED_LOCALES_REQUEST:
|
|
2128
2118
|
return state.set('fetchSupportedLocalesStatus', types.REQUEST).set('supportedLocales', (0, _immutable.fromJS)([]));
|
|
2129
2119
|
case types.GET_SUPPORTED_LOCALES_SUCCESS:
|
|
2130
|
-
return state.set('fetchSupportedLocalesStatus', types.SUCCESS)
|
|
2131
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2132
|
-
.set('supportedLocales', (0, _immutable.fromJS)(action.data || []));
|
|
2120
|
+
return state.set('fetchSupportedLocalesStatus', types.SUCCESS).set('supportedLocales', (0, _immutable.fromJS)(action.data || []));
|
|
2133
2121
|
case types.GET_SUPPORTED_LOCALES_FAILURE:
|
|
2134
2122
|
return state.set('fetchSupportedLocalesStatus', types.FAILURE).set('supportedLocales', (0, _immutable.fromJS)([]));
|
|
2135
2123
|
default:
|
|
@@ -2763,7 +2751,6 @@ var _antdV = __webpack_require__(64273);
|
|
|
2763
2751
|
var _en_US = _interopRequireDefault(__webpack_require__(75543));
|
|
2764
2752
|
var _isEmpty = _interopRequireDefault(__webpack_require__(62193));
|
|
2765
2753
|
var _moment = _interopRequireDefault(__webpack_require__(51146));
|
|
2766
|
-
var _propTypes = _interopRequireDefault(__webpack_require__(43363));
|
|
2767
2754
|
var _react = _interopRequireDefault(__webpack_require__(9206));
|
|
2768
2755
|
var _reactIntl = __webpack_require__(46407);
|
|
2769
2756
|
var _reactRedux = __webpack_require__(31286);
|
|
@@ -2781,11 +2768,18 @@ const {
|
|
|
2781
2768
|
makeSelectLanguage,
|
|
2782
2769
|
makeSelectSupportedLocalesDetails
|
|
2783
2770
|
} = selectors;
|
|
2771
|
+
|
|
2784
2772
|
/**
|
|
2785
|
-
*
|
|
2786
|
-
*
|
|
2787
|
-
*
|
|
2788
|
-
* @
|
|
2773
|
+
* Converts locale string to appropriate formats for different libraries.
|
|
2774
|
+
*
|
|
2775
|
+
* @param lang - Locale string from user.iso_lang or localStorage (e.g., 'en_US', 'en-US', 'fr-FR')
|
|
2776
|
+
* @param supportedLocales - Array of supported locale configurations
|
|
2777
|
+
* @returns Object containing formatted locales for antd, react-intl, and locize
|
|
2778
|
+
*
|
|
2779
|
+
* @remarks
|
|
2780
|
+
* - Antd uses underscore format (e.g., 'en_US', 'fr_FR')
|
|
2781
|
+
* - React Intl uses 2-letter format (e.g., 'en', 'fr')
|
|
2782
|
+
* - Locize uses the mapped locize_locale from supportedLocales
|
|
2789
2783
|
*/
|
|
2790
2784
|
function getAllLocales(_ref) {
|
|
2791
2785
|
var _lang$split, _supportedLocales$fin;
|
|
@@ -2828,6 +2822,27 @@ class CapLanguageProvider extends _react.default.PureComponent {
|
|
|
2828
2822
|
checkLoginPage() {
|
|
2829
2823
|
return window.location.pathname.indexOf('/login') !== -1;
|
|
2830
2824
|
}
|
|
2825
|
+
loadDefaultLocale() {
|
|
2826
|
+
(specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(__webpack_require__(94639)(s))))("antd-v5/locale/en_US").then(module => {
|
|
2827
|
+
if (module != null && module.default) {
|
|
2828
|
+
this.setState({
|
|
2829
|
+
locale: module.default
|
|
2830
|
+
});
|
|
2831
|
+
} else {
|
|
2832
|
+
console.error('Failed to load default antd locale (en_US). Using static import fallback.');
|
|
2833
|
+
// Fallback to the statically imported enUS
|
|
2834
|
+
this.setState({
|
|
2835
|
+
locale: _en_US.default
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2838
|
+
}).catch(error => {
|
|
2839
|
+
console.error('Failed to load default antd locale (en_US):', error);
|
|
2840
|
+
// Fallback to the statically imported enUS
|
|
2841
|
+
this.setState({
|
|
2842
|
+
locale: _en_US.default
|
|
2843
|
+
});
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2831
2846
|
componentDidMount() {
|
|
2832
2847
|
var _this$props$actions;
|
|
2833
2848
|
(_this$props$actions = this.props.actions) == null || _this$props$actions.getSupportedLocales({
|
|
@@ -2837,9 +2852,10 @@ class CapLanguageProvider extends _react.default.PureComponent {
|
|
|
2837
2852
|
}
|
|
2838
2853
|
updateLocale() {
|
|
2839
2854
|
var _this$props$actions2;
|
|
2855
|
+
const supportedLocalesDetails = this.props.supportedLocalesDetails;
|
|
2840
2856
|
const {
|
|
2841
2857
|
supportedLocales = []
|
|
2842
|
-
} =
|
|
2858
|
+
} = supportedLocalesDetails || {};
|
|
2843
2859
|
/**
|
|
2844
2860
|
* Admin user locale's first locale. Otherwise if org_locale exists -> first org_locale else default_cluster_locale or (en_US);
|
|
2845
2861
|
*/
|
|
@@ -2893,16 +2909,17 @@ class CapLanguageProvider extends _react.default.PureComponent {
|
|
|
2893
2909
|
|
|
2894
2910
|
/**In case of any errors, use default as fallback. */
|
|
2895
2911
|
(specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(__webpack_require__(94639)(s))))("antd-v5/locale/" + antdLocale).then(module => {
|
|
2896
|
-
|
|
2897
|
-
locale: module.default
|
|
2898
|
-
});
|
|
2899
|
-
}).catch(() => {
|
|
2900
|
-
console.warn("antd locale module does not exist for " + antdLocale + ". Using en_US instead");
|
|
2901
|
-
(specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(__webpack_require__(94639)(s))))("antd-v5/locale/en_US").then(module => {
|
|
2912
|
+
if (module != null && module.default) {
|
|
2902
2913
|
this.setState({
|
|
2903
2914
|
locale: module.default
|
|
2904
2915
|
});
|
|
2905
|
-
}
|
|
2916
|
+
} else {
|
|
2917
|
+
console.warn("antd locale module for " + antdLocale + " does not have a default export. Using en_US instead");
|
|
2918
|
+
this.loadDefaultLocale();
|
|
2919
|
+
}
|
|
2920
|
+
}).catch(error => {
|
|
2921
|
+
console.warn("antd locale module does not exist for " + antdLocale + ". Using en_US instead", error);
|
|
2922
|
+
this.loadDefaultLocale();
|
|
2906
2923
|
});
|
|
2907
2924
|
}
|
|
2908
2925
|
render() {
|
|
@@ -2910,46 +2927,36 @@ class CapLanguageProvider extends _react.default.PureComponent {
|
|
|
2910
2927
|
language,
|
|
2911
2928
|
messages,
|
|
2912
2929
|
supportedLocalesDetails = {},
|
|
2913
|
-
spinnerVisible = true
|
|
2930
|
+
spinnerVisible = true,
|
|
2931
|
+
className
|
|
2914
2932
|
} = this.props;
|
|
2915
|
-
const
|
|
2933
|
+
const languageState = language;
|
|
2934
|
+
const supportedLocalesDetailsState = supportedLocalesDetails;
|
|
2935
|
+
const translatedMessages = (languageState == null ? void 0 : languageState.messages) || messages;
|
|
2916
2936
|
const isLoginPage = this.checkLoginPage();
|
|
2917
|
-
const showSpinner = spinnerVisible && !isLoginPage && ((
|
|
2937
|
+
const showSpinner = spinnerVisible && !isLoginPage && ((languageState == null ? void 0 : languageState.localeLoading) === types.REQUEST || (supportedLocalesDetailsState == null ? void 0 : supportedLocalesDetailsState.fetchSupportedLocalesStatus) === types.REQUEST);
|
|
2918
2938
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_antdV.ConfigProvider, {
|
|
2919
2939
|
locale: this.state.locale,
|
|
2920
2940
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.IntlProvider, {
|
|
2921
|
-
locale: (
|
|
2941
|
+
locale: (languageState == null ? void 0 : languageState.locale) || 'en',
|
|
2922
2942
|
messages: translatedMessages,
|
|
2923
2943
|
onError: () => {},
|
|
2924
2944
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CapSpin.default, {
|
|
2925
|
-
className:
|
|
2945
|
+
className: className,
|
|
2926
2946
|
spinning: showSpinner,
|
|
2927
2947
|
children: _react.default.Children.only(this.props.children)
|
|
2928
2948
|
})
|
|
2929
|
-
}, (
|
|
2949
|
+
}, (languageState == null ? void 0 : languageState.locale) || 'en')
|
|
2930
2950
|
});
|
|
2931
2951
|
}
|
|
2932
2952
|
}
|
|
2933
2953
|
exports.CapLanguageProvider = CapLanguageProvider;
|
|
2934
|
-
CapLanguageProvider.propTypes = {
|
|
2935
|
-
user: _propTypes.default.object,
|
|
2936
|
-
actions: _propTypes.default.object,
|
|
2937
|
-
children: _propTypes.default.node,
|
|
2938
|
-
language: _propTypes.default.object,
|
|
2939
|
-
messages: _propTypes.default.object,
|
|
2940
|
-
supportedLocalesDetails: _propTypes.default.object,
|
|
2941
|
-
className: _propTypes.default.string,
|
|
2942
|
-
spinnerVisible: _propTypes.default.bool
|
|
2943
|
-
};
|
|
2944
2954
|
const mapStateToProps = (0, _reselect.createStructuredSelector)({
|
|
2945
2955
|
language: makeSelectLanguage(),
|
|
2946
2956
|
supportedLocalesDetails: makeSelectSupportedLocalesDetails()
|
|
2947
2957
|
});
|
|
2948
|
-
|
|
2949
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2950
2958
|
function mapDispatchToProps(dispatch) {
|
|
2951
2959
|
return {
|
|
2952
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2953
2960
|
actions: (0, _redux.bindActionCreators)(action, dispatch)
|
|
2954
2961
|
};
|
|
2955
2962
|
}
|