PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Core/wordpress/language.php +48 -18 10.10.2 → 11.1.0 View file →
@@ -1,8 +1,10 @@
1 1 <?php
2 2
3 -global $acyWPLangCodes;
4 -$acyWPLangCodes = [
3 +defined('ABSPATH') || die('Restricted Access');
4 +
5 +global $acymWPLangCodes;
6 +$acymWPLangCodes = [
5 7 'af' => 'af-ZA',
6 8 'ar' => 'ar-AA',
7 9 'as' => 'as-AS', // Not sure
8 10 'az' => 'az-AZ', // Not sure
@@ -36,10 +38,16 @@
36 38 ];
37 39
38 40 global $acymLanguages;
39 41
42 +/**
43 + * Display the translation based on a key
44 + *
45 + * @param bool $interpretBackSlashes Deprecated Interpret or not the \ like \t \n etc...
46 + */
40 47 function acym_translation(string $key, bool $jsSafe = false, bool $interpretBackSlashes = true, string $textdomain = 'acymailing'): string
41 48 {
49 + // Return the key passed by default as it may be a random text instead of a key
42 50 $translation = $key;
43 51
44 52 global $acymLanguages;
45 53 acym_getLanguageTag();
@@ -52,19 +60,23 @@
52 60 break;
53 61 }
54 62 }
55 63
56 - global $customTranslation;
64 + global $acymailingCustomTranslation;
57 65 acym_getCustomTranslation();
58 66
59 - if (!empty($customTranslation) && isset($customTranslation[$key])) {
60 - $translation = $customTranslation[$key];
67 + if (!empty($acymailingCustomTranslation) && isset($acymailingCustomTranslation[$key])) {
68 + $translation = $acymailingCustomTranslation[$key];
61 69 } elseif (!empty($acymailingEnglishText)) {
70 + // If there is an english translation, get the WordPress translation. By default, it returns the text passed, so the english translation
71 + // phpcs:ignore WordPress.WP.I18n.MissingArgDomain,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
62 72 $translation = empty($textdomain) ? __($acymailingEnglishText) : __($acymailingEnglishText, $textdomain);
63 73
74 + // If there is no translation on the WordPress side, and we're not in english, take the AcyMailing community translation
64 75 if ($translation === $acymailingEnglishText && $acymLanguages['currentLanguage'] != ACYM_DEFAULT_LANGUAGE) {
65 76 foreach ($acymLanguages[$acymLanguages['currentLanguage']] as $fileContent) {
66 77 if (isset($fileContent[$key])) {
78 + // If a translation is found for the specified key, take it
67 79 $translation = $fileContent[$key];
68 80 break;
69 81 }
70 82 }
@@ -70,8 +82,9 @@
70 82 }
71 83 }
72 84 }
73 85
86 + // Escape the quotes if we're in a javascript context
74 87 if ($jsSafe) {
75 88 $translation = str_replace('"', '\"', $translation);
76 89 } elseif ($interpretBackSlashes && strpos($translation, '\\') !== false) {
77 90 $translation = str_replace(['\\\\', '\t', '\n'], ["\\", "\t", "\n"], $translation);
@@ -77,8 +90,9 @@
77 90 $translation = str_replace(['\\\\', '\t', '\n'], ["\\", "\t", "\n"], $translation);
78 91 }
79 92
80 93 if ($translation == $key) {
94 + // phpcs:ignore WordPress.WP.I18n.MissingArgDomain,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
81 95 $translation = empty($textdomain) ? __($translation) : __($translation, $textdomain);
82 96 }
83 97
84 98 return $translation;
@@ -92,8 +106,11 @@
92 106
93 107 return $previousLanguage;
94 108 }
95 109
110 +/**
111 + * Display the according translation
112 + */
96 113 function acym_translationSprintf(): string
97 114 {
98 115 $args = func_get_args();
99 116 $args[0] = acym_translation($args[0]);
@@ -102,9 +119,9 @@
102 119 }
103 120
104 121 function acym_getLanguages(bool $uppercaseLangCode = false, bool $published = false): array
105 122 {
106 - global $acyWPLangCodes;
123 + global $acymWPLangCodes;
107 124
108 125 $result = [];
109 126
110 127 require_once ABSPATH.'wp-admin/includes/translation-install.php';
@@ -111,9 +128,11 @@
111 128 $wplanguages = wp_get_available_translations();
112 129 $languages = get_available_languages();
113 130 foreach ($languages as $oneLang) {
114 131 $wpLangCode = $oneLang;
115 - if (!empty($acyWPLangCodes[$oneLang])) $oneLang = $acyWPLangCodes[$oneLang];
132 + if (!empty($acymWPLangCodes[$oneLang])) {
133 + $oneLang = $acymWPLangCodes[$oneLang];
134 + }
116 135 $langTag = str_replace('_', '-', $oneLang);
117 136
118 137 $lang = new stdClass();
119 138 $lang->sef = empty($wplanguages[$oneLang]['iso'][1]) ? null : $wplanguages[$oneLang]['iso'][1];
@@ -146,9 +165,9 @@
146 165 } else {
147 166 $currentLocale = get_locale();
148 167 }
149 168
150 - $currentLocale = convertWPLocaleToAcyLocale($currentLocale);
169 + $currentLocale = acym_convertWPLocaleToAcyLocale($currentLocale);
151 170
152 171 global $acymLanguages;
153 172 if (!isset($acymLanguages['currentLanguage'])) {
154 173 $acymLanguages['currentLanguage'] = $currentLocale;
@@ -156,13 +175,23 @@
156 175
157 176 return $simple ? substr($acymLanguages['currentLanguage'], 0, 2) : $acymLanguages['currentLanguage'];
158 177 }
159 178
179 +function acym_getSiteLanguageTag(bool $simple = false): string
180 +{
181 + $currentLocale = acym_convertWPLocaleToAcyLocale(get_locale());
182 +
183 + return $simple ? substr($currentLocale, 0, 2) : $currentLocale;
184 +}
185 +
160 186 function acym_getCustomTranslation()
161 187 {
162 - global $customTranslation;
163 - if (isset($customTranslation)) return;
164 - $customTranslation = [];
188 + global $acymailingCustomTranslation;
189 + if (isset($acymailingCustomTranslation)) {
190 + return;
191 + }
192 +
193 + $acymailingCustomTranslation = [];
165 194 $currentLanguage = acym_getLanguageTag();
166 195 $filePath = ACYM_LANGUAGE.$currentLanguage.'.'.ACYM_LANGUAGE_FILE.'_custom.ini';
167 196 if (file_exists($filePath)) {
168 197 $data = acym_fileGetContent($filePath);
@@ -173,9 +202,9 @@
173 202
174 203 $keyval = explode('=', $raw);
175 204 $key = array_shift($keyval);
176 205
177 - $customTranslation[$key] = trim(implode('=', $keyval), "\"\r\n\t ");
206 + $acymailingCustomTranslation[$key] = trim(implode('=', $keyval), "\"\r\n\t ");
178 207 }
179 208 }
180 209 }
181 210
@@ -239,19 +268,20 @@
239 268 {
240 269 return rtrim(ACYM_LANGUAGE, DS);
241 270 }
242 271
243 -function acym_languageOption(?string $emailLanguage, string $name): string
272 +function acym_languageOption(?string $emailLanguage, string $name): void
244 273 {
245 - return '';
246 274 }
247 275
248 -function convertWPLocaleToAcyLocale(string $locale): string
276 +function acym_convertWPLocaleToAcyLocale(string $locale): string
249 277 {
250 278 if (strpos($locale, '-') !== false) return $locale;
251 279
252 - global $acyWPLangCodes;
253 - if (!empty($acyWPLangCodes[$locale])) return $acyWPLangCodes[$locale];
280 + global $acymWPLangCodes;
281 + if (!empty($acymWPLangCodes[$locale])) {
282 + return $acymWPLangCodes[$locale];
283 + }
254 284
255 285 if (strpos($locale, '_') === false) {
256 286 return $locale.'-'.strtoupper($locale);
257 287 } else {
@@ -263,9 +293,9 @@
263 293 {
264 294 if ($userId === null) $userId = acym_currentUserId();
265 295 if (empty($userId)) return '';
266 296
267 - return convertWPLocaleToAcyLocale(get_user_locale($userId));
297 + return acym_convertWPLocaleToAcyLocale(get_user_locale($userId));
268 298 }
269 299
270 300 function acym_getTranslationTools(): array
271 301 {