File size: 698 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Locator } from 'playwright';

/**
 * Translate string by evaluating the `wp.i18n__` translate function from the page.
 */
export async function translateFromPage(
	locator: Locator,
	string: string,
	context?: string
): Promise< string > {
	return (
		locator.evaluate(
			// eslint-disable-next-line @wordpress/i18n-no-variables
			( _el, [ string, context ] ) =>
				context === undefined
					? // eslint-disable-next-line @wordpress/i18n-no-variables
					  ( window as any )?.wp?.i18n?.__( string )
					: // eslint-disable-next-line @wordpress/i18n-no-variables
					  ( window as any )?.wp?.i18n?._x( string, context ),
			[ string, context ]
		) || Promise.resolve( string )
	);
}