Sin descripción

class-twentytwenty-non-latin-languages.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Non-latin language handling.
  4. *
  5. * Handle non-latin language styles.
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Twenty
  9. * @since Twenty Twenty 1.0
  10. */
  11. if ( ! class_exists( 'TwentyTwenty_Non_Latin_Languages' ) ) {
  12. /**
  13. * Language handling.
  14. *
  15. * @since Twenty Twenty 1.0
  16. */
  17. class TwentyTwenty_Non_Latin_Languages {
  18. /**
  19. * Get custom CSS.
  20. *
  21. * Return CSS for non-latin language, if available, or null
  22. *
  23. * @since Twenty Twenty 1.0
  24. *
  25. * @param string $type Whether to return CSS for the "front-end", "block-editor", or "classic-editor".
  26. * @return void
  27. */
  28. public static function get_non_latin_css( $type = 'front-end' ) {
  29. // Fetch site locale.
  30. $locale = get_bloginfo( 'language' );
  31. /**
  32. * Filters the fallback fonts for non-latin languages.
  33. *
  34. * @since Twenty Twenty 1.0
  35. *
  36. * @param array $font_family An array of locales and font families.
  37. */
  38. $font_family = apply_filters(
  39. 'twentytwenty_get_localized_font_family_types',
  40. array(
  41. // Arabic.
  42. 'ar' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  43. 'ary' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  44. 'azb' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  45. 'ckb' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  46. 'fa-IR' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  47. 'haz' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  48. 'ps' => array( 'Tahoma', 'Arial', 'sans-serif' ),
  49. // Chinese Simplified (China) - Noto Sans SC.
  50. 'zh-CN' => array( '\'PingFang SC\'', '\'Helvetica Neue\'', '\'Microsoft YaHei New\'', '\'STHeiti Light\'', 'sans-serif' ),
  51. // Chinese Traditional (Taiwan) - Noto Sans TC.
  52. 'zh-TW' => array( '\'PingFang TC\'', '\'Helvetica Neue\'', '\'Microsoft YaHei New\'', '\'STHeiti Light\'', 'sans-serif' ),
  53. // Chinese (Hong Kong) - Noto Sans HK.
  54. 'zh-HK' => array( '\'PingFang HK\'', '\'Helvetica Neue\'', '\'Microsoft YaHei New\'', '\'STHeiti Light\'', 'sans-serif' ),
  55. // Cyrillic.
  56. 'bel' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  57. 'bg-BG' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  58. 'kk' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  59. 'mk-MK' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  60. 'mn' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  61. 'ru-RU' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  62. 'sah' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  63. 'sr-RS' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  64. 'tt-RU' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  65. 'uk' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
  66. // Devanagari.
  67. 'bn-BD' => array( 'Arial', 'sans-serif' ),
  68. 'hi-IN' => array( 'Arial', 'sans-serif' ),
  69. 'mr' => array( 'Arial', 'sans-serif' ),
  70. 'ne-NP' => array( 'Arial', 'sans-serif' ),
  71. // Greek.
  72. 'el' => array( '\'Helvetica Neue\', Helvetica, Arial, sans-serif' ),
  73. // Gujarati.
  74. 'gu' => array( 'Arial', 'sans-serif' ),
  75. // Hebrew.
  76. 'he-IL' => array( '\'Arial Hebrew\'', 'Arial', 'sans-serif' ),
  77. // Japanese.
  78. 'ja' => array( 'sans-serif' ),
  79. // Korean.
  80. 'ko-KR' => array( '\'Apple SD Gothic Neo\'', '\'Malgun Gothic\'', '\'Nanum Gothic\'', 'Dotum', 'sans-serif' ),
  81. // Thai.
  82. 'th' => array( '\'Sukhumvit Set\'', '\'Helvetica Neue\'', 'Helvetica', 'Arial', 'sans-serif' ),
  83. // Vietnamese.
  84. 'vi' => array( '\'Libre Franklin\'', 'sans-serif' ),
  85. )
  86. );
  87. // Return if the selected language has no fallback fonts.
  88. if ( empty( $font_family[ $locale ] ) ) {
  89. return;
  90. }
  91. /**
  92. * Filters the elements to apply fallback fonts to.
  93. *
  94. * @since Twenty Twenty 1.0
  95. *
  96. * @param array $elements An array of elements for "front-end", "block-editor", or "classic-editor".
  97. */
  98. $elements = apply_filters(
  99. 'twentytwenty_get_localized_font_family_elements',
  100. array(
  101. 'front-end' => array( 'body', 'input', 'textarea', 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file__button', '.has-drop-cap:not(:focus)::first-letter', '.has-drop-cap:not(:focus)::first-letter', '.entry-content .wp-block-archives', '.entry-content .wp-block-categories', '.entry-content .wp-block-cover-image', '.entry-content .wp-block-latest-comments', '.entry-content .wp-block-latest-posts', '.entry-content .wp-block-pullquote', '.entry-content .wp-block-quote.is-large', '.entry-content .wp-block-quote.is-style-large', '.entry-content .wp-block-archives *', '.entry-content .wp-block-categories *', '.entry-content .wp-block-latest-posts *', '.entry-content .wp-block-latest-comments *', '.entry-content p', '.entry-content ol', '.entry-content ul', '.entry-content dl', '.entry-content dt', '.entry-content cite', '.entry-content figcaption', '.entry-content .wp-caption-text', '.comment-content p', '.comment-content ol', '.comment-content ul', '.comment-content dl', '.comment-content dt', '.comment-content cite', '.comment-content figcaption', '.comment-content .wp-caption-text', '.widget_text p', '.widget_text ol', '.widget_text ul', '.widget_text dl', '.widget_text dt', '.widget-content .rssSummary', '.widget-content cite', '.widget-content figcaption', '.widget-content .wp-caption-text' ),
  102. 'block-editor' => array( '.editor-styles-wrapper > *', '.editor-styles-wrapper p', '.editor-styles-wrapper ol', '.editor-styles-wrapper ul', '.editor-styles-wrapper dl', '.editor-styles-wrapper dt', '.editor-post-title__block .editor-post-title__input', '.editor-styles-wrapper .wp-block h1', '.editor-styles-wrapper .wp-block h2', '.editor-styles-wrapper .wp-block h3', '.editor-styles-wrapper .wp-block h4', '.editor-styles-wrapper .wp-block h5', '.editor-styles-wrapper .wp-block h6', '.editor-styles-wrapper .has-drop-cap:not(:focus)::first-letter', '.editor-styles-wrapper cite', '.editor-styles-wrapper figcaption', '.editor-styles-wrapper .wp-caption-text' ),
  103. 'classic-editor' => array( 'body#tinymce.wp-editor', 'body#tinymce.wp-editor p', 'body#tinymce.wp-editor ol', 'body#tinymce.wp-editor ul', 'body#tinymce.wp-editor dl', 'body#tinymce.wp-editor dt', 'body#tinymce.wp-editor figcaption', 'body#tinymce.wp-editor .wp-caption-text', 'body#tinymce.wp-editor .wp-caption-dd', 'body#tinymce.wp-editor cite', 'body#tinymce.wp-editor table' ),
  104. )
  105. );
  106. // Return if the specified type doesn't exist.
  107. if ( empty( $elements[ $type ] ) ) {
  108. return;
  109. }
  110. // Return the specified styles.
  111. return twentytwenty_generate_css( implode( ',', $elements[ $type ] ), 'font-family', implode( ',', $font_family[ $locale ] ), null, null, false );
  112. }
  113. }
  114. }