@discord/intl 0.0.6-rc.2 → 0.0.8
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/dist/intl-manager.d.ts +9 -0
- package/dist/intl-manager.js +11 -0
- package/dist/message-loader.d.ts +2 -2
- package/package.json +1 -1
- package/src/intl-manager.ts +30 -0
- package/src/message-loader.ts +2 -2
package/dist/intl-manager.d.ts
CHANGED
|
@@ -60,6 +60,15 @@ export declare class IntlManager<DefaultElements extends RichTextElementMap, Def
|
|
|
60
60
|
*/
|
|
61
61
|
formatToPlainString<T extends TypedIntlMessageGetter<object | undefined>>(message: T): string;
|
|
62
62
|
formatToPlainString<T extends TypedIntlMessageGetter<object | undefined>>(message: T, values: Omit<FormatValuesFor<T>, DefaultValues>): string;
|
|
63
|
+
/**
|
|
64
|
+
* Similar to `formatToPlainString`, format the given message with the provided
|
|
65
|
+
* values, but convert all rich text formatting back to Markdown syntax rather
|
|
66
|
+
* than rendering the actual rich content. The result is a plain string that
|
|
67
|
+
* can be sent through a separate Markdown renderer to get an equivalent
|
|
68
|
+
* result to formatting this message directly.
|
|
69
|
+
*/
|
|
70
|
+
formatToMarkdownString<T extends TypedIntlMessageGetter<object | undefined>>(message: T): string;
|
|
71
|
+
formatToMarkdownString<T extends TypedIntlMessageGetter<object | undefined>>(message: T, values: Omit<FormatValuesFor<T>, DefaultValues>): string;
|
|
63
72
|
}
|
|
64
73
|
/**
|
|
65
74
|
* Create a new MessageLoader, which handles lazily loading messages for
|
package/dist/intl-manager.js
CHANGED
|
@@ -138,6 +138,17 @@ var IntlManager = /** @class */ (function () {
|
|
|
138
138
|
// will be removed from the string anyway.
|
|
139
139
|
return resolvedMessage.formatToPlainString(this.intl.formatters, this.intl.formats, values);
|
|
140
140
|
};
|
|
141
|
+
IntlManager.prototype.formatToMarkdownString = function (message, values) {
|
|
142
|
+
// TODO(faulty): Implement the markdown syntax conversion here.
|
|
143
|
+
if (typeof message === 'string')
|
|
144
|
+
return message;
|
|
145
|
+
var resolvedMessage = message(this.currentLocale);
|
|
146
|
+
if (typeof resolvedMessage === 'string')
|
|
147
|
+
return resolvedMessage;
|
|
148
|
+
// No need to pass in `defaultRichTextElements`, since the stylistic tags
|
|
149
|
+
// will be removed from the string anyway.
|
|
150
|
+
return resolvedMessage.formatToPlainString(this.intl.formatters, this.intl.formats, values);
|
|
151
|
+
};
|
|
141
152
|
return IntlManager;
|
|
142
153
|
}());
|
|
143
154
|
exports.IntlManager = IntlManager;
|
package/dist/message-loader.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare class MessageLoader {
|
|
|
53
53
|
*
|
|
54
54
|
* @private
|
|
55
55
|
*/
|
|
56
|
-
_debugKeyMap
|
|
56
|
+
_debugKeyMap?: Record<string, string>;
|
|
57
57
|
/**
|
|
58
58
|
* Map of locale names to source file names, used to provide context for where messages are
|
|
59
59
|
* imported from during development.
|
|
@@ -62,7 +62,7 @@ export declare class MessageLoader {
|
|
|
62
62
|
*
|
|
63
63
|
* @private
|
|
64
64
|
*/
|
|
65
|
-
_localeFileMap
|
|
65
|
+
_localeFileMap?: Record<string, string>;
|
|
66
66
|
constructor(messageKeys: string[], localeImportMap: LocaleImportMap, defaultLocale: LocaleId);
|
|
67
67
|
/**
|
|
68
68
|
* Provide additional debug information to use during development, providing additional context
|
package/package.json
CHANGED
package/src/intl-manager.ts
CHANGED
|
@@ -168,6 +168,36 @@ export class IntlManager<
|
|
|
168
168
|
values,
|
|
169
169
|
);
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Similar to `formatToPlainString`, format the given message with the provided
|
|
174
|
+
* values, but convert all rich text formatting back to Markdown syntax rather
|
|
175
|
+
* than rendering the actual rich content. The result is a plain string that
|
|
176
|
+
* can be sent through a separate Markdown renderer to get an equivalent
|
|
177
|
+
* result to formatting this message directly.
|
|
178
|
+
*/
|
|
179
|
+
formatToMarkdownString<T extends TypedIntlMessageGetter<object | undefined>>(message: T): string;
|
|
180
|
+
formatToMarkdownString<T extends TypedIntlMessageGetter<object | undefined>>(
|
|
181
|
+
message: T,
|
|
182
|
+
values: Omit<FormatValuesFor<T>, DefaultValues>,
|
|
183
|
+
): string;
|
|
184
|
+
formatToMarkdownString<T extends TypedIntlMessageGetter<object | undefined>>(
|
|
185
|
+
message: T,
|
|
186
|
+
values?: Omit<FormatValuesFor<T>, DefaultValues>,
|
|
187
|
+
) {
|
|
188
|
+
// TODO(faulty): Implement the markdown syntax conversion here.
|
|
189
|
+
if (typeof message === 'string') return message;
|
|
190
|
+
const resolvedMessage = message(this.currentLocale);
|
|
191
|
+
if (typeof resolvedMessage === 'string') return resolvedMessage;
|
|
192
|
+
|
|
193
|
+
// No need to pass in `defaultRichTextElements`, since the stylistic tags
|
|
194
|
+
// will be removed from the string anyway.
|
|
195
|
+
return resolvedMessage.formatToPlainString(
|
|
196
|
+
this.intl.formatters as Formatters,
|
|
197
|
+
this.intl.formats as Formats,
|
|
198
|
+
values,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
171
201
|
}
|
|
172
202
|
|
|
173
203
|
/**
|
package/src/message-loader.ts
CHANGED
|
@@ -64,7 +64,7 @@ export class MessageLoader {
|
|
|
64
64
|
*
|
|
65
65
|
* @private
|
|
66
66
|
*/
|
|
67
|
-
_debugKeyMap
|
|
67
|
+
_debugKeyMap?: Record<string, string>;
|
|
68
68
|
/**
|
|
69
69
|
* Map of locale names to source file names, used to provide context for where messages are
|
|
70
70
|
* imported from during development.
|
|
@@ -73,7 +73,7 @@ export class MessageLoader {
|
|
|
73
73
|
*
|
|
74
74
|
* @private
|
|
75
75
|
*/
|
|
76
|
-
_localeFileMap
|
|
76
|
+
_localeFileMap?: Record<string, string>;
|
|
77
77
|
|
|
78
78
|
constructor(messageKeys: string[], localeImportMap: LocaleImportMap, defaultLocale: LocaleId) {
|
|
79
79
|
this.messageKeys = messageKeys;
|