/var/www/hkosl.com/aga/wp-content/plugins/wordpress-seo/inc/language-utils.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
<?php
/**
 * WPSEO plugin file.
 *
 * @package WPSEO\Internals
 * @since   5.9.0
 */

/**
 * Group of language utility methods for use by WPSEO.
 * All methods are static, this is just a sort of namespacing class wrapper.
 */
class WPSEO_Language_Utils {

    
/**
     * Returns the language part of a given locale, defaults to english when the $locale is empty.
     *
     * @param string $locale The locale to get the language of.
     *
     * @returns string The language part of the locale.
     */
    
public static function get_language$locale null ) {
        
$language 'en';

        if ( empty( 
$locale ) || ! is_string$locale ) ) {
            return 
$language;
        }

        
$locale_parts explode'_'$locale );

        if ( ! empty( 
$locale_parts[0] ) && ( strlen$locale_parts[0] ) === || strlen$locale_parts[0] ) === ) ) {
            
$language $locale_parts[0];
        }

        return 
$language;
    }

    
/**
     * Returns the user locale for the language to be used in the admin.
     *
     * WordPress 4.7 introduced the ability for users to specify an Admin language
     * different from the language used on the front end. This checks if the feature
     * is available and returns the user's language, with a fallback to the site's language.
     * Can be removed when support for WordPress 4.6 will be dropped, in favor
     * of WordPress get_user_locale() that already fallbacks to the site's locale.
     *
     * @returns string The locale.
     */
    
public static function get_user_locale() {
        if ( 
function_exists'get_user_locale' ) ) {
            return 
get_user_locale();
        }

        return 
get_locale();
    }

    
/**
     * Returns the full name for the sites' language.
     *
     * @return string The language name.
     */
    
public static function get_site_language_name() {
        require_once 
ABSPATH 'wp-admin/includes/translation-install.php';

        
$translations wp_get_available_translations();
        
$locale       get_locale();
        
$language     = isset( $translations$locale ] ) ? $translations$locale ]['native_name'] : 'English (US)';

        return 
$language;
    }
}