Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function myPluginGetCurrentLanguageCode()
- {
- $currentLanguage = null;
- $myPluginWPLANG = get_option('WPLANG', 'en_US');
- if (empty($myPluginWPLANG) || strlen($myPluginWPLANG) <= 1) {
- $myPluginWPLANG = 'en';
- }
- if (defined('ICL_LANGUAGE_CODE') || defined('POLYLANG_FILE')) {
- // Polylang
- if (function_exists('pll_current_language')) {
- $currentLanguage = pll_current_language();
- // If currentLanguage is still empty, we have to get the default language
- if (empty($currentLanguage)) {
- $currentLanguage = pll_default_language();
- }
- } else {
- // WPML
- $null = null;
- $currentLanguage = apply_filters('wpml_current_language', $null);
- }
- // Fallback
- if ($currentLanguage === 'all') {
- $currentLanguage = $myPluginWPLANG;
- }
- } else {
- $currentLanguage = $myPluginWPLANG;
- }
- return $currentLanguage;
- }
- load_plugin_textdomain('my-plugin', false, 'my-plugin/languages/');
- // Load correct DE language file if any DE language was selected
- if (in_array(myPluginGetCurrentLanguageCode(), ['de', 'de_DE', 'de_DE_formal', 'de_AT', 'de_CH', 'de_CH_informal'])) {
- // Load german language pack
- load_textdomain('my-plugin', 'full-path-to-your-plugin-folder/languages/my-plugin-de_DE.mo');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement