25 $this->CONFIG = $CONFIG;
26 $this->defaultPath = dirname(dirname(dirname(dirname(__DIR__)))) .
"/languages/";
43 static $CURRENT_LANGUAGE;
46 if (!is_array(
$args)) {
48 'As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.',
56 if (!isset($this->CONFIG->translations)) {
61 if (!$CURRENT_LANGUAGE) {
68 if (!isset($this->CONFIG->translations[
$language])) {
76 if (isset($this->CONFIG->translations[
$language][$message_key])) {
78 }
else if (isset($this->CONFIG->translations[
"en"][$message_key])) {
79 $string = $this->CONFIG->translations[
"en"][$message_key];
80 _elgg_services()->logger->notice(sprintf(
'Missing %s translation for "%s" language key',
$language, $message_key));
83 _elgg_services()->logger->notice(sprintf(
'Missing English translation for "%s" language key', $message_key));
110 if (!isset($this->CONFIG->translations)) {
111 $this->CONFIG->translations = array();
114 $country_code = strtolower($country_code);
115 $country_code = trim($country_code);
116 if (is_array($language_array) && $country_code !=
"") {
117 if (
sizeof($language_array) > 0) {
118 if (!isset($this->CONFIG->translations[$country_code])) {
119 $this->CONFIG->translations[$country_code] = $language_array;
121 $this->CONFIG->translations[$country_code] = $language_array + $this->CONFIG->translations[$country_code];
162 if ((!
$language) && (isset($this->CONFIG->language)) && ($this->CONFIG->language)) {
179 if ($this->CONFIG->system_cache_enabled) {
192 $this->CONFIG->i18n_loaded_from_cache =
true;
194 $this->CONFIG->language_paths[$this->defaultPath] =
true;
218 if (!isset($this->CONFIG->language_paths)) {
219 $this->CONFIG->language_paths = array();
221 $this->CONFIG->language_paths[
$path] =
true;
225 _elgg_services()->logger->info(
"Translations loaded from: $path");
228 $load_language_files = array(
230 "$current_language.php" 233 $load_language_files = array_unique($load_language_files);
235 $handle = opendir(
$path);
237 _elgg_services()->logger->error(
"Could not open language path: $path");
242 while (
false !== (
$language = readdir($handle))) {
248 if (in_array(
$language, $load_language_files) || $load_all) {
274 static $LANG_RELOAD_ALL_RUN;
275 if ($LANG_RELOAD_ALL_RUN) {
279 if ($this->CONFIG->i18n_loaded_from_cache) {
281 $cache_dir = $cache->getVariable(
"cache_path");
287 if (preg_match(
'/(([a-z]{2,3})(_[a-z]{2})?)\.lang$/', $filename, $matches)) {
296 foreach ($this->CONFIG->language_paths as
$path => $dummy) {
301 $LANG_RELOAD_ALL_RUN =
true;
316 $installed = array();
320 foreach ($this->CONFIG->translations as $k => $v) {
321 $installed[$k] = $this->
translate($k, array(), $k);
322 if ($admin_logged_in && ($k !=
'en')) {
324 if ($completeness < 100) {
325 $installed[$k] .=
" (" . $completeness .
"% " . $this->
translate(
'complete') .
")";
348 $en = count($this->CONFIG->translations[
'en']);
352 $missing = count($missing);
358 $lang = $en - $missing;
360 return round((
$lang / $en) * 100, 2);
379 foreach ($this->CONFIG->translations[
'en'] as $k => $v) {
380 if ((!isset($this->CONFIG->translations[
$language][$k]))
381 || ($this->CONFIG->translations[
$language][$k] == $this->CONFIG->translations[
'en'][$k])) {
386 if (count($missing)) {
407 if ((
$language !==
'en') && !array_key_exists(
$language, $this->CONFIG->translations)) {
412 if (!array_key_exists(
$language, $this->CONFIG->translations)) {
416 return array_key_exists(
$key, $this->CONFIG->translations[
$language]);
getInstalledTranslations()
Return an array of installed translations as an associative array "two letter code" => "native langua...
_elgg_load_translations_for_language($language)
Load both core and plugin translations for a specific language.
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.
$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...
getAllLanguageCodes()
Returns an array of language codes.
addTranslation($country_code, $language_array)
Add a translation.
elgg_get_file_list($directory, $exceptions=array(), $list=array(), $extensions=null)
Returns a list of files in $directory.
reloadAllTranslations()
Reload all translations from all registered paths.
registerTranslations($path, $load_all=false)
When given a full path, finds translation files and loads them.
loadTranslations()
private
sanitise_string($string)
Wrapper function for alternate English spelling (.
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()
Detect the current language being used by the current site or logged in user.
getLanguageCompleteness($language)
Return the level of completeness for a given language code (compared to english)
elgg_load_system_cache($type)
Retrieve the contents of a system cache.
translate($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
languageKeyExists($key, $language= 'en')
Check if a give language key exists.
__construct()
Initializes new translator.
$language
$vars['language']
getLanguage()
Gets the current language in use by the system or user.