27 $this->CONFIG = $CONFIG;
28 $this->defaultPath = dirname(dirname(dirname(dirname(__DIR__)))) .
"/languages/";
45 static $CURRENT_LANGUAGE;
48 if (!is_array(
$args)) {
50 'As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.',
58 if (!isset($this->CONFIG->translations)) {
63 if (!$CURRENT_LANGUAGE) {
70 if (!isset($this->CONFIG->translations[
$language])) {
78 if (isset($this->CONFIG->translations[
$language][$message_key])) {
80 }
else if (isset($this->CONFIG->translations[
"en"][$message_key])) {
81 $string = $this->CONFIG->translations[
"en"][$message_key];
82 _elgg_services()->logger->notice(sprintf(
'Missing %s translation for "%s" language key',
$language, $message_key));
85 _elgg_services()->logger->notice(sprintf(
'Missing English translation for "%s" language key', $message_key));
112 if (!isset($this->CONFIG->translations)) {
113 $this->CONFIG->translations = array();
116 $country_code = strtolower($country_code);
117 $country_code = trim($country_code);
118 if (is_array($language_array) && $country_code !=
"") {
119 if (
sizeof($language_array) > 0) {
120 if (!isset($this->CONFIG->translations[$country_code])) {
121 $this->CONFIG->translations[$country_code] = $language_array;
123 $this->CONFIG->translations[$country_code] = $language_array + $this->CONFIG->translations[$country_code];
159 if ((!
$language) && (isset($this->CONFIG->language)) && ($this->CONFIG->language)) {
176 if ($this->CONFIG->system_cache_enabled) {
189 $this->CONFIG->i18n_loaded_from_cache =
true;
191 $this->CONFIG->language_paths[$this->defaultPath] =
true;
215 if (!isset($this->CONFIG->language_paths)) {
216 $this->CONFIG->language_paths = array();
218 $this->CONFIG->language_paths[
$path] =
true;
222 _elgg_services()->logger->info(
"Translations loaded from: $path");
225 $load_language_files = array(
227 "$current_language.php" 230 $load_language_files = array_unique($load_language_files);
232 $handle = opendir(
$path);
234 _elgg_services()->logger->error(
"Could not open language path: $path");
239 while (
false !== (
$language = readdir($handle))) {
245 if (in_array(
$language, $load_language_files) || $load_all) {
271 static $LANG_RELOAD_ALL_RUN;
272 if ($LANG_RELOAD_ALL_RUN) {
276 if ($this->CONFIG->i18n_loaded_from_cache) {
278 $cache_dir = $cache->getVariable(
"cache_path");
284 if (preg_match(
'/(([a-z]{2,3})(_[a-z]{2})?)\.lang$/', $filename, $matches)) {
293 foreach ($this->CONFIG->language_paths as
$path => $dummy) {
298 $LANG_RELOAD_ALL_RUN =
true;
313 $installed = array();
315 foreach ($this->CONFIG->translations as $k => $v) {
316 $installed[$k] = $this->
translate($k, array(), $k);
319 if (($completeness < 100) && ($k !=
'en')) {
320 $installed[$k] .=
" (" . $completeness .
"% " . $this->
translate(
'complete') .
")";
343 $en = count($this->CONFIG->translations[
'en']);
347 $missing = count($missing);
353 $lang = $en - $missing;
355 return round((
$lang / $en) * 100, 2);
374 foreach ($this->CONFIG->translations[
'en'] as $k => $v) {
375 if ((!isset($this->CONFIG->translations[
$language][$k]))
376 || ($this->CONFIG->translations[
$language][$k] == $this->CONFIG->translations[
'en'][$k])) {
381 if (count($missing)) {
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.
if(!$autoload_available) _elgg_services()
$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.
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)
Sends 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.
__construct()
Initializes new translator.
$language
$vars['language'] $vars['lc'] if present, client will be sent long expires headers ...
getLanguage()
Gets the current language in use by the system or user.