| 1 |
<?php |
| 2 |
/** |
| 3 |
* Internationalization class |
| 4 |
* |
| 5 |
* @package micropackage/internationalization |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Micropackage\Internationalization; |
| 9 |
|
| 10 |
/** |
| 11 |
* Internationalization class |
| 12 |
*/ |
| 13 |
class Internationalization { |
| 14 |
|
| 15 |
/** |
| 16 |
* Textdomain |
| 17 |
* |
| 18 |
* @since 1.0.0 |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
protected $textdomain; |
| 22 |
|
| 23 |
/** |
| 24 |
* Full path to language files directory |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
protected $lang_dir; |
| 30 |
|
| 31 |
/** |
| 32 |
* Constructor |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @param string $textdomain Textdomain. |
| 36 |
* @param string $full_lang_dir_path Full path to language files directory. |
| 37 |
*/ |
| 38 |
public function __construct( $textdomain, $full_lang_dir_path ) { |
| 39 |
$this->textdomain = $textdomain; |
| 40 |
$this->lang_dir = trailingslashit( $full_lang_dir_path ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Loads the translation |
| 45 |
* The file has to be named: {textdomain}-{locale_LOCALE}.mo |
| 46 |
* |
| 47 |
* @action init |
| 48 |
* |
| 49 |
* @since 1.0.0 |
| 50 |
* @return bool Whether the translation has been loaded or not. |
| 51 |
*/ |
| 52 |
public function load_translation() { |
| 53 |
$mo_file = sprintf( '%s%s-%s.mo', $this->lang_dir, $this->textdomain, determine_locale() ); |
| 54 |
return load_textdomain( $this->textdomain, $mo_file ); |
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
|