@lingui/react 4.0.0-next.1 → 4.0.0-next.3
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/build/cjs/index.js +26 -52
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +26 -52
- package/build/esm/index.js.map +1 -1
- package/build/index.d.ts +4 -14
- package/package.json +3 -3
package/build/cjs/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
4
3
|
var React = require('react');
|
|
5
4
|
|
|
6
5
|
const LinguiContext = /*#__PURE__*/React.createContext(null);
|
|
@@ -13,34 +12,17 @@ function useLingui() {
|
|
|
13
12
|
}
|
|
14
13
|
return context;
|
|
15
14
|
}
|
|
16
|
-
function withI18n(o) {
|
|
17
|
-
return WrappedComponent => {
|
|
18
|
-
return props => {
|
|
19
|
-
if (process.env.NODE_ENV !== "production") {
|
|
20
|
-
if (typeof o === "function" || /*#__PURE__*/React.isValidElement(o)) {
|
|
21
|
-
throw new Error("withI18n([options]) takes options as a first argument, " + "but received React component itself. Without options, the Component " + "should be wrapped as withI18n()(Component), not withI18n(Component).");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const {
|
|
25
|
-
i18n
|
|
26
|
-
} = useLingui();
|
|
27
|
-
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
|
28
|
-
i18n: i18n
|
|
29
|
-
}));
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
15
|
const I18nProvider = _ref => {
|
|
34
16
|
let {
|
|
35
17
|
i18n,
|
|
36
18
|
defaultComponent,
|
|
37
|
-
forceRenderOnLocaleChange = true,
|
|
38
19
|
children
|
|
39
20
|
} = _ref;
|
|
21
|
+
const latestKnownLocale = React.useRef(i18n.locale);
|
|
40
22
|
/**
|
|
41
23
|
* We can't pass `i18n` object directly through context, because even when locale
|
|
42
24
|
* or messages are changed, i18n object is still the same. Context provider compares
|
|
43
|
-
* reference identity and suggested workaround is create a wrapper object every time
|
|
25
|
+
* reference identity and suggested workaround is to create a wrapper object every time
|
|
44
26
|
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
|
|
45
27
|
*
|
|
46
28
|
* Due to this effect we also pass `defaultComponent` in the same context, instead
|
|
@@ -48,15 +30,11 @@ const I18nProvider = _ref => {
|
|
|
48
30
|
*
|
|
49
31
|
* We can't use useMemo hook either, because we want to recalculate value manually.
|
|
50
32
|
*/
|
|
51
|
-
const makeContext = () => ({
|
|
33
|
+
const makeContext = React.useCallback(() => ({
|
|
52
34
|
i18n,
|
|
53
35
|
defaultComponent
|
|
54
|
-
});
|
|
55
|
-
const
|
|
56
|
-
return forceRenderOnLocaleChange ? i18n.locale || "default" : "default";
|
|
57
|
-
};
|
|
58
|
-
const [context, setContext] = React.useState(makeContext()),
|
|
59
|
-
[renderKey, setRenderKey] = React.useState(getRenderKey());
|
|
36
|
+
}), [i18n, defaultComponent]);
|
|
37
|
+
const [context, setContext] = React.useState(makeContext());
|
|
60
38
|
|
|
61
39
|
/**
|
|
62
40
|
* Subscribe for locale/message changes
|
|
@@ -64,29 +42,29 @@ const I18nProvider = _ref => {
|
|
|
64
42
|
* I18n object from `@lingui/core` is the single source of truth for all i18n related
|
|
65
43
|
* data (active locale, catalogs). When new messages are loaded or locale is changed
|
|
66
44
|
* we need to trigger re-rendering of LinguiContext.Consumers.
|
|
67
|
-
*
|
|
68
|
-
* We call `setContext(makeContext())` after adding the observer in case the `change`
|
|
69
|
-
* event would already have fired between the inital renderKey calculation and the
|
|
70
|
-
* `useEffect` hook being called. This can happen if locales are loaded/activated
|
|
71
|
-
* async.
|
|
72
45
|
*/
|
|
73
46
|
React.useEffect(() => {
|
|
74
|
-
const
|
|
47
|
+
const updateContext = () => {
|
|
48
|
+
latestKnownLocale.current = i18n.locale;
|
|
75
49
|
setContext(makeContext());
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
};
|
|
51
|
+
const unsubscribe = i18n.on("change", updateContext);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* unlikely, but if the locale changes before the onChange listener
|
|
55
|
+
* was added, we need to trigger a rerender
|
|
56
|
+
* */
|
|
57
|
+
if (latestKnownLocale.current !== i18n.locale) {
|
|
58
|
+
updateContext();
|
|
83
59
|
}
|
|
84
|
-
return
|
|
85
|
-
}, []);
|
|
86
|
-
if (
|
|
60
|
+
return unsubscribe;
|
|
61
|
+
}, [makeContext]);
|
|
62
|
+
if (!latestKnownLocale.current) {
|
|
63
|
+
process.env.NODE_ENV === "development" && console.log("I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render." + "This is not an error but an informational message logged only in development.");
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
87
66
|
return /*#__PURE__*/React.createElement(LinguiContext.Provider, {
|
|
88
|
-
value: context
|
|
89
|
-
key: renderKey
|
|
67
|
+
value: context
|
|
90
68
|
}, children);
|
|
91
69
|
};
|
|
92
70
|
|
|
@@ -193,10 +171,10 @@ function Trans(props) {
|
|
|
193
171
|
formats
|
|
194
172
|
} = props;
|
|
195
173
|
const values = {
|
|
196
|
-
...props.values
|
|
174
|
+
...(props.values || {})
|
|
197
175
|
};
|
|
198
176
|
const components = {
|
|
199
|
-
...props.components
|
|
177
|
+
...(props.components || {})
|
|
200
178
|
};
|
|
201
179
|
if (values) {
|
|
202
180
|
/*
|
|
@@ -259,13 +237,9 @@ function Trans(props) {
|
|
|
259
237
|
const DefaultComponent = defaultComponent;
|
|
260
238
|
return DefaultComponent && !component ? /*#__PURE__*/React.createElement(DefaultComponent, i18nProps, translation) : /*#__PURE__*/React.createElement(Component, null, translation);
|
|
261
239
|
}
|
|
262
|
-
Trans.defaultProps = {
|
|
263
|
-
values: {},
|
|
264
|
-
components: {}
|
|
265
|
-
};
|
|
266
240
|
|
|
267
241
|
exports.I18nProvider = I18nProvider;
|
|
242
|
+
exports.LinguiContext = LinguiContext;
|
|
268
243
|
exports.Trans = Trans;
|
|
269
244
|
exports.useLingui = useLingui;
|
|
270
|
-
exports.withI18n = withI18n;
|
|
271
245
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type withI18nProps = {\n i18n: I18n\n}\n\nexport type I18nProviderProps = I18nContext & {\n forceRenderOnLocaleChange?: boolean\n children?: React.ReactNode\n}\n\nconst LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport function withI18n(\n o?: object\n): <P extends withI18nProps>(\n Component: ComponentType<P>\n) => React.ComponentType<Omit<P, \"i18n\">> {\n return <P extends withI18nProps>(\n WrappedComponent: ComponentType<P>\n ): ComponentType<P> => {\n return (props) => {\n if (process.env.NODE_ENV !== \"production\") {\n if (typeof o === \"function\" || React.isValidElement(o)) {\n throw new Error(\n \"withI18n([options]) takes options as a first argument, \" +\n \"but received React component itself. Without options, the Component \" +\n \"should be wrapped as withI18n()(Component), not withI18n(Component).\"\n )\n }\n }\n\n const { i18n } = useLingui()\n return <WrappedComponent {...props} i18n={i18n} />\n }\n }\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n forceRenderOnLocaleChange = true,\n children,\n}) => {\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = () => ({\n i18n,\n defaultComponent,\n })\n const getRenderKey = () => {\n return (\n forceRenderOnLocaleChange ? i18n.locale || \"default\" : \"default\"\n ) as string\n }\n\n const [context, setContext] = React.useState<I18nContext>(makeContext()),\n [renderKey, setRenderKey] = React.useState<string>(getRenderKey())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n *\n * We call `setContext(makeContext())` after adding the observer in case the `change`\n * event would already have fired between the inital renderKey calculation and the\n * `useEffect` hook being called. This can happen if locales are loaded/activated\n * async.\n */\n React.useEffect(() => {\n const unsubscribe = i18n.on(\"change\", () => {\n setContext(makeContext())\n setRenderKey(getRenderKey())\n })\n if (renderKey === \"default\") {\n setRenderKey(getRenderKey())\n }\n if (forceRenderOnLocaleChange && renderKey === \"default\") {\n console.log(\n \"I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false.\"\n )\n }\n return () => unsubscribe()\n }, [])\n\n if (forceRenderOnLocaleChange && renderKey === \"default\") return null\n\n return (\n <LinguiContext.Provider value={context} key={renderKey}>\n {children}\n </LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <tag>paired</tag> and <tag/> unpaired tags\nconst tagRe = /<([a-zA-Z0-9]+)>(.*?)<\\/\\1>|<([a-zA-Z0-9]+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true,\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, \"$lingui$\")\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can't use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[paired || unpaired, children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter =\n (count = 0, prefix = \"\") =>\n () =>\n `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values: Record<string, unknown>\n components: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...props.values }\n const components = { ...props.components }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return translation as unknown as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n\nTrans.defaultProps = {\n values: {},\n components: {},\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","withI18n","o","WrappedComponent","props","isValidElement","i18n","I18nProvider","defaultComponent","forceRenderOnLocaleChange","children","makeContext","getRenderKey","locale","setContext","useState","renderKey","setRenderKey","useEffect","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","index","after","getElements","element","type","error","createElement","Fragment","cloneElement","key","paired","unpaired","slice","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent","defaultProps"],"mappings":";;;;;AAkBA,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAa,CAAc,IAAI,CAAC,CAAA;AAErD,SAASC,SAAS,GAAgB;AACvC,EAAA,MAAMC,OAAO,GAAGH,KAAK,CAACI,UAAU,CAAcL,aAAa,CAAC,CAAA;AAE5D,E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AAA,SAAU,EAAC,CACpG,CAAA;AACD,IAAA,oBAAO,oBAAC,iBAAiB,EAAKa,SAAS,EAAGF,WAAW,CAAqB,CAAA;AAC5E,GAAA;;AAEA;AACA,EAAA,IAAI,OAAOZ,MAAM,KAAK,UAAU,EAAE;AAChC;IACA,OAAOA,MAAM,CAACc,SAAS,CAAC,CAAA;AAC1B,GAAA;;AAEA;AACA,EAAA,MAAME,SAAS,GAAIf,SAAS,IAAIY,iBAA8C,CAAA;EAC9E,MAAMI,gBAAgB,GAAGjF,gBAAgB,CAAA;AAEzC,EAAA,OAAOiF,gBAAgB,IAAI,CAAChB,SAAS,gBACnC,oBAAC,gBAAgB,EAAKa,SAAS,EAAGF,WAAW,CAAoB,gBAEjE,oBAAC,SAAS,EAAA,IAAA,EAAEA,WAAW,CACxB,CAAA;AACH,CAAA;AAEAb,KAAK,CAACmB,YAAY,GAAG;EACnBb,MAAM,EAAE,EAAE;AACVC,EAAAA,UAAU,EAAE,EAAC;AACf,CAAC;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type I18nProviderProps = I18nContext & {\n children?: React.ReactNode\n}\n\nexport const LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n children,\n}) => {\n const latestKnownLocale = React.useRef<string | undefined>(i18n.locale)\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is to create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = React.useCallback(\n () => ({\n i18n,\n defaultComponent,\n }),\n [i18n, defaultComponent]\n )\n\n const [context, setContext] = React.useState<I18nContext>(makeContext())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n */\n React.useEffect(() => {\n const updateContext = () => {\n latestKnownLocale.current = i18n.locale\n setContext(makeContext())\n }\n const unsubscribe = i18n.on(\"change\", updateContext)\n\n /**\n * unlikely, but if the locale changes before the onChange listener\n * was added, we need to trigger a rerender\n * */\n if (latestKnownLocale.current !== i18n.locale) {\n updateContext()\n }\n return unsubscribe\n }, [makeContext])\n\n if (!latestKnownLocale.current) {\n process.env.NODE_ENV === \"development\" &&\n console.log(\n \"I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render.\" +\n \"This is not an error but an informational message logged only in development.\"\n )\n return null\n }\n\n return (\n <LinguiContext.Provider value={context}>{children}</LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <tag>paired</tag> and <tag/> unpaired tags\nconst tagRe = /<([a-zA-Z0-9]+)>(.*?)<\\/\\1>|<([a-zA-Z0-9]+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true,\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, \"$lingui$\")\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can't use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[paired || unpaired, children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter =\n (count = 0, prefix = \"\") =>\n () =>\n `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values?: Record<string, unknown>\n components?: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...(props.values || {}) }\n const components = { ...(props.components || {}) }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return translation as unknown as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","I18nProvider","i18n","defaultComponent","children","latestKnownLocale","useRef","locale","makeContext","useCallback","setContext","useState","useEffect","updateContext","current","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","index","after","getElements","element","type","error","createElement","Fragment","cloneElement","key","props","paired","unpaired","slice","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","isValidElement","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent"],"mappings":";;;;AAaO,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAa,CAAc,IAAI,EAAC;AAE5D,SAASC,SAAS,GAAgB;AACvC,EAAA,MAAMC,OAAO,GAAGH,KAAK,CAACI,UAAU,CAAcL,aAAa,CAAC,CAAA;AAE5D,EAAA,IAAIM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,IAAIJ,OAAO,IAAI,IAAI,EAAE;AACnB,MAAA,MAAM,IAAIK,KAAK,CAAC,+CAA+C,CAAC,CAAA;AAClE,KAAA;AACF,GAAA;AAEA,EAAA,OAAOL,OAAO,CAAA;AAChB,C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AIV,OAAO,KAAKU,WAAAA;GACjD,CAAA;;AAED;EACA,IAAIb,MAAM,IAAIC,SAAS,EAAE;AACvBrD,IAAAA,OAAO,CAACuC,KAAK,CACX,4FAA4F,CAC7F,CAAA;GACF,MAAM,IAAIa,MAAM,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;AACjDpD,IAAAA,OAAO,CAACuC,KAAK,CACV,CAA6Ea,2EAAAA,EAAAA,MAAO,EAAC,CACvF,CAAA;GACF,MAAM,IAAIC,SAAS,IAAI,OAAOA,SAAS,KAAK,UAAU,EAAE;AACvD;AACA;AACArD,IAAAA,OAAO,CAACuC,KAAK,CACV,CAAuFc,qFAAAA,EAAAA,SAAU,EAAC,CACpG,CAAA;AACD,IAAA,oBAAO,oBAAC,iBAAiB,EAAKc,SAAS,EAAGF,WAAW,CAAqB,CAAA;AAC5E,GAAA;;AAEA;AACA,EAAA,IAAI,OAAOb,MAAM,KAAK,UAAU,EAAE;AAChC;IACA,OAAOA,MAAM,CAACe,SAAS,CAAC,CAAA;AAC1B,GAAA;;AAEA;AACA,EAAA,MAAME,SAAS,GAAIhB,SAAS,IAAIa,iBAA8C,CAAA;EAC9E,MAAMI,gBAAgB,GAAGpF,gBAAgB,CAAA;AAEzC,EAAA,OAAOoF,gBAAgB,IAAI,CAACjB,SAAS,gBACnC,oBAAC,gBAAgB,EAAKc,SAAS,EAAGF,WAAW,CAAoB,gBAEjE,oBAAC,SAAS,EAAA,IAAA,EAAEA,WAAW,CACxB,CAAA;AACH;;;;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
|
|
4
3
|
const LinguiContext = /*#__PURE__*/React.createContext(null);
|
|
@@ -11,34 +10,17 @@ function useLingui() {
|
|
|
11
10
|
}
|
|
12
11
|
return context;
|
|
13
12
|
}
|
|
14
|
-
function withI18n(o) {
|
|
15
|
-
return WrappedComponent => {
|
|
16
|
-
return props => {
|
|
17
|
-
if (process.env.NODE_ENV !== "production") {
|
|
18
|
-
if (typeof o === "function" || /*#__PURE__*/React.isValidElement(o)) {
|
|
19
|
-
throw new Error("withI18n([options]) takes options as a first argument, " + "but received React component itself. Without options, the Component " + "should be wrapped as withI18n()(Component), not withI18n(Component).");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const {
|
|
23
|
-
i18n
|
|
24
|
-
} = useLingui();
|
|
25
|
-
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
|
26
|
-
i18n: i18n
|
|
27
|
-
}));
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
13
|
const I18nProvider = _ref => {
|
|
32
14
|
let {
|
|
33
15
|
i18n,
|
|
34
16
|
defaultComponent,
|
|
35
|
-
forceRenderOnLocaleChange = true,
|
|
36
17
|
children
|
|
37
18
|
} = _ref;
|
|
19
|
+
const latestKnownLocale = React.useRef(i18n.locale);
|
|
38
20
|
/**
|
|
39
21
|
* We can't pass `i18n` object directly through context, because even when locale
|
|
40
22
|
* or messages are changed, i18n object is still the same. Context provider compares
|
|
41
|
-
* reference identity and suggested workaround is create a wrapper object every time
|
|
23
|
+
* reference identity and suggested workaround is to create a wrapper object every time
|
|
42
24
|
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
|
|
43
25
|
*
|
|
44
26
|
* Due to this effect we also pass `defaultComponent` in the same context, instead
|
|
@@ -46,15 +28,11 @@ const I18nProvider = _ref => {
|
|
|
46
28
|
*
|
|
47
29
|
* We can't use useMemo hook either, because we want to recalculate value manually.
|
|
48
30
|
*/
|
|
49
|
-
const makeContext = () => ({
|
|
31
|
+
const makeContext = React.useCallback(() => ({
|
|
50
32
|
i18n,
|
|
51
33
|
defaultComponent
|
|
52
|
-
});
|
|
53
|
-
const
|
|
54
|
-
return forceRenderOnLocaleChange ? i18n.locale || "default" : "default";
|
|
55
|
-
};
|
|
56
|
-
const [context, setContext] = React.useState(makeContext()),
|
|
57
|
-
[renderKey, setRenderKey] = React.useState(getRenderKey());
|
|
34
|
+
}), [i18n, defaultComponent]);
|
|
35
|
+
const [context, setContext] = React.useState(makeContext());
|
|
58
36
|
|
|
59
37
|
/**
|
|
60
38
|
* Subscribe for locale/message changes
|
|
@@ -62,29 +40,29 @@ const I18nProvider = _ref => {
|
|
|
62
40
|
* I18n object from `@lingui/core` is the single source of truth for all i18n related
|
|
63
41
|
* data (active locale, catalogs). When new messages are loaded or locale is changed
|
|
64
42
|
* we need to trigger re-rendering of LinguiContext.Consumers.
|
|
65
|
-
*
|
|
66
|
-
* We call `setContext(makeContext())` after adding the observer in case the `change`
|
|
67
|
-
* event would already have fired between the inital renderKey calculation and the
|
|
68
|
-
* `useEffect` hook being called. This can happen if locales are loaded/activated
|
|
69
|
-
* async.
|
|
70
43
|
*/
|
|
71
44
|
React.useEffect(() => {
|
|
72
|
-
const
|
|
45
|
+
const updateContext = () => {
|
|
46
|
+
latestKnownLocale.current = i18n.locale;
|
|
73
47
|
setContext(makeContext());
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
48
|
+
};
|
|
49
|
+
const unsubscribe = i18n.on("change", updateContext);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* unlikely, but if the locale changes before the onChange listener
|
|
53
|
+
* was added, we need to trigger a rerender
|
|
54
|
+
* */
|
|
55
|
+
if (latestKnownLocale.current !== i18n.locale) {
|
|
56
|
+
updateContext();
|
|
81
57
|
}
|
|
82
|
-
return
|
|
83
|
-
}, []);
|
|
84
|
-
if (
|
|
58
|
+
return unsubscribe;
|
|
59
|
+
}, [makeContext]);
|
|
60
|
+
if (!latestKnownLocale.current) {
|
|
61
|
+
process.env.NODE_ENV === "development" && console.log("I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render." + "This is not an error but an informational message logged only in development.");
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
85
64
|
return /*#__PURE__*/React.createElement(LinguiContext.Provider, {
|
|
86
|
-
value: context
|
|
87
|
-
key: renderKey
|
|
65
|
+
value: context
|
|
88
66
|
}, children);
|
|
89
67
|
};
|
|
90
68
|
|
|
@@ -191,10 +169,10 @@ function Trans(props) {
|
|
|
191
169
|
formats
|
|
192
170
|
} = props;
|
|
193
171
|
const values = {
|
|
194
|
-
...props.values
|
|
172
|
+
...(props.values || {})
|
|
195
173
|
};
|
|
196
174
|
const components = {
|
|
197
|
-
...props.components
|
|
175
|
+
...(props.components || {})
|
|
198
176
|
};
|
|
199
177
|
if (values) {
|
|
200
178
|
/*
|
|
@@ -257,10 +235,6 @@ function Trans(props) {
|
|
|
257
235
|
const DefaultComponent = defaultComponent;
|
|
258
236
|
return DefaultComponent && !component ? /*#__PURE__*/React.createElement(DefaultComponent, i18nProps, translation) : /*#__PURE__*/React.createElement(Component, null, translation);
|
|
259
237
|
}
|
|
260
|
-
Trans.defaultProps = {
|
|
261
|
-
values: {},
|
|
262
|
-
components: {}
|
|
263
|
-
};
|
|
264
238
|
|
|
265
|
-
export { I18nProvider, Trans, useLingui
|
|
239
|
+
export { I18nProvider, LinguiContext, Trans, useLingui };
|
|
266
240
|
//# sourceMappingURL=index.js.map
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type withI18nProps = {\n i18n: I18n\n}\n\nexport type I18nProviderProps = I18nContext & {\n forceRenderOnLocaleChange?: boolean\n children?: React.ReactNode\n}\n\nconst LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport function withI18n(\n o?: object\n): <P extends withI18nProps>(\n Component: ComponentType<P>\n) => React.ComponentType<Omit<P, \"i18n\">> {\n return <P extends withI18nProps>(\n WrappedComponent: ComponentType<P>\n ): ComponentType<P> => {\n return (props) => {\n if (process.env.NODE_ENV !== \"production\") {\n if (typeof o === \"function\" || React.isValidElement(o)) {\n throw new Error(\n \"withI18n([options]) takes options as a first argument, \" +\n \"but received React component itself. Without options, the Component \" +\n \"should be wrapped as withI18n()(Component), not withI18n(Component).\"\n )\n }\n }\n\n const { i18n } = useLingui()\n return <WrappedComponent {...props} i18n={i18n} />\n }\n }\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n forceRenderOnLocaleChange = true,\n children,\n}) => {\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = () => ({\n i18n,\n defaultComponent,\n })\n const getRenderKey = () => {\n return (\n forceRenderOnLocaleChange ? i18n.locale || \"default\" : \"default\"\n ) as string\n }\n\n const [context, setContext] = React.useState<I18nContext>(makeContext()),\n [renderKey, setRenderKey] = React.useState<string>(getRenderKey())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n *\n * We call `setContext(makeContext())` after adding the observer in case the `change`\n * event would already have fired between the inital renderKey calculation and the\n * `useEffect` hook being called. This can happen if locales are loaded/activated\n * async.\n */\n React.useEffect(() => {\n const unsubscribe = i18n.on(\"change\", () => {\n setContext(makeContext())\n setRenderKey(getRenderKey())\n })\n if (renderKey === \"default\") {\n setRenderKey(getRenderKey())\n }\n if (forceRenderOnLocaleChange && renderKey === \"default\") {\n console.log(\n \"I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false.\"\n )\n }\n return () => unsubscribe()\n }, [])\n\n if (forceRenderOnLocaleChange && renderKey === \"default\") return null\n\n return (\n <LinguiContext.Provider value={context} key={renderKey}>\n {children}\n </LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <tag>paired</tag> and <tag/> unpaired tags\nconst tagRe = /<([a-zA-Z0-9]+)>(.*?)<\\/\\1>|<([a-zA-Z0-9]+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true,\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, \"$lingui$\")\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can't use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[paired || unpaired, children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter =\n (count = 0, prefix = \"\") =>\n () =>\n `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values: Record<string, unknown>\n components: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...props.values }\n const components = { ...props.components }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return translation as unknown as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n\nTrans.defaultProps = {\n values: {},\n components: {},\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","withI18n","o","WrappedComponent","props","isValidElement","i18n","I18nProvider","defaultComponent","forceRenderOnLocaleChange","children","makeContext","getRenderKey","locale","setContext","useState","renderKey","setRenderKey","useEffect","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","index","after","getElements","element","type","error","createElement","Fragment","cloneElement","key","paired","unpaired","slice","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent","defaultProps"],"mappings":";;;AAkBA,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAa,CAAc,IAAI,CAAC,CAAA;AAErD,SAASC,SAAS,GAAgB;AACvC,EAAA,MAAMC,OAAO,GAAGH,KAAK,CAACI,UAAU,CAAcL,aAAa,CAAC,CAAA;AAE5D,EAAA,IAAIM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,IAAIJ,OAAO,IAAI,IAAI,EAAE;AACnB,MAAA,MAAM,IAAIK,KAAK,CAAC,+CAA+C,CAAC,CAAA;AAClE,KAAA;AACF,GAAA;AAEA,EAAA,OAAOL,OAAO,CAAA;AAChB,CAAA;AAEO,SAASM,QAAQ,CACtBC,CAAU,EAG8B;AACxC,EAAA,OACEC,gBAAkC,IACb;AACrB,IAAA,OAAQC,KAAK,IAAK;AAChB,MAAA,IAAIP,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,OAAOG,CAAC,KAAK,UAAU,iBAAIV,KAAK,CAACa,cAAc,CAACH,CAAC,CAAC,EAAE;UACtD,MAAM,IAAIF,KAAK,CACb,yDAAyD,GACvD,sEAAsE,GACtE,sEAAsE,CACzE,CAAA;AACH,SAAA;AACF,OAAA;MAEA,MAAM;AAAEM,QAAAA,IAAAA;OAAM,GAAGZ,SAAS,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
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type I18nProviderProps = I18nContext & {\n children?: React.ReactNode\n}\n\nexport const LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n children,\n}) => {\n const latestKnownLocale = React.useRef<string | undefined>(i18n.locale)\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is to create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = React.useCallback(\n () => ({\n i18n,\n defaultComponent,\n }),\n [i18n, defaultComponent]\n )\n\n const [context, setContext] = React.useState<I18nContext>(makeContext())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n */\n React.useEffect(() => {\n const updateContext = () => {\n latestKnownLocale.current = i18n.locale\n setContext(makeContext())\n }\n const unsubscribe = i18n.on(\"change\", updateContext)\n\n /**\n * unlikely, but if the locale changes before the onChange listener\n * was added, we need to trigger a rerender\n * */\n if (latestKnownLocale.current !== i18n.locale) {\n updateContext()\n }\n return unsubscribe\n }, [makeContext])\n\n if (!latestKnownLocale.current) {\n process.env.NODE_ENV === \"development\" &&\n console.log(\n \"I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render.\" +\n \"This is not an error but an informational message logged only in development.\"\n )\n return null\n }\n\n return (\n <LinguiContext.Provider value={context}>{children}</LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <tag>paired</tag> and <tag/> unpaired tags\nconst tagRe = /<([a-zA-Z0-9]+)>(.*?)<\\/\\1>|<([a-zA-Z0-9]+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true,\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, \"$lingui$\")\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can't use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[paired || unpaired, children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter =\n (count = 0, prefix = \"\") =>\n () =>\n `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values?: Record<string, unknown>\n components?: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...(props.values || {}) }\n const components = { ...(props.components || {}) }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return translation as unknown as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","I18nProvider","i18n","defaultComponent","children","latestKnownLocale","useRef","locale","makeContext","useCallback","setContext","useState","useEffect","updateContext","current","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","index","after","getElements","element","type","error","createElement","Fragment","cloneElement","key","props","paired","unpaired","slice","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","isValidElement","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent"],"mappings":";;AAaO,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAa,CAAc,IAAI,EAAC;AAE5D,SAASC,SAAS,GAAgB;AACvC,EAAA,MAAMC,OAAO,GAAGH,KAAK,CAACI,UAAU,CAAcL,aAAa,CAAC,CAAA;AAE5D,EAAA,IAAIM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,IAAIJ,OAAO,IAAI,IAAI,EAAE;AACnB,MAAA,MAAM,IAAIK,KAAK,CAAC,+CAA+C,CAAC,CAAA;AAClE,KAAA;AACF,GAAA;AAEA,EAAA,OAAOL,OAAO,CAAA;AAChB,CAAA;AAEO,MAAMM,YAAkD,GAAG,IAI5D,IAAA;EAAA,IAJ6D;IACjEC,IAAI;IACJC,gBAAgB;AAChBC,IAAAA,QAAAA;GACD,GAAA,IAAA,CAAA;EACC,MAAMC,iBAAiB,GAAGb,KAAK,CAACc,MAAM,CAAqBJ,IAAI,CAACK,MAAM,CAAC,CAAA;AACvE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACE,EAAA,MAAMC,WAAW,GAAGhB,KAAK,CAACiB,WAAW,CACnC,OAAO;IACLP,IAAI;AACJC,IAAAA,gBAAAA;AACF,GAAC,CAAC,EACF,CAACD,IAAI,EAAEC,gBAAgB,CAAC,CACzB,CAAA;AAED,EAAA,MAAM,CAACR,OAAO,EAAEe,UAAU,CAAC,GAAGlB,KAAK,CAACmB,QAAQ,CAAcH,WAAW,EAAE,CAAC,CAAA;;AAExE;AACF;AACA;AACA;AACA;AACA;AACA;EACEhB,KAAK,CAACoB,SAAS,CAAC,MAAM;IACpB,MAAMC,aAAa,GAAG,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1B,GAAA;;AAEA;AACA,EAAA,MAAME,SAAS,GAAIhB,SAAS,IAAIa,iBAA8C,CAAA;EAC9E,MAAMI,gBAAgB,GAAGpF,gBAAgB,CAAA;AAEzC,EAAA,OAAOoF,gBAAgB,IAAI,CAACjB,SAAS,gBACnC,oBAAC,gBAAgB,EAAKc,SAAS,EAAGF,WAAW,CAAoB,gBAEjE,oBAAC,SAAS,EAAA,IAAA,EAAEA,WAAW,CACxB,CAAA;AACH;;;;"}
|
package/build/index.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ type TransRenderProps = {
|
|
|
11
11
|
type TransProps = {
|
|
12
12
|
id: string;
|
|
13
13
|
message?: string;
|
|
14
|
-
values
|
|
15
|
-
components
|
|
14
|
+
values?: Record<string, unknown>;
|
|
15
|
+
components?: {
|
|
16
16
|
[key: string]: React.ElementType | any;
|
|
17
17
|
};
|
|
18
18
|
formats?: Record<string, unknown>;
|
|
@@ -21,26 +21,16 @@ type TransProps = {
|
|
|
21
21
|
render?: (props: TransRenderProps) => React.ReactElement<any, any> | null;
|
|
22
22
|
};
|
|
23
23
|
declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
|
|
24
|
-
declare namespace Trans {
|
|
25
|
-
var defaultProps: {
|
|
26
|
-
values: {};
|
|
27
|
-
components: {};
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
24
|
|
|
31
25
|
type I18nContext = {
|
|
32
26
|
i18n: I18n;
|
|
33
27
|
defaultComponent?: ComponentType<TransRenderProps>;
|
|
34
28
|
};
|
|
35
|
-
type withI18nProps = {
|
|
36
|
-
i18n: I18n;
|
|
37
|
-
};
|
|
38
29
|
type I18nProviderProps = I18nContext & {
|
|
39
|
-
forceRenderOnLocaleChange?: boolean;
|
|
40
30
|
children?: React.ReactNode;
|
|
41
31
|
};
|
|
32
|
+
declare const LinguiContext: React.Context<I18nContext>;
|
|
42
33
|
declare function useLingui(): I18nContext;
|
|
43
|
-
declare function withI18n(o?: object): <P extends withI18nProps>(Component: ComponentType<P>) => React.ComponentType<Omit<P, "i18n">>;
|
|
44
34
|
declare const I18nProvider: FunctionComponent<I18nProviderProps>;
|
|
45
35
|
|
|
46
|
-
export { I18nContext, I18nProvider, I18nProviderProps, Trans, TransProps, TransRenderProps, useLingui
|
|
36
|
+
export { I18nContext, I18nProvider, I18nProviderProps, LinguiContext, Trans, TransProps, TransRenderProps, useLingui };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/react",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React components for translations",
|
|
6
6
|
"main": "./build/cjs/index.js",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/runtime": "^7.20.13",
|
|
57
|
-
"@lingui/core": "^4.0.0-next.
|
|
57
|
+
"@lingui/core": "^4.0.0-next.3"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@testing-library/react": "^11.0.4"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "29cad1bdcc781994ac4d496e5c4937795423d405"
|
|
63
63
|
}
|