File size: 3,170 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// // This file is just an example of different translation requests that will be parsed as part of the test. This file itself doesn't need to actually work. :-)
/*eslint-disable */
/* global i18n:false, howManyHats, getCity, getZip, React */
function test() {
	// simplest case... just a translation, no special options
	var content = i18n.translate( 'My hat has three corners.' );

	// or it could also be called like this
	content = i18n.translate( { original: 'My hat has three corners too.' } );

	// pluralization
	var numHats = howManyHats(); // returns integer
	content = i18n.translate( {
		original: {
			single: 'My hat has four corners.',
			plural: 'My hats have five corners.',
			count: numHats,
		},
	} );

	// Should be merged in POT with the pluralized form
	content = i18n.translate( { original: 'My hat has four corners.' } );

	// Should catch template literals
	content = i18n.translate( `My hat has six corners.` );
	content = i18n.translate( `My hat
has seventeen
corners.` );

	// providing context
	content = i18n.translate( {
		original: 'post',
		context: 'verb',
	} );

	// passing string as initial argument
	content = i18n.translate( 'post2', { context: 'verb2' } );

	// add a comment to the translator
	content = i18n.translate( {
		original: 'g:i:s a',
		comment: 'draft saved date format, see http://php.net/date',
	} );

	// sprintf-style string substitution
	// NOTE: You can also pass args as an array,
	// although named arguments are more explicit and encouraged
	// See http://www.diveintojavascript.com/projects/javascript-sprintf
	var city = getCity(), // returns string
		zip = getZip(); // returns string

	content = i18n.translate( {
		original: 'Your city is %(city)s and your zip is %(zip)s.',
		args: {
			city,
			zip,
		},
	} );

	// test the new syntax for translating plurals
	content = i18n.translate( 'single test', 'plural test', { count: 1 } );

	// count should accept a variable placeholder
	var varCount = 1;
	content = i18n.translate( 'single test2', 'plural test2', { count: varCount } );

	// test the ability to break strings to multiple lines
	// prettier-ignore
	content = <div>{ i18n.translate(
		"This is a multi-line translation with \"mixed quotes\" " +
		'and mixed \'single quotes\''
	) }</div>;

	content = this.translate( 'The string key text', {
		context: 'context with a literal string key',
	} );

	i18n.translate( 'My hat has three corners.', {
		comment: 'Second ocurrence',
	} );

	i18n.translate( 'My hat has one corner.', 'My hat has many corners.', {
		context: 'context after new plural syntax',
		count: 5,
	} );
	i18n.translate( 'This is how the test performed\u2026' );

	i18n.translate(
		"It's been %(timeLapsed)s since {{href}}{{postTitle/}}{{/href}} was published. Here's how the post has performed so far\u2026",
		{
			args: {
				timeLapsed: postTime.fromNow( true ),
			},
			components: {
				href: <a href={ post.URL } target="_blank" rel="noopener noreferrer" />,
				postTitle: <b>{ postTitle }</b>,
			},
			context:
				'Stats: Sentence showing how much time has passed since the last post, and how the stats are',
		}
	);
}

module.exports = test;
/*eslint-enable */