Elgg  Version 2.3
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 
48 elgg.echo = function(key, argv, language) {
49  //elgg.echo('str', 'en')
50  if (elgg.isString(argv)) {
51  language = argv;
52  argv = [];
53  }
54 
55  //elgg.echo('str', [...], 'en')
56  var translations = elgg.config.translations,
57  dlang = elgg.get_language(),
58  map;
59 
60  language = language || dlang;
61  argv = argv || [];
62 
63  map = translations[language] || translations[dlang];
64  if (map && elgg.isString(map[key])) {
65  return vsprintf(map[key], argv);
66  }
67 
68  return key;
69 };
70 
elgg
Definition: install.js:23
$_ELGG translations
String translations for the current language.
Definition: config.php:333
elgg config language
Definition: languages.js:8
var vsprintf
Definition: sprintf.js:180
elgg menu user
Definition: admin.css.php:192