Advertisement
borlabs

WordPress - Load German Language Pack

Jan 3rd, 2020
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. function myPluginGetCurrentLanguageCode()
  3. {
  4.     $currentLanguage = null;
  5.    
  6.     $myPluginWPLANG = get_option('WPLANG', 'en_US');
  7.  
  8.     if (empty($myPluginWPLANG) || strlen($myPluginWPLANG) <= 1) {
  9.         $myPluginWPLANG = 'en';
  10.     }
  11.    
  12.     if (defined('ICL_LANGUAGE_CODE') || defined('POLYLANG_FILE')) {
  13.        
  14.         // Polylang
  15.         if (function_exists('pll_current_language')) {
  16.  
  17.             $currentLanguage = pll_current_language();
  18.  
  19.             // If currentLanguage is still empty, we have to get the default language
  20.             if (empty($currentLanguage)) {
  21.                 $currentLanguage = pll_default_language();
  22.             }
  23.         } else {
  24.         // WPML
  25.             $null = null;
  26.             $currentLanguage = apply_filters('wpml_current_language', $null);
  27.         }
  28.  
  29.         // Fallback
  30.         if ($currentLanguage === 'all') {
  31.             $currentLanguage = $myPluginWPLANG;
  32.         }
  33.     } else {
  34.         $currentLanguage = $myPluginWPLANG;
  35.     }
  36.    
  37.     return $currentLanguage;
  38. }
  39.  
  40. load_plugin_textdomain('my-plugin', false, 'my-plugin/languages/');
  41.  
  42. // Load correct DE language file if any DE language was selected
  43. if (in_array(myPluginGetCurrentLanguageCode(), ['de', 'de_DE', 'de_DE_formal', 'de_AT', 'de_CH', 'de_CH_informal'])) {
  44.     // Load german language pack
  45.     load_textdomain('my-plugin', 'full-path-to-your-plugin-folder/languages/my-plugin-de_DE.mo');
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement