-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathStringsTranslations.php
42 lines (39 loc) · 1.09 KB
/
StringsTranslations.php
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
<?php
namespace WPGraphQL\Extensions\Polylang;
class StringsTranslations
{
function init()
{
add_action(
'graphql_register_types',
[$this, '__action_graphql_register_types'],
10,
0
);
}
function __action_graphql_register_types()
{
register_graphql_field('RootQuery', 'translateString', [
'type' => 'String',
'description' => __(
'Translate string using pll_translate_string() (Polylang)',
'wp-graphql-polylang'
),
'args' => [
'string' => [
'type' => [
'non_null' => 'String',
],
],
'language' => [
'type' => [
'non_null' => 'LanguageCodeEnum',
],
],
],
'resolve' => function ($source, $args, $context, $info) {
return pll_translate_string($args['string'], $args['language']);
},
]);
}
}