ddw_wcde_load_custom_translations

Loading logic for (various) textdomains, based on different locations of the language files.

Description

(string) ddw_wcde_load_custom_translations( (array) $textdomains, (string) $slug, (constant) $extensions = FALSE, (bool) $neutral = false ); 

Returns (string)

Function load_textdomain() with given parameters.

Parameters (4)

0. $textdomains (array)
Array of used textdomains for a plugin.
1. $slug (string)
The given plugin folder/ file slug.
2. $extensions — Optional. (constant) => FALSE
For using this loading function for extensions.
3. $neutral — Optional. (bool) => false
If a plugin ignores formal/ informal variants, and is neutral..

Usage

  1. if ( !function_exists( 'ddw_wcde_load_custom_translations' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-german-de_de/includes/wcde-functions.php'; 
  3.  
  4. // Array of used textdomains for a plugin. 
  5. $textdomains = array(); 
  6.  
  7. // The given plugin folder/ file slug. 
  8. $slug = ''; 
  9.  
  10. // For using this loading function for extensions. 
  11. $extensions = FALSE; 
  12.  
  13. // If a plugin ignores formal/ informal variants, and is "neutral". 
  14. $neutral = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = ddw_wcde_load_custom_translations($textdomains, $slug, $extensions, $neutral); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/wcde-functions.php  
  1. function ddw_wcde_load_custom_translations( $textdomains, $slug, $extensions = FALSE, $neutral = FALSE ) { 
  2.  
  3. /** Get locale setting from WordPress */ 
  4. $locale = get_locale(); 
  5.  
  6. /** Set initial defaults */ 
  7. $variant_slug = ''; 
  8. $mofilepath = ''; 
  9.  
  10. /** Language variant checks - formal/ informal */ 
  11. if ( ! $extensions && ! ddw_wcde_woocommerce_is_informal() ) { 
  12.  
  13. $variant_slug = ( ! $neutral ) ? 'sie-version/' : ''; 
  14.  
  15. } elseif ( ! $extensions && ddw_wcde_woocommerce_is_informal() ) { 
  16.  
  17. $variant_slug = ( ! $neutral ) ? 'du-version/' : ''; 
  18.  
  19. } // end if 
  20.  
  21.  
  22. /** Making base slug filterable */ 
  23. $wcde_main_slug = 'woocommerce-de'; 
  24. $wcde_main_slug = apply_filters( 'wcde_filter_main_slug', esc_attr( $wcde_main_slug ) ); 
  25.  
  26. /** WP_LANG_DIR file path to check/ load */ 
  27. $wcde_wp_lang_dir_path = trailingslashit( WP_LANG_DIR ) . $wcde_main_slug . '/' . $slug . '/' . $variant_slug . $slug . '-' . $locale . '.mo'; 
  28.  
  29. /** WP_LANG_DIR custom file path to check/ load - especially for backwards compatibility */ 
  30. $wcde_wp_lang_dir_custom_path = trailingslashit( WP_LANG_DIR ) . 'woocommerce-de/custom/' . $slug . '-' . $locale . '.mo'; 
  31.  
  32. /** (Site) UPLOAD_DIR file path to check/ load */ 
  33. $wcde_upload_dir_path = ddw_wcde_get_site_upload_location( 'path' ) . $wcde_main_slug . '/' . $slug . '/' . $variant_slug . $slug . '-' . $locale . '.mo'; 
  34.  
  35. /** WP_PLUGIN_DIR file path to check/ load --- fallback to our plugin! */ 
  36. $wcde_plugindir_slug = apply_filters( 
  37. 'wcde_filter_plugindir_slug',  
  38. ); 
  39.  
  40. /** Set branch slug part */ 
  41. if ( $extensions ) { 
  42.  
  43. $wc_branch = 'wc-pomo-extensions'; 
  44.  
  45. } else { 
  46.  
  47. $wc_branch = ( ddw_wcde_woocommerce_current() ) ? 'wc-pomo' : 'wc-pomo-21x'; 
  48.  
  49. } // end if 
  50.  
  51. $wcde_plugin_path = trailingslashit( WP_PLUGIN_DIR ) . $wcde_plugindir_slug . trailingslashit( $wc_branch ) . $variant_slug . $slug . '-' . $locale . '.mo'; 
  52.  
  53.  
  54. /** (1) WP_LANG_DIR branch: */ 
  55. if ( is_readable( $wcde_wp_lang_dir_path ) ) { 
  56.  
  57. $mofilepath = $wcde_wp_lang_dir_path; 
  58.  
  59.  
  60. /** (2) WP_LANG_DIR custom branch: */ 
  61. elseif ( is_readable( $wcde_wp_lang_dir_custom_path ) ) { 
  62.  
  63. $mofilepath = $wcde_wp_lang_dir_custom_path; 
  64.  
  65.  
  66. /** (3) UPLOAD_DIR branch: */ 
  67. elseif ( is_readable( $wcde_upload_dir_path ) ) { 
  68.  
  69. $mofilepath = $wcde_upload_dir_path; 
  70.  
  71.  
  72. /** (4) Plugin standard branch: */ 
  73. elseif ( is_readable( $wcde_plugin_path ) ) { 
  74.  
  75. $mofilepath = $wcde_plugin_path; 
  76.  
  77. } // end if/ elseif language location folders 
  78.  
  79.  
  80. /** Prepare for output oftranslations*/ 
  81. if ( $mofilepath ) { 
  82.  
  83. /** Repeat for every given textdomain of our array */ 
  84. foreach ( (array) $textdomains as $textdomain ) { 
  85.  
  86. /** Finally load every textdomain from the given .mo file path */ 
  87. load_textdomain( $textdomain, $mofilepath ); 
  88.  
  89. } // end foreach 
  90.  
  91. } // end if 
  92.  
  93. } // end of function ddw_wcde_load_custom_translations