Нема описа

l10n.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Determine the current locale desired for the request.
  4. *
  5. * @since 5.0.0
  6. *
  7. * @global string $pagenow
  8. *
  9. * @return string The determined locale.
  10. */
  11. if ( ! function_exists( 'determine_locale' ) ) :
  12. function determine_locale() {
  13. /**
  14. * Filters the locale for the current request prior to the default determination process.
  15. *
  16. * Using this filter allows to override the default logic, effectively short-circuiting the function.
  17. *
  18. * @since 5.0.0
  19. *
  20. * @param string|null The locale to return and short-circuit, or null as default.
  21. */
  22. $determined_locale = apply_filters( 'pre_determine_locale', null );
  23. if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
  24. return $determined_locale;
  25. }
  26. $determined_locale = get_locale();
  27. if ( function_exists( 'get_user_locale' ) && is_admin() ) {
  28. $determined_locale = get_user_locale();
  29. }
  30. if ( function_exists( 'get_user_locale' ) && isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] ) {
  31. $determined_locale = get_user_locale();
  32. }
  33. if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
  34. $determined_locale = sanitize_text_field( $_GET['wp_lang'] );
  35. }
  36. /**
  37. * Filters the locale for the current request.
  38. *
  39. * @since 5.0.0
  40. *
  41. * @param string $locale The locale.
  42. */
  43. return apply_filters( 'determine_locale', $determined_locale );
  44. }
  45. endif;
  46. /*
  47. * acf_get_locale
  48. *
  49. * Returns the current locale.
  50. *
  51. * @date 16/12/16
  52. * @since 5.5.0
  53. *
  54. * @param void
  55. * @return string
  56. */
  57. function acf_get_locale() {
  58. // Determine local.
  59. $locale = determine_locale();
  60. // Fallback to parent language for regions without translation.
  61. // https://wpastra.com/docs/complete-list-wordpress-locale-codes/
  62. $langs = array(
  63. 'az_TR' => 'az', // Azerbaijani (Turkey)
  64. 'zh_HK' => 'zh_TW', // Chinese (Hong Kong)
  65. 'nl_BE' => 'nl_NL', // Dutch (Belgium)
  66. 'fr_BE' => 'fr_FR', // French (Belgium)
  67. 'nn_NO' => 'nb_NO', // Norwegian (Nynorsk)
  68. 'fa_AF' => 'fa_IR', // Persian (Afghanistan)
  69. 'ru_UA' => 'ru_RU', // Russian (Ukraine)
  70. );
  71. if ( isset( $langs[ $locale ] ) ) {
  72. $locale = $langs[ $locale ];
  73. }
  74. /**
  75. * Filters the determined local.
  76. *
  77. * @date 8/1/19
  78. * @since 5.7.10
  79. *
  80. * @param string $locale The local.
  81. */
  82. return apply_filters( 'acf/get_locale', $locale );
  83. }
  84. /**
  85. * acf_load_textdomain
  86. *
  87. * Loads the plugin's translated strings similar to load_plugin_textdomain().
  88. *
  89. * @date 8/1/19
  90. * @since 5.7.10
  91. *
  92. * @param string $locale The plugin's current locale.
  93. * @return void
  94. */
  95. function acf_load_textdomain( $domain = 'acf' ) {
  96. /**
  97. * Filters a plugin's locale.
  98. *
  99. * @date 8/1/19
  100. * @since 5.7.10
  101. *
  102. * @param string $locale The plugin's current locale.
  103. * @param string $domain Text domain. Unique identifier for retrieving translated strings.
  104. */
  105. $locale = apply_filters( 'plugin_locale', acf_get_locale(), $domain );
  106. $mofile = $domain . '-' . $locale . '.mo';
  107. // Try to load from the languages directory first.
  108. if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
  109. return true;
  110. }
  111. // Load from plugin lang folder.
  112. return load_textdomain( $domain, acf_get_path( 'lang/' . $mofile ) );
  113. }
  114. /**
  115. * _acf_apply_language_cache_key
  116. *
  117. * Applies the current language to the cache key.
  118. *
  119. * @date 23/1/19
  120. * @since 5.7.11
  121. *
  122. * @param string $key The cache key.
  123. * @return string
  124. */
  125. function _acf_apply_language_cache_key( $key ) {
  126. // Get current language.
  127. $current_language = acf_get_setting( 'current_language' );
  128. if ( $current_language ) {
  129. $key = "{$key}:{$current_language}";
  130. }
  131. // Return key.
  132. return $key;
  133. }
  134. // Hook into filter.
  135. add_filter( 'acf/get_cache_key', '_acf_apply_language_cache_key' );