This repository has been archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
language.php
96 lines (82 loc) · 2.74 KB
/
language.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
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
<?php
/**
* Function wrapper for register,unregister,get language and get string for WPML, Polylang and Ceceppa Multilingua
*
* example use https://gist.github.com/Mte90/fe687ceed408ab743238
*
* @author Mte90 <[email protected]>
* @license GPL-2.0+
* @copyright 2014-2015
*/
if ( !function_exists( 'get_language' ) ) {
/**
* Return the language 2-4 letters code
*
* @since 1.0.0
*
* @return string 4 letters cod of the locale
*/
function get_language() {
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
return ICL_LANGUAGE_CODE;
} elseif ( function_exists( 'pll_current_language' ) ) {
return pll_current_language();
}
// Return a 2-4 letters code
return get_locale();
}
}
if ( !function_exists( 'register_string' ) ) {
/**
* Add registration for multilanguage string (contain hook)
*
* @since 1.0.0
*
* @param string $plugin_name_human_format The Plugin name .
* @param string $string_name The name of the string.
* @param string $value The value.
*/
function register_string( $plugin_name_human_format, $string_name, $value ) {
if ( function_exists( 'icl_register_string' ) ) {
icl_register_string( $plugin_name_human_format, $string_name, $value );
} elseif ( function_exists( 'pll_register_string' ) ) {
$plugin_name_human_format_replaced = str_replace( ' ', '-', $plugin_name_human_format );
pll_register_string( $plugin_name_human_format_replaced, $string_name );
}
}
}
if ( !function_exists( 'deregister_string' ) ) {
/**
* Unregister multilanguage string, Polylang missing support of this feature
*
* @since 1.0.0
*
* @param string $plugin_name_human_format The Plugin name.
* @param string $string_name The name of the string.
*/
function deregister_string( $plugin_name_human_format, $string_name ) {
if ( function_exists( 'icl_unregister_string' ) ) {
icl_unregister_string( $plugin_name_human_format, $string_name );
}
}
}
if ( !function_exists( 'get_string' ) ) {
/**
* Get multilanguage string
*
* @since 1.0.0
*
* @param string $plugin_name_human_format The Plugin name.
* @param string $string_name The name of the string.
* @param string $value The value.
* @return string The string
*/
function get_string( $plugin_name_human_format, $string_name, $value ) {
if ( function_exists( 'icl_t' ) ) {
return icl_t( $plugin_name_human_format, $string_name, $value );
} elseif ( function_exists( 'pll__' ) ) {
return pll__( $string_name );
}
return $value;
}
}