Skip to content

Commit 01cfabd

Browse files
committed
test: type l10n helper overrides
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> (cherry picked from commit ea48b28) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent f81ca5a commit 01cfabd

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/tests/testHelpers/l10n.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55

66
import { 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+
*/
840
export 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} */
1851
const defaultTranslate = (_app, message, params) => interpolateL10n(message, params)
1952

53+
/** @type {L10nPlural} */
2054
const 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+
*/
2966
export const createL10nMock = ({
3067
t,
3168
translate,

0 commit comments

Comments
 (0)