|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { afterEach, describe, expect, it, beforeEach, vi } from 'vitest' |
| 7 | +import { createL10nMock, interpolateL10n } from '../testHelpers/l10n.js' |
7 | 8 | import { shallowMount } from '@vue/test-utils' |
8 | 9 | import axios from '@nextcloud/axios' |
9 | 10 | import { getCapabilities } from '@nextcloud/capabilities' |
@@ -97,36 +98,19 @@ vi.mock('@nextcloud/logger', () => ({ |
97 | 98 | })), |
98 | 99 | })) |
99 | 100 |
|
100 | | -vi.mock('@nextcloud/l10n', () => ({ |
101 | | - translate: vi.fn((app: string, text: string, vars?: Record<string, string>) => { |
102 | | - if (vars) { |
103 | | - return text.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key) |
104 | | - } |
105 | | - return text |
106 | | - }), |
107 | | - translatePlural: vi.fn((app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => { |
| 101 | +vi.mock('@nextcloud/l10n', () => createL10nMock({ |
| 102 | + t: (app: string, text: string, vars?: Record<string, string>) => { |
| 103 | + return interpolateL10n(text, vars) |
| 104 | + }, |
| 105 | + n: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => { |
108 | 106 | const template = count === 1 ? singular : plural |
109 | | - if (vars) { |
110 | | - return template.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key) |
111 | | - } |
112 | | - return template |
113 | | - }), |
114 | | - t: vi.fn((app: string, text: string, vars?: Record<string, string>) => { |
115 | | - if (vars) { |
116 | | - return text.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key) |
117 | | - } |
118 | | - return text |
119 | | - }), |
120 | | - n: vi.fn((app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => { |
| 107 | + return interpolateL10n(template, { count, ...(vars ?? {}) }) |
| 108 | + }, |
| 109 | + translate: (app: string, text: string, vars?: Record<string, string>) => interpolateL10n(text, vars), |
| 110 | + translatePlural: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => { |
121 | 111 | const template = count === 1 ? singular : plural |
122 | | - if (vars) { |
123 | | - return template.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key) |
124 | | - } |
125 | | - return template |
126 | | - }), |
127 | | - getLanguage: vi.fn(() => 'en'), |
128 | | - getLocale: vi.fn(() => 'en'), |
129 | | - isRTL: vi.fn(() => false), |
| 112 | + return interpolateL10n(template, { count, ...(vars ?? {}) }) |
| 113 | + }, |
130 | 114 | })) |
131 | 115 |
|
132 | 116 | // Mock router |
|
0 commit comments