Newer
Older
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Wpct i18n
Adapter for multilingual wp plugins.
The plugin offers a coherent and consistent filters API to interact
with multiple translation plugins. Integrates with [WPML](https://wpml.org/)
and [Polylang](https://wordpress.org/plugins/polylang/).
## Installation
Download the [latest release](https://git.coopdevs.org/codeccoop/wp/plugins/wpct-i18n/-/releases/permalin/latest/downloads/plugins/wpct-i18n.zip)
as a zipfile. Once downloaded, decompress and place its content on your WP instance.
`wp-content/plugins`'s directory.
> Go to the [releases](https://git.coopdevs.org/codeccoop/wp/plugins/wpct-i18n/-/releases) page
> to find previous versions.
You can install it with `wp-cli` with the next command:
```shell
wp plugin install https://git.coopdevs.org/codeccoop/wp/plugins/wpct-i18n/-/releases/permalink/latest/downloads/plugins/wpct-i18n.zip
```
## API
### Getters
#### `wpct_i18n_default_language`
Get site default language.
Arguments:
1. `any $default`: Default value.
2. `string $format`: Locale or slug.
Returns:
1. `string $language`: Site current language.
Example:
```php
$language = apply_filter('wpct_i18n_default_language', null, 'slug');
echo $language;
```
#### `wpct_i18n_current_language`
Get site current language.
Arguments:
1. `any $default`: Default value.
2. `string $format`: Locale or slug.
Returns:
1. `string $language`: Site current language.
Example:
```php
$language = apply_filter('wpct_i18n_current_language', null, 'slug');
echo $language;
```
#### `wpct_i18n_active_languages`
Returns the site active languages.
Arguments:
1. `any $default`: Default value.
2. `string $format`: Locale or slug.
Returns:
1. `array $lang`: Active languages
Example:
```php
$languages = apply_filters('wpct_i18n_active_languages', [], 'slug');
foreach ($languages as $language) {
// do something
}
```
#### `wpct_i18n_post_language`
Get WP_Post language.
Arguments:
1. `any $default`: Default value.
2. `integer $post_id`: Post ID.
3. `string $format`: Locale or slug.
Returns:
1. `string $language`: Post's language.
Example:
```php
$lang = apply_filters('wpct_i18n_post_language', null, 10, 'locale');
if ($lang !== 'en_US') {
// do something
}
```
#### `wpct_i18n_post_translations`
Get WP_Post current translations.
Arguments:
1. `any $default`: Default value.
2. `integer $post_id`: Post ID.
Returns:
1. `array<string, integer>`: Array with languages and post IDs.
Example:
```php
$translations = apply_filters('wpct_i18n_post_translations', [], 10);
foreach ($translations as $lang => $trans_id) {
// do something
}
```
#### `wpct_i18n_term_translations`
Gets WP_Term current translations.
Arguments:
1. `any $default`: Default value.
2. `integer $term_id`: Term ID.
Returns:
1. `array<string, integer>`: Array with languages and term IDs.
Example:
```php
$translations = apply_filters('wpct_i18n_term_translations', [], 10);
foreach ($translations as $lang => $trans_id) {
// do something
}
```
#### `wpct_i18n_is_translation`
Get site default language.
Arguments:
1. `any $default`: Default value.
2. `integer $post_id`: Post ID.
Returns:
1. `boolean $is_translation`: True if post is a translation.
Example:
```php
$is_translation = apply_filters('wpct_i18n_is_translation', false, 274);
if ($is_translation) {
// do something
}
```
#### `wpct_i18n_translate_post`
Add a post translation to the given post.
Arguments:
1. `any $default`: Default value.
2. `WP_Post $post`: Post object.
3. `string $lang`: Language code.
Returns:
1. `integer $trans_id`: ID of the new translation.
Example:
```php
$trans_id = apply_filters('wpct_i18n_translate_post', null, 1, 'en');
echo $trans_id;
```
### Actions
#### `wpct_i18n_language_switcher`
Renders the integration language switcher.
Arguments:
1. `any $default`: Default value.
2. `boolean $echo`: Should return string or echo it.
Returns:
1. `string $html`: Language switcher rendered HTML.
Example:
```php
do_action('wpct_i18n_language_switcher', '', true);
```