Skip to content

Commit e292c64

Browse files
committed
feat: Added basic MK support
1 parent d817ecf commit e292c64

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

lib/Core/Multi_Language.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ public function get_polylang_locale() {
124124
*/
125125
public function get_wpml_locale() {
126126
// Documented in WPML.
127-
return apply_filters( 'wpml_current_language', null ) === 'sr' ? 'sr_RS' : 'other';
127+
switch ( apply_filters( 'wpml_current_language', null ) ) {
128+
case 'sr':
129+
return 'sr_RS';
130+
case 'mk':
131+
return 'mk_MK';
132+
default:
133+
return 'other';
134+
}
128135
}
129136
}

lib/Core/Script_Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function is_serbian() {
104104
* @return bool True if the site should be transliterated, false otherwise
105105
*/
106106
public function should_transliterate() {
107-
return 'sr_RS' === $this->locale && 'lat' === $this->script;
107+
return in_array( $this->locale, array( 'mk_MK', 'sr_RS', 'bs_BA' ), true ) && 'lat' === $this->script;
108108
}
109109

110110
/**

lib/Language/WPML.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
* WPML Plugin compatibility
1212
*/
1313
class WPML {
14+
/**
15+
* Primary language
16+
*
17+
* @var string
18+
*/
19+
protected $primary_lang = null;
20+
1421
/**
1522
* Class constructor
1623
*/
@@ -29,7 +36,13 @@ public function extend_wpml_language_selector( $languages ) {
2936
return $languages;
3037
}
3138

32-
$serbian_ls = $languages['sr'];
39+
$this->primary_lang = $this->detect_primary_lang( $languages );
40+
41+
if ( 'sr' !== $this->primary_lang ) {
42+
return $languages;
43+
}
44+
45+
$serbian_ls = $languages['sr'] ?? $languages['mk'];
3346
$script = STL()->manager->get_script();
3447

3548
$languages['sr'] = array_merge(
@@ -54,4 +67,24 @@ public function extend_wpml_language_selector( $languages ) {
5467

5568
return $languages;
5669
}
70+
71+
/**
72+
* Detects primary language from WPML languages
73+
*
74+
* @param array<string, array> $languages WPML languages.
75+
* @return string Primary language
76+
*/
77+
protected function detect_primary_lang( $languages ) {
78+
$languages = array_keys( $languages );
79+
80+
if ( in_array( 'sr', $languages, true ) ) {
81+
return 'sr';
82+
}
83+
84+
if ( in_array( 'mk', $languages, true ) ) {
85+
return 'mk';
86+
}
87+
88+
return 'en';
89+
}
5790
}

0 commit comments

Comments
 (0)