ddw_wcde_custom_strings_via_l10n_global

Helper function: Search for a specific translation string and add changed text.

Description

(string) ddw_wcde_custom_strings_via_l10n_global( (string) $option_key, (array) $strings, (string) $default_translation, (string) $base_domain = '' ); 

NOTE: Provides fallback to default value if option is empty. Also works for default installs ('en_US' locale).

Returns (string)

Changed string for display. Merged to global object $l10n/MO.

Parameters (4)

0. $option_key (string)
Option key of our own options array. [Upcoming!]
1. $strings (array)
Array of original text strings used by WooCommerce.
2. $default_translation (string)
A fallback default translation if the user setting may be empty.
3. $base_domain — Optional. (string) => ''
String of basis textdomain in which the string swap is executed. Fallback is woocommerce..

Usage

  1. if ( !function_exists( 'ddw_wcde_custom_strings_via_l10n_global' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-german-de_de/includes/wcde-functions.php'; 
  3.  
  4. // Option key of our own options array. [Upcoming!] 
  5. $option_key = ''; 
  6.  
  7. // Array of original text strings used by WooCommerce. 
  8. $strings = array(); 
  9.  
  10. // A fallback default translation if the 
  11. // user setting may be empty. 
  12. $default_translation = ''; 
  13.  
  14. // String of basis textdomain in which the string 
  15. // swap is executed. Fallback is 'woocommerce'. 
  16. $base_domain = ''; 
  17.  
  18. // NOTICE! Understand what this does before running. 
  19. $result = ddw_wcde_custom_strings_via_l10n_global($option_key, $strings, $default_translation, $base_domain); 
  20.  

Defined (1)

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

/includes/wcde-functions.php  
  1. function ddw_wcde_custom_strings_via_l10n_global( $option_key, $strings, $default_translation, $base_domain = '' ) { 
  2.  
  3. global $l10n; 
  4.  
  5. /** Get our option [Upcoming!] */ 
  6. //$wcde_options = get_option( 'wcde-options' ); 
  7.  
  8. $base_domain = ( empty( $base_domain ) || ! isset( $base_domain ) ) ? 'woocommerce' : esc_attr( $base_domain ); 
  9.  
  10. /** Perform string swap for each string of our array with keys/strings */ 
  11. foreach ( (array) $strings as $string ) { 
  12.  
  13. /** Set label logic */ 
  14. $custom_label = $default_translation; 
  15.  
  16. /** Tweak/add translation/custom label within 'woocommerce' textdomain */ 
  17. if ( isset( $l10n[ $base_domain ] ) 
  18. && isset( $l10n[ $base_domain ]->entries[ $string ] ) 
  19. ) { 
  20.  
  21. $l10n[ $base_domain ]->entries[ $string ]->translations[0] = $custom_label; 
  22.  
  23. } else { 
  24.  
  25. $mo = new MO(); 
  26.  
  27. $mo->add_entry( 
  28. array( 
  29. 'singular' => $string,  
  30. translations => array( $custom_label ) 
  31. ); 
  32.  
  33. if ( isset( $l10n[ $base_domain ] ) ) { 
  34.  
  35. $mo->merge_with( $l10n[ $base_domain ] ); 
  36.  
  37. } // end if 
  38.  
  39. $l10n[ $base_domain ] = &$mo; 
  40.  
  41. } // end if 
  42.  
  43. } // end foreach 
  44.  
  45. } // end of function ddw_wcde_custom_strings_via_l10n_global