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
<?php
namespace SIW;
class i18n {
public static function init() {
$self = new self();
add_filter( 'load_textdomain_mofile', [ $self, 'load_custom_translations'], 10, 2 );
load_plugin_textdomain( 'siw', false, SIW_PLUGIN_DIR . 'languages/siw/' );
}
public function load_custom_translations( string $mofile, string $domain ) {
$textdomains['nl_NL'] = [ 'woocommerce', 'pinnacle' ];
$textdomains['en_US'] = [ 'siw' ];
$locale = is_admin() ? get_user_locale() : get_locale();
if ( isset( $textdomains[ $locale ] ) && in_array( $domain, $textdomains[ $locale ] ) ) {
$custom_mofile = SIW_PLUGIN_DIR . "languages/{$domain}/{$locale}.mo";
$mofile = file_exists( $custom_mofile ) ? $custom_mofile : $mofile;
}
return $mofile;
}
public static function get_translated_page_url( int $page_id ) {
$translated_page_id = self::get_translated_page_id( $page_id );
return get_page_link( $translated_page_id );
}
public static function get_translated_page_id( int $page_id ) {
return apply_filters( 'wpml_object_id', $page_id, 'page', true );
}
public static function get_translated_permalink( string $permalink, string $language_code ) {
return apply_filters( 'wpml_permalink', $permalink, $language_code );
}
public static function is_default_language() {
return ( apply_filters( 'wpml_current_language', NULL ) == apply_filters( 'wpml_default_language', NULL ) );
}
public static function get_current_language() {
return apply_filters( 'wpml_current_language', NULL );
}
public static function get_default_language() {
return apply_filters( 'wpml_default_language', NULL );
}
public static function get_active_languages() {
return apply_filters( 'wpml_active_languages', null );
}
}