Form
2 years ago
Frontend
2 years ago
Gateways
4 years ago
ArrayDataSet.php
4 years ago
Call.php
3 years ago
Date.php
4 years ago
EnqueueScript.php
4 years ago
Hooks.php
4 years ago
Html.php
4 years ago
IntlTelInput.php
2 years ago
Language.php
2 years ago
Table.php
4 years ago
Utils.php
1 year ago
Language.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Helpers; |
| 4 | |
| 5 | /** |
| 6 | * @since 3.0.0 |
| 7 | */ |
| 8 | class Language |
| 9 | { |
| 10 | /** |
| 11 | * @since 3.0.0 |
| 12 | */ |
| 13 | public static function load() |
| 14 | { |
| 15 | $giveRelativePath = self::getRelativePath(); |
| 16 | |
| 17 | $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
| 18 | $locale = apply_filters('plugin_locale', $locale, 'give'); // Traditional WordPress plugin locale filter. |
| 19 | |
| 20 | // Setup paths to current locale file. |
| 21 | $moFile = sprintf('%1$s-%2$s.mo', 'give', $locale); |
| 22 | $moFileLocal = trailingslashit(WP_PLUGIN_DIR) . $giveRelativePath . $moFile; |
| 23 | $moFileGlobal = trailingslashit(WP_LANG_DIR) . 'plugins/' . $moFile; |
| 24 | |
| 25 | unload_textdomain('give'); |
| 26 | if (file_exists($moFileGlobal)) { |
| 27 | load_textdomain('give', $moFileGlobal); // Look in global /wp-content/languages/plugins folder. |
| 28 | } elseif (file_exists($moFileLocal)) { |
| 29 | load_textdomain('give', $moFileLocal); // Look in local /wp-content/plugins/give/languages/ folder. |
| 30 | } else { |
| 31 | load_plugin_textdomain('give', false, $giveRelativePath); // Load the default language files. |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @since 3.0.0 |
| 37 | */ |
| 38 | public static function setScriptTranslations($handle) |
| 39 | { |
| 40 | wp_set_script_translations($handle, 'give', trailingslashit(WP_PLUGIN_DIR) . self::getRelativePath()); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Return the plugin language dir relative path, e.g. "give/languages/" |
| 45 | * |
| 46 | * @since 3.0.0 |
| 47 | */ |
| 48 | public static function getRelativePath(): string |
| 49 | { |
| 50 | $giveRelativePath = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/'; |
| 51 | $giveRelativePath = ltrim(apply_filters('give_languages_directory', $giveRelativePath), '/\\'); |
| 52 | |
| 53 | return trailingslashit($giveRelativePath); |
| 54 | } |
| 55 | } |
| 56 |