Elgg  Version 1.11
languages.js
Go to the documentation of this file.
1 /*globals vsprintf*/
5 elgg.provide('elgg.config.translations');
6 
7 // default language - required by unit tests
8 elgg.config.language = 'en';
9 
14 elgg.add_translation = function(lang, translations) {
15  elgg.provide('elgg.config.translations.' + lang);
16 
17  elgg.extend(elgg.config.translations[lang], translations);
18 };
19 
24 elgg.get_language = function() {
25  var user = elgg.get_logged_in_user_entity();
26 
27  if (user && user.language) {
28  return user.language;
29  }
30 
31  return elgg.config.language;
32 };
33 
43 elgg.echo = function(key, argv, language) {
44  //elgg.echo('str', 'en')
45  if (elgg.isString(argv)) {
46  language = argv;
47  argv = [];
48  }
49 
50  //elgg.echo('str', [...], 'en')
51  var translations = elgg.config.translations,
52  dlang = elgg.get_language(),
53  map;
54 
55  language = language || dlang;
56  argv = argv || [];
57 
58  map = translations[language] || translations[dlang];
59  if (map && map[key]) {
60  return vsprintf(map[key], argv);
61  }
62 
63  return key;
64 };
65 
elgg
Definition: install.js:23
elgg menu user
Definition: admin.php:192
elgg config language
Definition: languages.js:8
$CONFIG translations
String translations for the current language.
Definition: config.php:48