Completed
Push — develop ( d8be36...adf00f )
by Aristeides
02:34
created

Kirki_l10n::get_string()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Internationalization helper.
4
 *
5
 * @package     Kirki
6
 * @category    Core
7
 * @author      Aristeides Stathopoulos
8
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
9
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
10
 * @since       1.0
11
 */
12
13
/**
14
 * Handles translations
15
 */
16
class Kirki_l10n {
17
18
	/**
19
	 * The plugin textdomain
20
	 *
21
	 * @access protected
22
	 * @var string
23
	 */
24
	protected $textdomain = 'kirki';
25
26
	/**
27
	 * The class constructor.
28
	 * Adds actions & filters to handle the rest of the methods.
29
	 *
30
	 * @access public
31
	 */
32
	public function __construct() {
33
34
		add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
35
36
	}
37
38
	/**
39
	 * Load the plugin textdomain
40
	 *
41
	 * @access public
42
	 */
43
	public function load_textdomain() {
44
45
		if ( null !== $this->get_path() ) {
46
			load_textdomain( $this->textdomain, $this->get_path() );
47
		}
48
		load_plugin_textdomain( $this->textdomain, false, Kirki::$path . '/languages' );
49
50
	}
51
52
	/**
53
	 * Gets the path to a translation file.
54
	 *
55
	 * @access protected
56
	 * @return string Absolute path to the translation file.
57
	 */
58
	protected function get_path() {
59
		$path_found = false;
60
		$found_path = null;
61
		foreach ( $this->get_paths() as $path ) {
62
			if ( $path_found ) {
63
				continue;
64
			}
65
			$path = wp_normalize_path( $path );
66
			if ( file_exists( $path ) ) {
67
				$path_found = true;
68
				$found_path = $path;
69
			}
70
		}
71
72
		return $found_path;
73
74
	}
75
76
	/**
77
	 * Returns an array of paths where translation files may be located.
78
	 *
79
	 * @access protected
80
	 * @return array
81
	 */
82
	protected function get_paths() {
83
84
		return array(
85
			WP_LANG_DIR . '/' . $this->textdomain . '-' . get_locale() . '.mo',
86
			Kirki::$path . '/languages/' . $this->textdomain . '-' . get_locale() . '.mo',
87
		);
88
89
	}
90
}
91