@asteby/metacore-i18n 2.0.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/LICENSE +201 -0
- package/README.md +78 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +48 -0
- package/dist/config.js.map +1 -0
- package/dist/direction-provider.d.ts +44 -0
- package/dist/direction-provider.d.ts.map +1 -0
- package/dist/direction-provider.js +47 -0
- package/dist/direction-provider.js.map +1 -0
- package/dist/hooks.d.ts +27 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +40 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/language-switcher.d.ts +37 -0
- package/dist/language-switcher.d.ts.map +1 -0
- package/dist/language-switcher.js +29 -0
- package/dist/language-switcher.js.map +1 -0
- package/dist/locales/en.json +174 -0
- package/dist/locales/es.json +174 -0
- package/dist/locales/index.d.ts +365 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +14 -0
- package/dist/locales/index.js.map +1 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Asteby, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @asteby/metacore-i18n
|
|
2
|
+
|
|
3
|
+
i18next factory + base ES/EN bundles + layout-agnostic language switcher and
|
|
4
|
+
direction (RTL) provider for Metacore apps.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @asteby/metacore-i18n i18next react-i18next
|
|
10
|
+
# Optional — needed only if you render `<LanguageSwitcher />`:
|
|
11
|
+
pnpm add @asteby/metacore-ui
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// src/i18n.ts
|
|
18
|
+
import { createI18n, baseResources } from '@asteby/metacore-i18n'
|
|
19
|
+
import appEn from './locales/en.json'
|
|
20
|
+
import appEs from './locales/es.json'
|
|
21
|
+
|
|
22
|
+
export const i18n = createI18n({
|
|
23
|
+
resources: {
|
|
24
|
+
en: { translation: { ...baseResources.en.translation, ...appEn } },
|
|
25
|
+
es: { translation: { ...baseResources.es.translation, ...appEs } },
|
|
26
|
+
},
|
|
27
|
+
fallback: 'es',
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// App.tsx
|
|
33
|
+
import { I18nextProvider } from 'react-i18next'
|
|
34
|
+
import { DirectionProvider, LanguageSwitcher } from '@asteby/metacore-i18n'
|
|
35
|
+
import { i18n } from './i18n'
|
|
36
|
+
|
|
37
|
+
export function App() {
|
|
38
|
+
return (
|
|
39
|
+
<I18nextProvider i18n={i18n}>
|
|
40
|
+
<DirectionProvider language={i18n.language}>
|
|
41
|
+
<header>
|
|
42
|
+
<LanguageSwitcher
|
|
43
|
+
languages={[
|
|
44
|
+
{ code: 'en', label: 'English', flag: '🇺🇸' },
|
|
45
|
+
{ code: 'es', label: 'Español', flag: '🇪🇸' },
|
|
46
|
+
]}
|
|
47
|
+
/>
|
|
48
|
+
</header>
|
|
49
|
+
{/* ...app... */}
|
|
50
|
+
</DirectionProvider>
|
|
51
|
+
</I18nextProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Entry points
|
|
57
|
+
|
|
58
|
+
- `@asteby/metacore-i18n` — re-exports everything below.
|
|
59
|
+
- `@asteby/metacore-i18n/config` — `createI18n` factory.
|
|
60
|
+
- `@asteby/metacore-i18n/language-switcher` — `<LanguageSwitcher />`.
|
|
61
|
+
- `@asteby/metacore-i18n/direction-provider` — `<DirectionProvider />`, `useDirection`.
|
|
62
|
+
- `@asteby/metacore-i18n/hooks` — `useLocale`, `directionFor`, `DEFAULT_RTL_LANGUAGES`.
|
|
63
|
+
- `@asteby/metacore-i18n/locales/en`, `.../es` — raw JSON bundles.
|
|
64
|
+
|
|
65
|
+
## Base namespaces
|
|
66
|
+
|
|
67
|
+
The shipped ES/EN bundles are intentionally generic and cover:
|
|
68
|
+
|
|
69
|
+
- `auth.signIn`, `auth.signUp`
|
|
70
|
+
- `common.*` (save, cancel, loading, search, theme…)
|
|
71
|
+
- `errors.*` (validation, network, required…)
|
|
72
|
+
- `datatable.*` (pagination, bulk delete, rows per page…)
|
|
73
|
+
- `settings.profile`, `settings.appearance`, `settings.notifications`
|
|
74
|
+
- `coming_soon.*`
|
|
75
|
+
- `language.*`
|
|
76
|
+
|
|
77
|
+
App-specific namespaces (dashboards, pipelines, products, marketplace, etc.)
|
|
78
|
+
live in each app and should be deep-merged on top of `baseResources`.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type i18n as I18nInstance, type InitOptions, type Resource } from 'i18next';
|
|
2
|
+
import { type DetectorOptions } from 'i18next-browser-languagedetector';
|
|
3
|
+
export type CreateI18nOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Resource bundles keyed by language code (e.g. `{ en: { translation: {...} } }`).
|
|
6
|
+
* Use `baseResources` from `@asteby/metacore-i18n/locales` as a starting point and
|
|
7
|
+
* deep-merge any app-specific namespaces on top.
|
|
8
|
+
*/
|
|
9
|
+
resources: Resource;
|
|
10
|
+
/**
|
|
11
|
+
* Language to fall back to when a key is missing. Defaults to `'en'`.
|
|
12
|
+
*/
|
|
13
|
+
fallback?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Default language to initialize with. When omitted, i18next will rely on
|
|
16
|
+
* the language detector (if `detection` is enabled).
|
|
17
|
+
*/
|
|
18
|
+
lng?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Namespaces available on the instance. Defaults to i18next's single
|
|
21
|
+
* `translation` namespace.
|
|
22
|
+
*/
|
|
23
|
+
namespaces?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Default namespace used when no explicit `ns` is supplied. Defaults to
|
|
26
|
+
* `'translation'`.
|
|
27
|
+
*/
|
|
28
|
+
defaultNS?: string;
|
|
29
|
+
/**
|
|
30
|
+
* If provided, enables `i18next-browser-languagedetector` with the given
|
|
31
|
+
* configuration. Pass `false` (default) to disable automatic detection
|
|
32
|
+
* entirely — useful for SSR or Node environments.
|
|
33
|
+
*/
|
|
34
|
+
detection?: DetectorOptions | false;
|
|
35
|
+
/**
|
|
36
|
+
* Enable debug logging. Defaults to `false`.
|
|
37
|
+
*/
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* When `true` (default in browser), syncs `<html lang>` with the active
|
|
41
|
+
* language on every change. Set to `false` for non-browser environments.
|
|
42
|
+
*/
|
|
43
|
+
syncHtmlLang?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Escape hatch for any extra i18next init option not covered above. Merged
|
|
46
|
+
* last so it can override the generated config if absolutely necessary.
|
|
47
|
+
*/
|
|
48
|
+
extra?: Partial<InitOptions>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Factory that builds and initializes a brand-new i18next instance.
|
|
52
|
+
*
|
|
53
|
+
* This is intentionally NOT a singleton — each call returns a fresh instance
|
|
54
|
+
* so multiple apps / tests can coexist without stepping on each other.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createI18n(options: CreateI18nOptions): I18nInstance;
|
|
57
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,IAAI,IAAI,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC7F,OAAyB,EACvB,KAAK,eAAe,EACrB,MAAM,kCAAkC,CAAA;AAGzC,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,SAAS,EAAE,QAAQ,CAAA;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,eAAe,GAAG,KAAK,CAAA;IACnC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;CAC7B,CAAA;AAOD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAiDnE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import i18next, {} from 'i18next';
|
|
2
|
+
import LanguageDetector, {} from 'i18next-browser-languagedetector';
|
|
3
|
+
import { initReactI18next } from 'react-i18next';
|
|
4
|
+
const DEFAULT_DETECTION = {
|
|
5
|
+
order: ['localStorage', 'navigator', 'htmlTag'],
|
|
6
|
+
caches: ['localStorage'],
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Factory that builds and initializes a brand-new i18next instance.
|
|
10
|
+
*
|
|
11
|
+
* This is intentionally NOT a singleton — each call returns a fresh instance
|
|
12
|
+
* so multiple apps / tests can coexist without stepping on each other.
|
|
13
|
+
*/
|
|
14
|
+
export function createI18n(options) {
|
|
15
|
+
const { resources, fallback = 'en', lng, namespaces, defaultNS = 'translation', detection, debug = false, syncHtmlLang = typeof document !== 'undefined', extra, } = options;
|
|
16
|
+
const instance = i18next.createInstance();
|
|
17
|
+
const useDetection = detection !== false;
|
|
18
|
+
if (useDetection) {
|
|
19
|
+
instance.use(LanguageDetector);
|
|
20
|
+
}
|
|
21
|
+
instance.use(initReactI18next);
|
|
22
|
+
const initOptions = {
|
|
23
|
+
resources,
|
|
24
|
+
fallbackLng: fallback,
|
|
25
|
+
debug,
|
|
26
|
+
interpolation: {
|
|
27
|
+
escapeValue: false,
|
|
28
|
+
},
|
|
29
|
+
...(lng ? { lng } : {}),
|
|
30
|
+
...(namespaces ? { ns: namespaces } : {}),
|
|
31
|
+
defaultNS,
|
|
32
|
+
...(useDetection
|
|
33
|
+
? { detection: { ...DEFAULT_DETECTION, ...(detection ?? {}) } }
|
|
34
|
+
: {}),
|
|
35
|
+
...extra,
|
|
36
|
+
};
|
|
37
|
+
// Kick off init. Callers can `await instance.init(...)` themselves if they
|
|
38
|
+
// need the promise; we follow the same fire-and-forget pattern as the ops
|
|
39
|
+
// reference implementation so `useTranslation` just works.
|
|
40
|
+
void instance.init(initOptions);
|
|
41
|
+
if (syncHtmlLang && typeof document !== 'undefined') {
|
|
42
|
+
instance.on('languageChanged', (lang) => {
|
|
43
|
+
document.documentElement.lang = lang;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return instance;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAA8D,MAAM,SAAS,CAAA;AAC7F,OAAO,gBAAgB,EAAE,EAExB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAkDhD,MAAM,iBAAiB,GAAoB;IACzC,KAAK,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,SAAS,CAAC;IAC/C,MAAM,EAAE,CAAC,cAAc,CAAC;CACzB,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,MAAM,EACJ,SAAS,EACT,QAAQ,GAAG,IAAI,EACf,GAAG,EACH,UAAU,EACV,SAAS,GAAG,aAAa,EACzB,SAAS,EACT,KAAK,GAAG,KAAK,EACb,YAAY,GAAG,OAAO,QAAQ,KAAK,WAAW,EAC9C,KAAK,GACN,GAAG,OAAO,CAAA;IAEX,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAA;IAEzC,MAAM,YAAY,GAAG,SAAS,KAAK,KAAK,CAAA;IACxC,IAAI,YAAY,EAAE,CAAC;QACjB,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IAChC,CAAC;IACD,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IAE9B,MAAM,WAAW,GAAgB;QAC/B,SAAS;QACT,WAAW,EAAE,QAAQ;QACrB,KAAK;QACL,aAAa,EAAE;YACb,WAAW,EAAE,KAAK;SACnB;QACD,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,SAAS;QACT,GAAG,CAAC,YAAY;YACd,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,iBAAiB,EAAE,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,EAAE;YAC/D,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,KAAK;KACT,CAAA;IAED,2EAA2E;IAC3E,0EAA0E;IAC1E,2DAA2D;IAC3D,KAAK,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAE/B,IAAI,YAAY,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpD,QAAQ,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE;YACtC,QAAQ,CAAC,eAAe,CAAC,IAAI,GAAG,IAAI,CAAA;QACtC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type Direction } from './hooks';
|
|
3
|
+
export type { Direction } from './hooks';
|
|
4
|
+
export type DirectionContextValue = {
|
|
5
|
+
defaultDir: Direction;
|
|
6
|
+
dir: Direction;
|
|
7
|
+
setDir: (dir: Direction) => void;
|
|
8
|
+
resetDir: () => void;
|
|
9
|
+
};
|
|
10
|
+
export type DirectionProviderProps = {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Initial direction to seed the provider with. Defaults to `'ltr'`.
|
|
14
|
+
* Overridden by `storage` if a stored value exists.
|
|
15
|
+
*/
|
|
16
|
+
defaultDir?: Direction;
|
|
17
|
+
/**
|
|
18
|
+
* Optional pluggable storage (e.g. `localStorage`-backed wrapper or a
|
|
19
|
+
* cookie helper). Leave undefined to disable persistence.
|
|
20
|
+
*/
|
|
21
|
+
storage?: {
|
|
22
|
+
get: () => Direction | null | undefined;
|
|
23
|
+
set: (dir: Direction) => void;
|
|
24
|
+
remove: () => void;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* If provided, direction auto-syncs to this language code using the
|
|
28
|
+
* `rtlLanguages` list. Useful when wired to i18next's current language.
|
|
29
|
+
*/
|
|
30
|
+
language?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Override the list of languages considered RTL. Defaults to
|
|
33
|
+
* `DEFAULT_RTL_LANGUAGES` from `./hooks`.
|
|
34
|
+
*/
|
|
35
|
+
rtlLanguages?: readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* When `true` (default in browser), syncs `<html dir>` with the active
|
|
38
|
+
* direction on every change.
|
|
39
|
+
*/
|
|
40
|
+
syncHtmlDir?: boolean;
|
|
41
|
+
};
|
|
42
|
+
export declare function DirectionProvider({ children, defaultDir, storage, language, rtlLanguages, syncHtmlDir, }: DirectionProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare function useDirection(): DirectionContextValue;
|
|
44
|
+
//# sourceMappingURL=direction-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction-provider.d.ts","sourceRoot":"","sources":["../src/direction-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AACd,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;AAE7E,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,SAAS,CAAA;IACrB,GAAG,EAAE,SAAS,CAAA;IACd,MAAM,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAA;IAChC,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB,CAAA;AAID,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,SAAS,CAAA;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE;QACR,GAAG,EAAE,MAAM,SAAS,GAAG,IAAI,GAAG,SAAS,CAAA;QACvC,GAAG,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAA;QAC7B,MAAM,EAAE,MAAM,IAAI,CAAA;KACnB,CAAA;IACD;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAChC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,UAAkB,EAClB,OAAO,EACP,QAAQ,EACR,YAAoC,EACpC,WAA6C,GAC9C,EAAE,sBAAsB,2CA6CxB;AAED,wBAAgB,YAAY,IAAI,qBAAqB,CAMpD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
3
|
+
import { DEFAULT_RTL_LANGUAGES, directionFor } from './hooks';
|
|
4
|
+
const DirectionContext = createContext(null);
|
|
5
|
+
export function DirectionProvider({ children, defaultDir = 'ltr', storage, language, rtlLanguages = DEFAULT_RTL_LANGUAGES, syncHtmlDir = typeof document !== 'undefined', }) {
|
|
6
|
+
const [dir, _setDir] = useState(() => {
|
|
7
|
+
const stored = storage?.get();
|
|
8
|
+
if (stored === 'ltr' || stored === 'rtl')
|
|
9
|
+
return stored;
|
|
10
|
+
if (language)
|
|
11
|
+
return directionFor(language, rtlLanguages);
|
|
12
|
+
return defaultDir;
|
|
13
|
+
});
|
|
14
|
+
// Keep in sync with the active language when caller wires one in.
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!language)
|
|
17
|
+
return;
|
|
18
|
+
// Respect an explicit stored preference over language-derived direction.
|
|
19
|
+
if (storage?.get())
|
|
20
|
+
return;
|
|
21
|
+
const next = directionFor(language, rtlLanguages);
|
|
22
|
+
_setDir((prev) => (prev === next ? prev : next));
|
|
23
|
+
}, [language, rtlLanguages, storage]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!syncHtmlDir || typeof document === 'undefined')
|
|
26
|
+
return;
|
|
27
|
+
document.documentElement.setAttribute('dir', dir);
|
|
28
|
+
}, [dir, syncHtmlDir]);
|
|
29
|
+
const setDir = useCallback((next) => {
|
|
30
|
+
_setDir(next);
|
|
31
|
+
storage?.set(next);
|
|
32
|
+
}, [storage]);
|
|
33
|
+
const resetDir = useCallback(() => {
|
|
34
|
+
_setDir(defaultDir);
|
|
35
|
+
storage?.remove();
|
|
36
|
+
}, [defaultDir, storage]);
|
|
37
|
+
const value = useMemo(() => ({ defaultDir, dir, setDir, resetDir }), [defaultDir, dir, setDir, resetDir]);
|
|
38
|
+
return (_jsx(DirectionContext.Provider, { value: value, children: children }));
|
|
39
|
+
}
|
|
40
|
+
export function useDirection() {
|
|
41
|
+
const context = useContext(DirectionContext);
|
|
42
|
+
if (!context) {
|
|
43
|
+
throw new Error('useDirection must be used within a DirectionProvider');
|
|
44
|
+
}
|
|
45
|
+
return context;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=direction-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction-provider.js","sourceRoot":"","sources":["../src/direction-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,GAET,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAW7E,MAAM,gBAAgB,GAAG,aAAa,CAA+B,IAAI,CAAC,CAAA;AAmC1E,MAAM,UAAU,iBAAiB,CAAC,EAChC,QAAQ,EACR,UAAU,GAAG,KAAK,EAClB,OAAO,EACP,QAAQ,EACR,YAAY,GAAG,qBAAqB,EACpC,WAAW,GAAG,OAAO,QAAQ,KAAK,WAAW,GACtB;IACvB,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAY,GAAG,EAAE;QAC9C,MAAM,MAAM,GAAG,OAAO,EAAE,GAAG,EAAE,CAAA;QAC7B,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,KAAK;YAAE,OAAO,MAAM,CAAA;QACvD,IAAI,QAAQ;YAAE,OAAO,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QACzD,OAAO,UAAU,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,kEAAkE;IAClE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ;YAAE,OAAM;QACrB,yEAAyE;QACzE,IAAI,OAAO,EAAE,GAAG,EAAE;YAAE,OAAM;QAC1B,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QACjD,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IAClD,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;IAErC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,OAAM;QAC3D,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACnD,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAA;IAEtB,MAAM,MAAM,GAAG,WAAW,CACxB,CAAC,IAAe,EAAE,EAAE;QAClB,OAAO,CAAC,IAAI,CAAC,CAAA;QACb,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAA;IAED,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;QAChC,OAAO,CAAC,UAAU,CAAC,CAAA;QACnB,OAAO,EAAE,MAAM,EAAE,CAAA;IACnB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;IAEzB,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAC7C,CAAC,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CACpC,CAAA;IAED,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACpC,QAAQ,GACiB,CAC7B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type UseLocaleResult = {
|
|
2
|
+
/** Current active language code (e.g. `"en"`, `"es"`). */
|
|
3
|
+
locale: string;
|
|
4
|
+
/** Resolved languages, including fallbacks. */
|
|
5
|
+
languages: readonly string[];
|
|
6
|
+
/** Change the active language on the underlying i18next instance. */
|
|
7
|
+
setLocale: (lang: string) => Promise<unknown>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Lightweight wrapper around `useTranslation` that exposes only the
|
|
11
|
+
* language-management bits — handy for building language switchers or
|
|
12
|
+
* reading the active locale in components that don't need `t()`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useLocale(): UseLocaleResult;
|
|
15
|
+
export type Direction = 'ltr' | 'rtl';
|
|
16
|
+
/**
|
|
17
|
+
* List of language codes that default to right-to-left script.
|
|
18
|
+
* Extend at the app level via the `DirectionProvider`'s `rtlLanguages` prop
|
|
19
|
+
* if you ship additional RTL locales.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_RTL_LANGUAGES: readonly string[];
|
|
22
|
+
/**
|
|
23
|
+
* Compute the expected writing direction for a language code, honoring an
|
|
24
|
+
* optional override list.
|
|
25
|
+
*/
|
|
26
|
+
export declare function directionFor(lang: string, rtlLanguages?: readonly string[]): Direction;
|
|
27
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC5B,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAA;IACd,+CAA+C;IAC/C,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,qEAAqE;IACrE,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9C,CAAA;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,eAAe,CAa3C;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,CAAA;AAErC;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EASlD,CAAA;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,YAAY,GAAE,SAAS,MAAM,EAA0B,GACtD,SAAS,CAGX"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight wrapper around `useTranslation` that exposes only the
|
|
5
|
+
* language-management bits — handy for building language switchers or
|
|
6
|
+
* reading the active locale in components that don't need `t()`.
|
|
7
|
+
*/
|
|
8
|
+
export function useLocale() {
|
|
9
|
+
const { i18n } = useTranslation();
|
|
10
|
+
const setLocale = useCallback((lang) => i18n.changeLanguage(lang), [i18n]);
|
|
11
|
+
return {
|
|
12
|
+
locale: i18n.language,
|
|
13
|
+
languages: i18n.languages ?? [i18n.language],
|
|
14
|
+
setLocale,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List of language codes that default to right-to-left script.
|
|
19
|
+
* Extend at the app level via the `DirectionProvider`'s `rtlLanguages` prop
|
|
20
|
+
* if you ship additional RTL locales.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_RTL_LANGUAGES = [
|
|
23
|
+
'ar',
|
|
24
|
+
'fa',
|
|
25
|
+
'he',
|
|
26
|
+
'ur',
|
|
27
|
+
'yi',
|
|
28
|
+
'ps',
|
|
29
|
+
'sd',
|
|
30
|
+
'ckb',
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Compute the expected writing direction for a language code, honoring an
|
|
34
|
+
* optional override list.
|
|
35
|
+
*/
|
|
36
|
+
export function directionFor(lang, rtlLanguages = DEFAULT_RTL_LANGUAGES) {
|
|
37
|
+
const base = lang.split('-')[0]?.toLowerCase() ?? '';
|
|
38
|
+
return rtlLanguages.includes(base) ? 'rtl' : 'ltr';
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAW9C;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAA;IAEjC,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAC3C,CAAC,IAAI,CAAC,CACP,CAAA;IAED,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,QAAQ;QACrB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC5C,SAAS;KACV,CAAA;AACH,CAAC;AAID;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACtD,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;CACN,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,eAAkC,qBAAqB;IAEvD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;IACpD,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AACpD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createI18n, type CreateI18nOptions } from './config';
|
|
2
|
+
export { baseResources, en, es, type BaseLanguage, } from './locales/index';
|
|
3
|
+
export { LanguageSwitcher, type LanguageOption, type LanguageSwitcherProps, } from './language-switcher';
|
|
4
|
+
export { DirectionProvider, useDirection, type Direction, type DirectionContextValue, type DirectionProviderProps, } from './direction-provider';
|
|
5
|
+
export { useLocale, directionFor, DEFAULT_RTL_LANGUAGES, type UseLocaleResult, } from './hooks';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EACL,aAAa,EACb,EAAE,EACF,EAAE,EACF,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,qBAAqB,EACrB,KAAK,eAAe,GACrB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createI18n } from './config';
|
|
2
|
+
export { baseResources, en, es, } from './locales/index';
|
|
3
|
+
export { LanguageSwitcher, } from './language-switcher';
|
|
4
|
+
export { DirectionProvider, useDirection, } from './direction-provider';
|
|
5
|
+
export { useLocale, directionFor, DEFAULT_RTL_LANGUAGES, } from './hooks';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,UAAU,CAAA;AAC7D,OAAO,EACL,aAAa,EACb,EAAE,EACF,EAAE,GAEH,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,iBAAiB,EACjB,YAAY,GAIb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,qBAAqB,GAEtB,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type LanguageOption = {
|
|
2
|
+
/** BCP-47 language code (e.g. `"en"`, `"es"`, `"en-US"`). */
|
|
3
|
+
code: string;
|
|
4
|
+
/** Human-readable label shown in the dropdown. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Optional flag emoji or short prefix rendered before the label. */
|
|
7
|
+
flag?: string;
|
|
8
|
+
};
|
|
9
|
+
export type LanguageSwitcherProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Languages to render. When omitted, defaults to English + Spanish which
|
|
12
|
+
* matches the base resource bundles shipped with this package.
|
|
13
|
+
*/
|
|
14
|
+
languages?: LanguageOption[];
|
|
15
|
+
/** Alignment of the dropdown content. Defaults to `"end"`. */
|
|
16
|
+
align?: 'start' | 'center' | 'end';
|
|
17
|
+
/** Override the trigger button size. Defaults to `"icon"`. */
|
|
18
|
+
size?: 'default' | 'sm' | 'lg' | 'icon';
|
|
19
|
+
/** Override the trigger button variant. Defaults to `"ghost"`. */
|
|
20
|
+
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
21
|
+
/** Extra class names for the trigger button. */
|
|
22
|
+
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Called after the language has been changed. Useful for re-fetching
|
|
25
|
+
* server-side data or invalidating caches.
|
|
26
|
+
*/
|
|
27
|
+
onChange?: (code: string) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Layout-agnostic dropdown that swaps the active i18next language.
|
|
31
|
+
*
|
|
32
|
+
* Ships no app-specific styling beyond the shadcn primitives re-exported from
|
|
33
|
+
* `@asteby/metacore-ui`. Apps can inject their own list of languages (with
|
|
34
|
+
* optional flag emojis) via the `languages` prop.
|
|
35
|
+
*/
|
|
36
|
+
export declare function LanguageSwitcher({ languages, align, size, variant, className, onChange, }: LanguageSwitcherProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
//# sourceMappingURL=language-switcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-switcher.d.ts","sourceRoot":"","sources":["../src/language-switcher.tsx"],"names":[],"mappings":"AAUA,MAAM,MAAM,cAAc,GAAG;IAC3B,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAA;IACZ,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAA;IACb,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAA;IAC5B,8DAA8D;IAC9D,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAA;IAClC,8DAA8D;IAC9D,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAA;IACvC,kEAAkE;IAClE,OAAO,CAAC,EACJ,SAAS,GACT,aAAa,GACb,SAAS,GACT,WAAW,GACX,OAAO,GACP,MAAM,CAAA;IACV,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC,CAAA;AAOD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,SAA6B,EAC7B,KAAa,EACb,IAAa,EACb,OAAiB,EACjB,SAAS,EACT,QAAQ,GACT,EAAE,qBAAqB,2CAyCvB"}
|