@genrwork/laravel-i18next 0.1.0 → 0.1.1
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 +110 -28
- package/dist/index.cjs +125 -3
- package/dist/index.mjs +124 -1
- package/dist/react.cjs +7 -5
- package/dist/react.mjs +7 -5
- package/dist/shared/{create-i18n-WsDK4Z8L.cjs → create-i18n-DI7Eog6O.cjs} +83 -333
- package/dist/shared/{create-i18n-BSEwKsCX.mjs → create-i18n-DaZzs1DJ.mjs} +78 -333
- package/dist/shared/demand-6YnTqSM4.mjs +92 -0
- package/dist/shared/demand-sbjTXVnl.cjs +101 -0
- package/dist/svelte.cjs +7 -1
- package/dist/svelte.mjs +7 -1
- package/dist/types/contrib/get-plural-index.d.ts +1 -1
- package/dist/types/defaults.d.ts +18 -0
- package/dist/types/demand.d.ts +51 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/plugin/convert.d.ts +10 -0
- package/dist/types/plugin/namespaces.d.ts +20 -0
- package/dist/types/plugin/parser.d.ts +3 -0
- package/dist/types/plugin/sources.d.ts +5 -5
- package/dist/types/preload.d.ts +99 -0
- package/dist/types/react/i18n-provider-props.d.ts +5 -0
- package/dist/types/react/provider.d.ts +4 -3
- package/dist/types/shared/create-i18n.d.ts +9 -3
- package/dist/types/utils/cache.d.ts +3 -0
- package/dist/types/vite.d.ts +18 -1
- package/dist/vite.cjs +408 -6
- package/dist/vite.mjs +408 -6
- package/dist/vue.cjs +2 -1
- package/dist/vue.mjs +2 -1
- package/package.json +155 -155
- package/dist/types/format.d.ts +0 -43
- package/dist/types/interfaces/replacements.d.ts +0 -6
- package/dist/types/utils/replacer.d.ts +0 -9
- /package/dist/types/{utils → plugin}/pluralization.d.ts +0 -0
package/dist/svelte.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { onDestroy, setContext, hasContext, getContext } from 'svelte';
|
|
2
2
|
import { writable, derived } from 'svelte/store';
|
|
3
|
-
import { c as createI18n, s as syncDocumentLang } from './shared/create-i18n-
|
|
3
|
+
import { c as createI18n, s as syncDocumentLang } from './shared/create-i18n-DaZzs1DJ.mjs';
|
|
4
4
|
import 'i18next';
|
|
5
|
+
import './shared/demand-6YnTqSM4.mjs';
|
|
5
6
|
|
|
6
7
|
const CONTEXT_KEY = 'laravel-i18next';
|
|
7
8
|
/**
|
|
@@ -52,6 +53,11 @@ function getI18nextFromContext() {
|
|
|
52
53
|
const instance = i18nextInstance !== null && i18nextInstance !== void 0 ? i18nextInstance : getI18nextFromContext();
|
|
53
54
|
const revision = writable(0);
|
|
54
55
|
const bump = ()=>revision.update((n)=>n + 1);
|
|
56
|
+
// Not preloaded (see `preloadI18n()`): load it now, `ready` turns true once it arrives.
|
|
57
|
+
const current = instance.language || instance.options.lng;
|
|
58
|
+
if (namespace && (!current || !instance.hasResourceBundle(current, namespace))) {
|
|
59
|
+
void instance.loadNamespaces(namespace);
|
|
60
|
+
}
|
|
55
61
|
instance.on('languageChanged', bump);
|
|
56
62
|
instance.on('loaded', bump);
|
|
57
63
|
instance.on('added', bump);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { i18n, InitOptions } from 'i18next';
|
|
2
|
+
/**
|
|
3
|
+
* The i18next options Laravel translations need. `createI18n()` applies them;
|
|
4
|
+
* pass them to `init()` yourself when you set i18next up by hand.
|
|
5
|
+
*
|
|
6
|
+
* - no key or namespace separator: Laravel keys are flat and contain dots
|
|
7
|
+
* and colons (`auth.failed`, `Email:`);
|
|
8
|
+
* - an empty message counts as missing and falls back to the next language;
|
|
9
|
+
* - no escaping of interpolated values: React, Vue and Svelte already escape
|
|
10
|
+
* what they render, and Laravel's `:name` replacements were never escaped.
|
|
11
|
+
*/
|
|
12
|
+
export declare const laravelOptions: InitOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Register the `uppercase`, `lowercase` and `capitalize` interpolation formats.
|
|
15
|
+
* The Vite plugin writes Laravel's `:NAME` as `{{name, uppercase}}` and `:Name`
|
|
16
|
+
* as `{{name, capitalize}}`; call this once the instance is initialized.
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerCaseFormats(instance: i18n): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { i18n } from 'i18next';
|
|
2
|
+
/**
|
|
3
|
+
* Namespaces the application's modules asked for, by evaluating.
|
|
4
|
+
*
|
|
5
|
+
* The Vite plugin adds one `declareNamespaces([...])` call to every module
|
|
6
|
+
* calling `useTranslation('ns')` (or `withTranslation`, `<Trans ns>`), so
|
|
7
|
+
* evaluating a module -- a page, a layout, any component it statically
|
|
8
|
+
* imports -- records which namespaces it will translate with. A bundler loads
|
|
9
|
+
* a page together with everything it imports, so by the time a page is
|
|
10
|
+
* resolved this set holds exactly the namespaces that page needs, however
|
|
11
|
+
* deeply they are nested, with nothing to declare by hand. `preloadI18n()`
|
|
12
|
+
* reads it.
|
|
13
|
+
*
|
|
14
|
+
* Only ever grows, and is shared by every i18next instance of the process.
|
|
15
|
+
*
|
|
16
|
+
* It lives on `globalThis`, under a registered symbol, and the code the Vite
|
|
17
|
+
* plugin injects writes to it directly instead of importing this module: a
|
|
18
|
+
* module can be evaluated before this one (a bundler is free to order a
|
|
19
|
+
* package's chunks around import cycles), can sit in a package that does not
|
|
20
|
+
* depend on this one, and a page bundle and a server bundle can each carry
|
|
21
|
+
* their own copy of this module -- none of that may lose a declaration.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DECLARED_NAMESPACES_KEY = "laravel-i18next.declared";
|
|
24
|
+
/**
|
|
25
|
+
* Record namespaces a module translates with. Called by the code the Vite
|
|
26
|
+
* plugin injects; call it yourself for a namespace requested dynamically
|
|
27
|
+
* (`useTranslation(name)`), which the plugin cannot see.
|
|
28
|
+
*/
|
|
29
|
+
export declare function declareNamespaces(namespaces: string | readonly string[]): void;
|
|
30
|
+
export declare function getDeclaredNamespaces(): string[];
|
|
31
|
+
/**
|
|
32
|
+
* Forget every declared namespace. For tests.
|
|
33
|
+
*/
|
|
34
|
+
export declare function clearDeclaredNamespaces(): void;
|
|
35
|
+
export declare function trackInstance(instance: i18n): void;
|
|
36
|
+
/**
|
|
37
|
+
* The namespaces the components of the live browser instances have rendered
|
|
38
|
+
* with since `forgetRenderedNamespaces()`, or none when nothing recorded them
|
|
39
|
+
* (another framework, or nothing has rendered yet).
|
|
40
|
+
*/
|
|
41
|
+
export declare function getRenderedNamespaces(): string[];
|
|
42
|
+
export declare function forgetRenderedNamespaces(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Make the live instances load only these namespaces the next time their
|
|
45
|
+
* language changes. i18next remembers every namespace it ever loaded and
|
|
46
|
+
* loads them all again for a new language; this forgets the others, which a
|
|
47
|
+
* later `loadNamespaces()` (see `preloadI18n()`) brings back when a page
|
|
48
|
+
* asks for them.
|
|
49
|
+
*/
|
|
50
|
+
export declare function keepOnlyNamespaces(namespaces: readonly string[]): void;
|
|
51
|
+
export declare function getLiveInstances(): i18n[];
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import LaravelBackend from './backend';
|
|
2
|
-
|
|
3
|
-
export {
|
|
2
|
+
export { LaravelBackend };
|
|
3
|
+
export { laravelOptions, registerCaseFormats } from './defaults';
|
|
4
|
+
export { declareNamespaces } from './demand';
|
|
5
|
+
export { preloadI18n, withI18nPreload } from './preload';
|
|
6
|
+
export type { PreloadOptions, ResolvedPage, WithI18nPreloadOptions } from './preload';
|
|
4
7
|
export { createI18n, documentLocale, syncDocumentLang } from './shared/create-i18n';
|
|
5
8
|
export type { LaravelI18nOptions } from './shared/create-i18n';
|
|
6
9
|
export type { default as LaravelBackendOptions, LocaleFiles, LocaleFileSources } from './interfaces/options';
|
|
7
|
-
export type { default as ReplacementsInterface } from './interfaces/replacements';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite Laravel placeholders as i18next interpolations.
|
|
3
|
+
*/
|
|
4
|
+
export declare function toInterpolation(message: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Convert one entry, returning the i18next entries it becomes (one for a
|
|
7
|
+
* plain message, several for a pluralized one). A list has its messages
|
|
8
|
+
* converted, anything else that is not a string is returned untouched.
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertEntry(key: string, value: unknown, locale: string): Record<string, unknown>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the i18next namespaces a module translates with, by reading its code.
|
|
3
|
+
* Deliberately a text scan and not a parse: it runs on every module of the
|
|
4
|
+
* app, on the code of any framework (JSX, Vue and Svelte output alike), and a
|
|
5
|
+
* namespace it over-reports is harmless -- `preloadI18n()` ignores names that
|
|
6
|
+
* have no language file.
|
|
7
|
+
*
|
|
8
|
+
* Recognized, with string literals only:
|
|
9
|
+
*
|
|
10
|
+
* - `useTranslation('auth')`, `useTranslation(['auth', 'teams'])`
|
|
11
|
+
* (react-i18next, i18next-vue, and this package's Svelte `useTranslation`);
|
|
12
|
+
* - `withTranslation('auth')`;
|
|
13
|
+
* - `ns="auth"` / `ns={'auth'}` (`<Trans>`, `<Translation>`);
|
|
14
|
+
* - `{ ns: 'auth' }` (`t()` options, `getFixedT`).
|
|
15
|
+
*
|
|
16
|
+
* Comments are ignored, so documentation that quotes a call (this package's
|
|
17
|
+
* own, or commented-out code) declares nothing. A namespace requested through
|
|
18
|
+
* a variable is invisible to it: declare it with `declareNamespaces()`.
|
|
19
|
+
*/
|
|
20
|
+
export default function detectNamespaces(source: string): string[];
|
|
@@ -6,6 +6,9 @@ export interface GeneratedFile {
|
|
|
6
6
|
* Convert every `lang/{locale}/{namespace}.php` file into a sibling
|
|
7
7
|
* `lang/{locale}/{namespace}.json` file, one per PHP file, so each PHP file
|
|
8
8
|
* becomes its own i18next namespace instead of being merged with the others.
|
|
9
|
+
* The PHP file keeps Laravel's conventions (`:name` placeholders, `one|many`
|
|
10
|
+
* plural forms); the JSON is written the i18next way (`{{name}}`,
|
|
11
|
+
* `key_one` / `key_other`), see `src/plugin/convert.ts`.
|
|
9
12
|
* A PHP file may sit at any depth under the locale directory --
|
|
10
13
|
* `lang/{locale}/{ns1}/{ns2}.php` and deeper -- and gets its sibling `.json`
|
|
11
14
|
* written at that same nested path; the resulting namespace name itself is
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* One configured source, resolved against the project root.
|
|
3
3
|
*/
|
|
4
4
|
export interface ResolvedSource {
|
|
5
|
-
/** As configured, e.g. `'
|
|
5
|
+
/** As configured, e.g. `'packages/*\/lang'`. */
|
|
6
6
|
pattern: string;
|
|
7
|
-
/** Root-relative glob for `import.meta.glob()`, e.g. `'/
|
|
7
|
+
/** Root-relative glob for `import.meta.glob()`, e.g. `'/packages/*\/lang/**\/*.json'`. */
|
|
8
8
|
glob: string;
|
|
9
9
|
/** Every directory the pattern currently expands to, existing ones only, sorted. */
|
|
10
10
|
dirnames: string[];
|
|
@@ -13,7 +13,7 @@ export interface ResolvedSource {
|
|
|
13
13
|
* Every directory an ordered source `pattern` currently expands to, relative
|
|
14
14
|
* to `root`. A pattern with no `*` is a single literal directory (existing or
|
|
15
15
|
* not -- callers decide what an absent literal directory means). A pattern
|
|
16
|
-
* with exactly one `*` segment (e.g. `
|
|
16
|
+
* with exactly one `*` segment (e.g. `packages/*\/lang`) is expanded against
|
|
17
17
|
* the filesystem: every existing subdirectory of the prefix before the `*`,
|
|
18
18
|
* with the suffix after it appended, kept only when the full path also
|
|
19
19
|
* exists, sorted. Two or more `*` segments throw -- unsupported.
|
|
@@ -28,8 +28,8 @@ export declare function expandDirs(pattern: string, root: string): string[];
|
|
|
28
28
|
* so this is always root-relative (a leading `/`). A `*` segment in the
|
|
29
29
|
* pattern passes through `path.resolve`/`path.relative`/`normalizePath`
|
|
30
30
|
* completely untouched -- none of them treat it specially -- which is why
|
|
31
|
-
* the emitted glob needs no separate wildcard handling: `
|
|
32
|
-
* becomes `/
|
|
31
|
+
* the emitted glob needs no separate wildcard handling: `packages/*\/lang`
|
|
32
|
+
* becomes `/packages/*\/lang/**\/*.json` and `import.meta.glob()` expands the
|
|
33
33
|
* `*` itself, natively, at both dev and build time.
|
|
34
34
|
*
|
|
35
35
|
* @param pattern
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { LocaleFileSources } from './interfaces/options';
|
|
2
|
+
export interface PreloadOptions {
|
|
3
|
+
files: LocaleFileSources;
|
|
4
|
+
/**
|
|
5
|
+
* The language about to be shown.
|
|
6
|
+
*/
|
|
7
|
+
locale: string;
|
|
8
|
+
/**
|
|
9
|
+
* Defaults to none; give the same value as the provider's `fallbackLocale`.
|
|
10
|
+
*/
|
|
11
|
+
fallbackLocale?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Namespaces to load besides the ones the evaluated modules declared (see
|
|
14
|
+
* `declareNamespaces()`), or `'*'` for every namespace there is.
|
|
15
|
+
*/
|
|
16
|
+
namespaces?: string[] | '*';
|
|
17
|
+
/**
|
|
18
|
+
* Whether to also load every namespace the evaluated modules declared.
|
|
19
|
+
* Defaults to `true`; `false` loads only the default namespace and the
|
|
20
|
+
* ones in `namespaces`.
|
|
21
|
+
*/
|
|
22
|
+
declared?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load, before anything renders, the translations a page needs.
|
|
26
|
+
*
|
|
27
|
+
* With lazy files (the browser, or the server with `ssr: 'lazy'`) a namespace
|
|
28
|
+
* is a chunk to download, and rendering something that needs a chunk not yet
|
|
29
|
+
* there means waiting for it: the framework suspends and shows a fallback --
|
|
30
|
+
* a blank gap, where Inertia would have kept the old page on screen. Inertia
|
|
31
|
+
* avoids that by loading the next page's component before swapping to it.
|
|
32
|
+
* This does the same for its translations: call it (see `withI18nPreload()`)
|
|
33
|
+
* while the page is resolved, and by the time it renders every namespace it
|
|
34
|
+
* translates with is already in memory, so nothing suspends.
|
|
35
|
+
*
|
|
36
|
+
* It loads, for the language and its fallback, the namespaces declared by the
|
|
37
|
+
* modules evaluated so far -- the page component and everything it statically
|
|
38
|
+
* imports, which the Vite plugin records -- plus the ones given in
|
|
39
|
+
* `namespaces`. Loaded modules are cached, so calling it again costs nothing
|
|
40
|
+
* for what is already there. Live browser instances get the namespaces added,
|
|
41
|
+
* and the new language too when the page switched it.
|
|
42
|
+
*
|
|
43
|
+
* With eager files there is nothing to wait for and it returns at once.
|
|
44
|
+
*/
|
|
45
|
+
export declare function preloadI18n({ files, locale, fallbackLocale, namespaces, declared }: PreloadOptions): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* The page a resolver is asked for: Inertia calls `resolve(name, page)`, where
|
|
48
|
+
* `page.props` holds what the server shared.
|
|
49
|
+
*/
|
|
50
|
+
export interface ResolvedPage {
|
|
51
|
+
props?: object;
|
|
52
|
+
}
|
|
53
|
+
export interface WithI18nPreloadOptions<Page extends ResolvedPage = ResolvedPage> extends Omit<PreloadOptions, "locale"> {
|
|
54
|
+
/**
|
|
55
|
+
* The language a page is shown in: read it from whatever the server shares
|
|
56
|
+
* with every page, e.g. `(page) => page.props.locale`. A page it returns
|
|
57
|
+
* nothing for is resolved without loading translations.
|
|
58
|
+
*/
|
|
59
|
+
locale: (page: Page) => string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* What to load when the page that is on screen is resolved again in another
|
|
62
|
+
* language (a language setting saved, a language chosen through a link).
|
|
63
|
+
*
|
|
64
|
+
* - `"declared"` (default): everything the evaluated modules declared, like
|
|
65
|
+
* for any other page. Always safe.
|
|
66
|
+
* - `"rendered"`: only the namespaces that page has rendered with so far
|
|
67
|
+
* (react-i18next records them), and i18next is told to load only those
|
|
68
|
+
* too, instead of every namespace it ever loaded. A session that visited
|
|
69
|
+
* many pages then downloads a few catalogs for the switch instead of all
|
|
70
|
+
* of them; a namespace left out is loaded, before the page renders, when
|
|
71
|
+
* a page that needs it is visited. Use it only when a page renders the
|
|
72
|
+
* same namespaces in every language and nothing it opens later needs one
|
|
73
|
+
* it has not shown yet, or that namespace suspends until it arrives.
|
|
74
|
+
* Ignored, like when nothing was recorded, outside react-i18next.
|
|
75
|
+
*/
|
|
76
|
+
onLanguageSwitch?: "declared" | "rendered";
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Wrap a page resolver so a page never renders before its translations are in
|
|
80
|
+
* memory -- the same guarantee Inertia gives the page component itself, and
|
|
81
|
+
* for the same reason: nothing is swapped in until it can be shown whole.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* createInertiaApp({
|
|
85
|
+
* resolve: withI18nPreload((name) => resolvePageComponent(...), {
|
|
86
|
+
* files,
|
|
87
|
+
* fallbackLocale: "en",
|
|
88
|
+
* locale: (page) => page.props.locale as string,
|
|
89
|
+
* }),
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* The page component is resolved first, which evaluates it and everything it
|
|
94
|
+
* imports and so declares their namespaces; then those are loaded. That order
|
|
95
|
+
* is what makes the namespaces exact, at the price of one more round of
|
|
96
|
+
* downloads after the page's own -- it happens in parallel with nothing, so
|
|
97
|
+
* keep catalogs small (one per area) rather than one per language.
|
|
98
|
+
*/
|
|
99
|
+
export declare function withI18nPreload<Component, Page extends ResolvedPage = ResolvedPage>(resolve: (name: string, page?: Page) => Component | Promise<Component>, options: WithI18nPreloadOptions<Page>): (name: string, page?: Page) => Promise<Component>;
|
|
@@ -20,4 +20,9 @@ export default interface I18nProviderProps {
|
|
|
20
20
|
* Defaults to the `<html lang="">` attribute, or `en`.
|
|
21
21
|
*/
|
|
22
22
|
fallbackLocale?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Shown while a namespace that was not preloaded (see `preloadI18n()`) loads.
|
|
25
|
+
* Defaults to nothing.
|
|
26
|
+
*/
|
|
27
|
+
fallback?: ReactNode;
|
|
23
28
|
}
|
|
@@ -4,7 +4,8 @@ import type I18nProviderProps from './i18n-provider-props';
|
|
|
4
4
|
*
|
|
5
5
|
* Every provider owns its instance, so concurrent SSR requests do not share a language.
|
|
6
6
|
* With eager files, every namespace is preloaded and translated on the first render.
|
|
7
|
-
* While a lazy namespace loads, the children suspend, which
|
|
8
|
-
* HTML in place until it can be hydrated.
|
|
7
|
+
* While a lazy namespace that was not preloaded loads, the children suspend, which
|
|
8
|
+
* keeps server-rendered HTML in place until it can be hydrated. Preload them (see
|
|
9
|
+
* `withI18nPreload()`) and nothing ever suspends.
|
|
9
10
|
*/
|
|
10
|
-
export default function LaravelReactI18nProvider({ children, files, locale, fallbackLocale }: I18nProviderProps): import("react").JSX.Element;
|
|
11
|
+
export default function LaravelReactI18nProvider({ children, files, locale, fallbackLocale, fallback }: I18nProviderProps): import("react").JSX.Element;
|
|
@@ -15,12 +15,18 @@ export declare function documentLocale(): string;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function syncDocumentLang(instance: i18n): () => void;
|
|
17
17
|
/**
|
|
18
|
-
* Create an i18next instance
|
|
18
|
+
* Create an i18next instance reading Laravel language files as i18next JSON: the default
|
|
19
19
|
* namespace from `lang/{locale}.json`, and one namespace per `lang/{locale}/{namespace}.json`
|
|
20
|
-
* file (
|
|
20
|
+
* file (converted from PHP by the Vite plugin, or hand-written the i18next way).
|
|
21
21
|
*
|
|
22
22
|
* With eager files, every known namespace of the locale and fallback locale is
|
|
23
23
|
* preloaded synchronously, so a first render never has to wait for translations.
|
|
24
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* With lazy files, only the namespaces the evaluated modules declared are loaded
|
|
26
|
+
* up front (see `declareNamespaces()`), plus the default one; any other is loaded
|
|
27
|
+
* when a component first asks for it, which suspends until it arrives. Loaded
|
|
28
|
+
* beforehand with `preloadI18n()` -- or `withI18nPreload()` around the page
|
|
29
|
+
* resolver -- the up front ones are already in memory, so the instance is ready
|
|
30
|
+
* synchronously and neither the first render nor a later page ever waits.
|
|
25
31
|
*/
|
|
26
32
|
export declare function createI18n({ files, locale, fallbackLocale }: LaravelI18nOptions): i18n;
|
package/dist/types/vite.d.ts
CHANGED
|
@@ -5,11 +5,28 @@ export interface ConfigInterface {
|
|
|
5
5
|
* hand-written `.json` files, `.php` files (each converted to a sibling
|
|
6
6
|
* `.json`), or both -- but not both for the same namespace, since a
|
|
7
7
|
* hand-written file is never overwritten (see `src/plugin/parser.ts`).
|
|
8
|
-
* One `*` segment is allowed per entry, e.g. `'
|
|
8
|
+
* One `*` segment is allowed per entry, e.g. `'packages/*\/lang'`, expanded
|
|
9
9
|
* against every matching directory that exists when the dev server starts
|
|
10
10
|
* or a build runs. Defaults to `['lang']`.
|
|
11
11
|
*/
|
|
12
12
|
sources?: string[];
|
|
13
|
+
/**
|
|
14
|
+
* How the server loads language files. `'eager'` (default) bundles them all
|
|
15
|
+
* into the server build, so SSR translates without any step of its own --
|
|
16
|
+
* simple, and right for a few languages and namespaces. `'lazy'` keeps each
|
|
17
|
+
* one a chunk of its own, loaded when a request needs it, so a project with
|
|
18
|
+
* many languages or namespaces keeps its server bundle (and startup) small;
|
|
19
|
+
* it needs `withI18nPreload()` around the page resolver, which loads a
|
|
20
|
+
* page's namespaces before it renders. The browser is always lazy.
|
|
21
|
+
*/
|
|
22
|
+
ssr?: 'eager' | 'lazy';
|
|
23
|
+
/**
|
|
24
|
+
* Tell `preloadI18n()` which namespaces a page needs, by adding a
|
|
25
|
+
* `declareNamespaces([...])` call to every module that calls
|
|
26
|
+
* `useTranslation('ns')` and the like (see `src/plugin/namespaces.ts`).
|
|
27
|
+
* Defaults to `true`; turn it off to declare them yourself.
|
|
28
|
+
*/
|
|
29
|
+
detectNamespaces?: boolean;
|
|
13
30
|
}
|
|
14
31
|
/**
|
|
15
32
|
* Language files, one namespace per language file: loaded eagerly by server
|