PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / helpers / language-helper.php

language-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/helpers/language-helper.php

84 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Helpers;
4
5 use WPSEO_Language_Utils;
6 use Yoast\WP\SEO\Config\Researcher_Languages;
7
8 /**
9 * A helper object for language features.
10 */
11 class Language_Helper {
12
13 /**
14 * The languages with inclusive language analysis support.
15 *
16 * @var string[]
17 */
18 public static $languages_with_inclusive_language_support = [ 'en' ];
19
20 /**
21 * Checks whether word form recognition is active for the used language.
22 *
23 * @param string $language The used language.
24 *
25 * @return bool Whether word form recognition is active for the used language.
26 */
27 public function is_word_form_recognition_active( $language ) {
28 $supported_languages = [ 'de', 'en', 'es', 'fr', 'it', 'nl', 'ru', 'id', 'pt', 'pl', 'ar', 'sv', 'he', 'hu', 'nb', 'tr', 'cs', 'sk', 'el', 'ja' ];
29
30 return \in_array( $language, $supported_languages, true );
31 }
32
33 /**
34 * Checks whether the given language has function word support.
35 * (E.g. function words are used or filtered out for this language when doing some SEO and readability assessments).
36 *
37 * @param string $language The language to check.
38 *
39 * @return bool Whether the language has function word support.
40 */
41 public function has_function_word_support( $language ) {
42 $supported_languages = [ 'en', 'de', 'nl', 'fr', 'es', 'it', 'pt', 'ru', 'pl', 'sv', 'id', 'he', 'ar', 'hu', 'nb', 'tr', 'cs', 'sk', 'fa', 'el', 'ja' ];
43
44 return \in_array( $language, $supported_languages, true );
45 }
46
47 /**
48 * Checks whether the given language has inclusive language support.
49 *
50 * @param string $language The language to check if inclusive language is supported.
51 *
52 * @return bool Whether the language has inclusive language support.
53 */
54 public function has_inclusive_language_support( $language ) {
55 return \in_array( $language, self::$languages_with_inclusive_language_support, true );
56 }
57
58 /**
59 * Checks whether we have a specific researcher for the current locale and returns that language.
60 * If there is no researcher for the current locale, returns default as the researcher.
61 *
62 * @return string The language to use to select a researcher.
63 */
64 public function get_researcher_language() {
65 $researcher_language = WPSEO_Language_Utils::get_language( \get_locale() );
66 $supported_languages = Researcher_Languages::SUPPORTED_LANGUAGES;
67
68 if ( ! \in_array( $researcher_language, $supported_languages, true ) ) {
69 $researcher_language = 'default';
70 }
71 return $researcher_language;
72 }
73
74 /**
75 * Returns The site language code without region
76 * (e.g. 'en' for 'en_US' or 'en_GB').
77 *
78 * @return string The site language code without region.
79 */
80 public function get_language() {
81 return WPSEO_Language_Utils::get_language( \get_locale() );
82 }
83 }
84