@mrmeg/expo-ui 0.1.4 → 0.1.5
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/LLM_USAGE.md +3 -2
- package/README.md +4 -3
- package/dist/components/Button.d.ts +1 -1
- package/dist/components/Notification.js +3 -3
- package/dist/components/StyledText.d.ts +2 -2
- package/dist/lib/i18n.d.ts +2 -2
- package/dist/lib/i18n.js +5 -5
- package/package.json +1 -1
package/LLM_USAGE.md
CHANGED
|
@@ -70,8 +70,9 @@ export function RootLayout() {
|
|
|
70
70
|
|
|
71
71
|
i18n is optional. Do not add app-level i18n setup just to use this package.
|
|
72
72
|
Plain children and `text` props work without `i18next` or `react-i18next`.
|
|
73
|
-
`tx` props render
|
|
74
|
-
translator
|
|
73
|
+
`tx` props render fallback text when provided and otherwise render the key
|
|
74
|
+
until the consumer opts in with a package-local translator. Package-owned
|
|
75
|
+
defaults such as notification titles stay human-readable without app i18n:
|
|
75
76
|
|
|
76
77
|
```tsx
|
|
77
78
|
import { configureExpoUiI18n } from "@mrmeg/expo-ui/lib";
|
package/README.md
CHANGED
|
@@ -116,9 +116,10 @@ Useful `StyledText` props:
|
|
|
116
116
|
- `variant`: `sansSerif`, `serif`
|
|
117
117
|
- `align`, `tx`, `txOptions`
|
|
118
118
|
|
|
119
|
-
`tx` support is opt-in. Without a configured translator, `tx` renders
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
`tx` support is opt-in. Without a configured translator, `tx` renders its
|
|
120
|
+
fallback text when provided and otherwise renders the key; package-owned
|
|
121
|
+
defaults such as notification titles use readable fallback text. Consumers
|
|
122
|
+
that already use i18n can connect it once near app startup:
|
|
122
123
|
|
|
123
124
|
```tsx
|
|
124
125
|
import { configureExpoUiI18n } from "@mrmeg/expo-ui/lib";
|
|
@@ -20,7 +20,7 @@ export interface ButtonProps extends PressableProps {
|
|
|
20
20
|
*/
|
|
21
21
|
tx?: TextProps["tx"];
|
|
22
22
|
/**
|
|
23
|
-
* The text to display
|
|
23
|
+
* The text to display directly, or as fallback text when `tx` is provided.
|
|
24
24
|
*/
|
|
25
25
|
text?: TextProps["text"];
|
|
26
26
|
/**
|
|
@@ -139,11 +139,11 @@ export const Notification = () => {
|
|
|
139
139
|
return alert.title;
|
|
140
140
|
switch (alert?.type) {
|
|
141
141
|
case "error":
|
|
142
|
-
return translateText("notification.error");
|
|
142
|
+
return translateText("notification.error", "Error");
|
|
143
143
|
case "success":
|
|
144
|
-
return translateText("notification.success");
|
|
144
|
+
return translateText("notification.success", "Success");
|
|
145
145
|
case "warning":
|
|
146
|
-
return translateText("notification.warning");
|
|
146
|
+
return translateText("notification.warning", "Warning");
|
|
147
147
|
case "info":
|
|
148
148
|
return "";
|
|
149
149
|
default:
|
|
@@ -53,7 +53,7 @@ export type TextProps = RNTextProps & {
|
|
|
53
53
|
*/
|
|
54
54
|
tx?: string;
|
|
55
55
|
/**
|
|
56
|
-
* The text to display
|
|
56
|
+
* The text to display directly, or as fallback text when `tx` is provided.
|
|
57
57
|
*/
|
|
58
58
|
text?: string;
|
|
59
59
|
/**
|
|
@@ -101,7 +101,7 @@ export declare const StyledText: React.ForwardRefExoticComponent<RNTextProps & {
|
|
|
101
101
|
*/
|
|
102
102
|
tx?: string;
|
|
103
103
|
/**
|
|
104
|
-
* The text to display
|
|
104
|
+
* The text to display directly, or as fallback text when `tx` is provided.
|
|
105
105
|
*/
|
|
106
106
|
text?: string;
|
|
107
107
|
/**
|
package/dist/lib/i18n.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type TranslateFn = (key: string, options?: object) => string;
|
|
1
|
+
export type TranslateFn = (key: string, options?: object) => string | undefined;
|
|
2
2
|
export declare function configureExpoUiI18n(fn: TranslateFn | null): void;
|
|
3
|
-
export declare function translateText(key?: string,
|
|
3
|
+
export declare function translateText(key?: string, fallbackText?: string, options?: object): string | undefined;
|
package/dist/lib/i18n.js
CHANGED
|
@@ -2,10 +2,10 @@ let translate = null;
|
|
|
2
2
|
export function configureExpoUiI18n(fn) {
|
|
3
3
|
translate = fn;
|
|
4
4
|
}
|
|
5
|
-
export function translateText(key,
|
|
6
|
-
if (text)
|
|
7
|
-
return text;
|
|
5
|
+
export function translateText(key, fallbackText, options) {
|
|
8
6
|
if (!key)
|
|
9
|
-
return
|
|
10
|
-
|
|
7
|
+
return fallbackText;
|
|
8
|
+
if (!translate)
|
|
9
|
+
return fallbackText ?? key;
|
|
10
|
+
return translate(key, options) ?? fallbackText ?? key;
|
|
11
11
|
}
|