languages_directory = apply_filters( 'charitable_languages_directory', 'charitable/i18n/languages' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- plugin_locale is a WordPress core hook used for plugin localization. $this->locale = apply_filters( 'plugin_locale', get_locale(), $this->textdomain ); $this->mofile = sprintf( '%1$s-%2$s.mo', $this->textdomain, $this->locale ); add_action( 'change_locale', array( $this, 'load_textdomain' ) ); add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 20 ); } /** * Returns and/or create the single instance of this class. * * @since 1.2.0 * * @return Charitable_i18n */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Create class object. * * @since 1.1.2 * @version 1.8.9.1 * * @return void */ public function load_textdomain() { foreach ( array( 'global', 'local' ) as $source ) { $mofile_path = $this->get_mofile_path( $source ); if ( ! file_exists( $mofile_path ) ) { continue; } load_textdomain( $this->textdomain, $mofile_path ); } // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound load_plugin_textdomain( $this->textdomain, false, $this->languages_directory ); } /** * Whether decline months is on or off. * * @since 1.6.35 * * @return boolean */ public function decline_months() { if ( ! isset( $this->decline_months ) ) { $this->decline_months = 'on' === _x( 'off', 'decline months names: on or off', 'charitable' ); } return $this->decline_months; } /** * Return the date format to use for datepickers, based * on whether decline months is on. * * @since 1.6.35 * * @param string $default The format to use when decline months is off. * @return string */ public function get_datepicker_format( $default = 'F d, Y' ) { // phpcs:ignore if ( ! $this->decline_months() ) { return $default; } /** * Filter the date format used for datepickers * when decline months is on. * * @since 1.6.35 * * @param string $format The date format to use. * @param string $default The format that would be used if decline months is off. */ return apply_filters( 'charitable_datepicker_date_format_decline_months', 'Y-m-d', $default ); } /** * Return the Javascript date format to use for datepickers, * based on whether decline months is on. * * @since 1.6.35 * * @param string $default The format to use when decline months is off. * @return string */ public function get_js_datepicker_format( $default = 'MM d, yy' ) { // phpcs:ignore if ( ! $this->decline_months() ) { return $default; } /** * Filter the Javascript date format used for datepickers * when decline months is on. * * @since 1.6.35 * * @param string $format The date format to use. * @param string $default The format that would be used if decline months is off. */ return apply_filters( 'charitable_datepicker_date_format_decline_months', 'yy-mm-dd', $default ); } /** * Get the path to the MO file. * * @since 1.1.2 * * @param string $source Either 'local' or 'global'. * @return string */ private function get_mofile_path( $source = 'local' ) { // phpcs:ignore if ( 'global' == $source ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return WP_LANG_DIR . '/' . $this->textdomain . '/' . $this->mofile; } return trailingslashit( $this->languages_directory ) . $this->mofile; } } endif;