55
66import { vi } from 'vitest'
77
8+ /**
9+ * @typedef {Record<string, any> } L10nParams
10+ */
11+
12+ /**
13+ * @typedef {(...args: Array<any>) => string } L10nTranslate
14+ */
15+
16+ /**
17+ * @typedef {(...args: Array<any>) => string } L10nPlural
18+ */
19+
20+ /**
21+ * @typedef {{
22+ * t?: L10nTranslate,
23+ * translate?: L10nTranslate,
24+ * n?: L10nPlural,
25+ * translatePlural?: L10nPlural,
26+ * language?: string,
27+ * locale?: string,
28+ * isRTL?: boolean,
29+ * }} CreateL10nMockBaseOptions
30+ */
31+
32+ /**
33+ * @typedef {CreateL10nMockBaseOptions & Record<string, unknown> } CreateL10nMockOptions
34+ */
35+
36+ /**
37+ * @param {string } message
38+ * @param {L10nParams } [params]
39+ */
840export const interpolateL10n = ( message , params = { } ) => {
941 return message . replace ( / { ( \w + ) } / g, ( match , key ) => {
1042 if ( Object . prototype . hasOwnProperty . call ( params , key ) ) {
@@ -15,8 +47,10 @@ export const interpolateL10n = (message, params = {}) => {
1547 } )
1648}
1749
50+ /** @type {L10nTranslate } */
1851const defaultTranslate = ( _app , message , params ) => interpolateL10n ( message , params )
1952
53+ /** @type {L10nPlural } */
2054const defaultPlural = ( _app , singular , plural , count , params ) => {
2155 const message = count === 1 ? singular : plural
2256
@@ -26,6 +60,9 @@ const defaultPlural = (_app, singular, plural, count, params) => {
2660 } )
2761}
2862
63+ /**
64+ * @param {CreateL10nMockOptions } [options]
65+ */
2966export const createL10nMock = ( {
3067 t,
3168 translate,
0 commit comments