Elgg  Version 6.1
languages.js.php
Go to the documentation of this file.
1 <?php
8 $language = elgg_extract('language', $vars, 'en');
9 
10 // requested language
13 
14 // add site language
16 if (!empty($site_language)) {
18 }
19 
20 // add English fallback
21 $combine_languages['en'] = true;
22 
23 // fetch all translations
24 $all_translations = _elgg_services()->translator->getLoadedTranslations();
25 
26 // make sure all requested languages are loaded
27 foreach (array_keys($combine_languages) as $language) {
28  if (!isset($all_translations[$language])) {
29  _elgg_services()->translator->reloadAllTranslations();
30 
31  $all_translations = _elgg_services()->translator->getLoadedTranslations();
32  break;
33  }
34 }
35 
36 // combine all languages in one result
38 foreach (array_keys($combine_languages) as $language) {
39  if (!isset($all_translations[$language])) {
40  continue;
41  }
42 
43  $translations = array_merge($all_translations[$language], $translations);
44 }
45 
46 echo json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
foreach(array_keys($combine_languages) as $language) $translations
$language
Build a JSON array of the combined language keys to be used in javascript elgg/i18n.
Definition: languages.js.php:8
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
$combine_languages
$site_language
$all_translations
$vars
Definition: theme.php:5
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353