PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Helpers / Language.php

Language.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Helpers/Language.php

81 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Helpers;
4
5 /**
6 * @since 3.0.0
7 */
8 class Language
9 {
10 /**
11 * @since 4.13.0 Added early return if the textdomain is loaded
12 * @since 3.0.0
13 */
14 public static function load()
15 {
16 if (is_textdomain_loaded('give')) {
17 return;
18 }
19
20 $giveRelativePath = self::getRelativePath();
21
22 $locale = is_admin() && !wp_doing_ajax() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
23 $locale = apply_filters('plugin_locale', $locale, 'give'); // Traditional WordPress plugin locale filter.
24
25 // Setup paths to current locale file.
26 $moFile = sprintf('%1$s-%2$s.mo', 'give', $locale);
27 $moFileLocal = trailingslashit(WP_PLUGIN_DIR) . $giveRelativePath . $moFile;
28 $moFileGlobal = trailingslashit(WP_LANG_DIR) . 'plugins/' . $moFile;
29
30 unload_textdomain('give');
31 if (file_exists($moFileGlobal)) {
32 load_textdomain('give', $moFileGlobal); // Look in global /wp-content/languages/plugins folder.
33 } elseif (file_exists($moFileLocal)) {
34 load_textdomain('give', $moFileLocal); // Look in local /wp-content/plugins/give/languages/ folder.
35 } else {
36 load_plugin_textdomain('give', false, $giveRelativePath); // Load the default language files.
37 }
38 }
39
40 /**
41 * @since 3.0.0
42 */
43 public static function setScriptTranslations($handle)
44 {
45 wp_set_script_translations($handle, 'give', trailingslashit(WP_PLUGIN_DIR) . self::getRelativePath());
46 }
47
48 /**
49 * Return the plugin language dir relative path, e.g. "give/languages/"
50 *
51 * @since 3.0.0
52 */
53 public static function getRelativePath(): string
54 {
55 $giveRelativePath = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/';
56 $giveRelativePath = ltrim(apply_filters('give_languages_directory', $giveRelativePath), '/\\');
57
58 return trailingslashit($giveRelativePath);
59 }
60
61 /**
62 * @since 3.22.0
63 */
64 public static function getLocale()
65 {
66 return apply_filters('givewp_locale', get_locale());
67 }
68
69 /**
70 * @since 3.22.0
71 */
72 public static function switchToLocale(string $locale)
73 {
74 if (empty($locale) || $locale == get_locale()) {
75 return;
76 }
77
78 switch_to_locale($locale);
79 }
80 }
81