25 $this->CONFIG = $CONFIG;
26 $this->defaultPath = dirname(dirname(dirname(dirname(__DIR__)))) .
"/languages/";
42 static $CURRENT_LANGUAGE;
44 if (!is_string($message_key) || strlen($message_key) < 1) {
46 '$message_key needs to be a string in ' . __METHOD__ .
'(), ' . gettype($message_key) .
' provided' 52 if (!is_array(
$args)) {
54 'As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.',
62 if (!$CURRENT_LANGUAGE) {
69 $this->ensureTranslationsLoaded(
$language);
78 foreach (array_keys($langs) as $try_lang) {
79 if (isset($GLOBALS[
'_ELGG']->
translations[$try_lang][$message_key])) {
80 $string = $GLOBALS[
'_ELGG']->translations[$try_lang][$message_key];
91 'Missing %s translation for "%s" language key',
92 ($try_lang ===
'en') ?
'English' : $try_lang,
121 $GLOBALS[
'_ELGG']->translations = array();
124 $country_code = strtolower($country_code);
125 $country_code = trim($country_code);
126 if (is_array($language_array) && $country_code !=
"") {
127 if (
sizeof($language_array) > 0) {
128 if (!isset($GLOBALS[
'_ELGG']->
translations[$country_code])) {
129 $GLOBALS[
'_ELGG']->translations[$country_code] = $language_array;
131 $GLOBALS[
'_ELGG']->translations[$country_code] = $language_array + $GLOBALS[
'_ELGG']->translations[$country_code];
172 if ((!
$language) && (isset($this->CONFIG->language)) && ($this->CONFIG->language)) {
216 $GLOBALS[
'_ELGG']->i18n_loaded_from_cache =
true;
218 $GLOBALS[
'_ELGG']->language_paths[$this->defaultPath] =
true;
230 $this->loadPluginTranslations(
$language);
245 private function loadPluginTranslations(
$language) {
254 foreach ($plugins as
$plugin) {
255 $languages_path =
"{$plugin->getPath()}languages/";
257 if (!is_dir($languages_path)) {
262 $language_file =
"{$languages_path}{$language}.php";
264 if (!file_exists($language_file)) {
267 $name = $plugin->getFriendlyName();
268 _elgg_services()->logger->notice(
"Plugin $name is missing translations for $language language");
275 throw new \PluginException(
sprintf(
'Cannot register languages for plugin %s (guid: %s) at %s.',
276 array($plugin->getID(), $plugin->guid, $languages_path)));
289 $languages_path = rtrim(
$path,
"\\/") .
"/languages";
292 if (!is_dir($languages_path)) {
314 $GLOBALS[
'_ELGG']->language_paths = array();
316 $GLOBALS[
'_ELGG']->language_paths[
$path] =
true;
318 _elgg_services()->logger->info(
"Translations loaded from: $path");
321 $load_language_files = array(
"$language.php");
327 $load_language_files = array(
329 "$current_language.php" 332 $load_language_files = array_unique($load_language_files);
335 $handle = opendir(
$path);
337 _elgg_services()->logger->error(
"Could not open language path: $path");
342 while (
false !== ($language_file = readdir($handle))) {
344 if (substr($language_file, 0, 1) ==
'.' || substr($language_file, -4) !==
'.php') {
348 if (in_array($language_file, $load_language_files) || $load_all) {
374 static $LANG_RELOAD_ALL_RUN;
375 if ($LANG_RELOAD_ALL_RUN) {
379 if ($GLOBALS[
'_ELGG']->i18n_loaded_from_cache) {
381 $cache_dir = $cache->getVariable(
"cache_path");
387 if (preg_match(
'/(([a-z]{2,3})(_[a-z]{2})?)\.lang$/', $filename, $matches)) {
401 $LANG_RELOAD_ALL_RUN =
true;
416 $installed = array();
427 $installed[$k] =
$lang;
429 if (!$admin_logged_in || ($k ===
'en')) {
434 if ($completeness < 100) {
435 $installed[$k] .=
" (" . $completeness .
"% " . $this->
translate(
'complete') .
")";
461 $missing = count($missing);
467 $lang = $en - $missing;
469 return round((
$lang / $en) * 100, 2);
488 foreach ($GLOBALS[
'_ELGG']->
translations[
'en'] as $k => $v) {
495 if (count($missing)) {
516 $this->ensureTranslationsLoaded(
$language);
531 private function ensureTranslationsLoaded(
$language) {
712 $code = preg_replace(
'~[^a-z0-9]~',
'_',
$code);
getInstalledTranslations()
Return an array of installed translations as an associative array "two letter code" => "native langua...
if($guid==elgg_get_logged_in_user_guid()) $name
registerTranslations($path, $load_all=false, $language=null)
When given a full path, finds translation files and loads them.
static getAllLanguageCodes()
Returns an array of language codes.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
elgg_get_system_cache()
Returns an object suitable for caching system information.
$_ELGG translations
String translations for the current language.
loadTranslations($language=null)
Load both core and plugin translations.
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
getMissingLanguageKeys($language)
Return the translation keys missing from a given language, or those that are identical to the english...
addTranslation($country_code, $language_array)
Add a translation.
detectLanguage()
Detect the current system/user language or false.
elgg_get_file_list($directory, $exceptions=array(), $list=array(), $extensions=null)
Returns a list of files in $directory.
translate($message_key, $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
reloadAllTranslations()
Reload all translations from all registered paths.
sanitise_string($string)
Alias of sanitize_string.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
getCurrentLanguage()
Get the current system/user language or "en".
getLanguageCompleteness($language)
Return the level of completeness for a given language code (compared to english)
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_load_system_cache($type)
Retrieve the contents of a system cache.
static normalizeLanguageCode($code)
Normalize a language code (e.g.
var sprintf
sprintf() for JavaScript 0.7-beta1 http://www.diveintojavascript.com/projects/javascript-sprintf ...
elgg_is_system_cache_enabled()
Is system cache enabled.
languageKeyExists($key, $language= 'en')
Check if a given language key exists.
__construct()
Initializes new translator.
registerPluginTranslations($path)
Registers translations in a directory assuming the standard plugin layout.
$_ELGG language_paths
Paths to scan for autoloading languages.