PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.12
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.12
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / locale / class-charitable-i18n.php

class-charitable-i18n.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.12, at includes/locale/class-charitable-i18n.php

223 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sets up translations for Charitable.
4 *
5 * @package Charitable/Classes/Charitable_i18n
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.1.2
10 * @version 1.6.35
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_i18n' ) ) :
19
20 /**
21 * Charitable_i18n
22 *
23 * @since 1.1.2
24 */
25 class Charitable_i18n {
26
27 /**
28 * The single instance of this class.
29 *
30 * @since 1.1.2
31 *
32 * @var Charitable_i18n|null
33 */
34 private static $instance = null;
35
36 /**
37 * Plugin's textdomain.
38 *
39 * @since 1.1.2
40 *
41 * @var string
42 */
43 protected $textdomain = 'charitable';
44
45 /**
46 * The path to the languages directory.
47 *
48 * @since 1.1.2
49 *
50 * @var string
51 */
52 protected $languages_directory;
53
54 /**
55 * The site locale.
56 *
57 * @since 1.1.2
58 *
59 * @var string
60 */
61 protected $locale;
62
63 /**
64 * The MO filename.
65 *
66 * @since 1.1.2
67 *
68 * @var string
69 */
70 protected $mofile;
71
72 /**
73 * Whether decline months names is on.
74 *
75 * @since 1.6.35
76 *
77 * @var boolean
78 */
79 private $decline_months;
80
81 /**
82 * Set up the class.
83 *
84 * @since 1.1.2
85 */
86 private function __construct() {
87 /**
88 * Customize the directory to use for translation files.
89 *
90 * @since 1.0.0
91 *
92 * @param string $directory The directory, relative to the WP_PLUGIN_DIR directory.
93 */
94 $this->languages_directory = apply_filters( 'charitable_languages_directory', 'charitable/i18n/languages' );
95 $this->locale = apply_filters( 'plugin_locale', get_locale(), $this->textdomain );
96 $this->mofile = sprintf( '%1$s-%2$s.mo', $this->textdomain, $this->locale );
97
98 add_action( 'change_locale', array( $this, 'load_textdomain' ) );
99 add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 20 );
100 }
101
102 /**
103 * Returns and/or create the single instance of this class.
104 *
105 * @since 1.2.0
106 *
107 * @return Charitable_i18n
108 */
109 public static function get_instance() {
110 if ( is_null( self::$instance ) ) {
111 self::$instance = new self();
112 }
113
114 return self::$instance;
115 }
116
117 /**
118 * Create class object.
119 *
120 * @since 1.1.2
121 *
122 * @return void
123 */
124 public function load_textdomain() {
125 foreach ( array( 'global', 'local' ) as $source ) {
126 $mofile_path = $this->get_mofile_path( $source );
127
128 if ( ! file_exists( $mofile_path ) ) {
129 continue;
130 }
131
132 load_textdomain( $this->textdomain, $mofile_path );
133 }
134
135 load_plugin_textdomain( $this->textdomain, false, $this->languages_directory );
136 }
137
138 /**
139 * Whether decline months is on or off.
140 *
141 * @since 1.6.35
142 *
143 * @return boolean
144 */
145 public function decline_months() {
146 if ( ! isset( $this->decline_months ) ) {
147 $this->decline_months = 'on' === _x( 'off', 'decline months names: on or off' );
148 }
149
150 return $this->decline_months;
151 }
152
153 /**
154 * Return the date format to use for datepickers, based
155 * on whether decline months is on.
156 *
157 * @since 1.6.35
158 *
159 * @param string $default The format to use when decline months is off.
160 * @return string
161 */
162 public function get_datepicker_format( $default = 'F d, Y' ) {
163 if ( ! $this->decline_months() ) {
164 return $default;
165 }
166
167 /**
168 * Filter the date format used for datepickers
169 * when decline months is on.
170 *
171 * @since 1.6.35
172 *
173 * @param string $format The date format to use.
174 * @param string $default The format that would be used if decline months is off.
175 */
176 return apply_filters( 'charitable_datepicker_date_format_decline_months', 'Y-m-d', $default );
177 }
178
179 /**
180 * Return the Javascript date format to use for datepickers,
181 * based on whether decline months is on.
182 *
183 * @since 1.6.35
184 *
185 * @param string $default The format to use when decline months is off.
186 * @return string
187 */
188 public function get_js_datepicker_format( $default = 'MM d, yy' ) {
189 if ( ! $this->decline_months() ) {
190 return $default;
191 }
192
193 /**
194 * Filter the Javascript date format used for datepickers
195 * when decline months is on.
196 *
197 * @since 1.6.35
198 *
199 * @param string $format The date format to use.
200 * @param string $default The format that would be used if decline months is off.
201 */
202 return apply_filters( 'charitable_datepicker_date_format_decline_months', 'yy-mm-dd', $default );
203 }
204
205 /**
206 * Get the path to the MO file.
207 *
208 * @since 1.1.2
209 *
210 * @param string $source Either 'local' or 'global'.
211 * @return string
212 */
213 private function get_mofile_path( $source = 'local' ) {
214 if ( 'global' == $source ) {
215 return WP_LANG_DIR . '/' . $this->textdomain . '/' . $this->mofile;
216 }
217
218 return trailingslashit( $this->languages_directory ) . $this->mofile;
219 }
220 }
221
222 endif;
223