1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
//
// Copyright (C) 2018 FreeIPA Contributors see COPYING for license
//
define([
'./jquery',
'./config',
'./_base/i18n'
],
function( $, config, i18n) {
/**
*
* Retrieve translations from server
*
* @class translations
* @singleton
*
*/
var translations = {};
var retrieve = function() {
var result = false;
var jsondata = {
method: "i18n_messages",
params: [ [], { "version": window.ipa_loader.api_version } ]
};
var json_url = config.i18n_messages_url;
// test case: tests dir with crafted data stored in the local json file
if (window.location.protocol === 'file:') {
json_url = "data/" + jsondata.method + '.json';
}
var request = {
method: 'POST',
url: json_url,
data: JSON.stringify(jsondata),
dataType: "json",
contentType: 'application/json',
async: false,
processData: false,
success: success_handler,
error: error_handler
};
function error_handler(xhr, text_status, error_thrown) {
result = false;
}
function success_handler(data, text_status, xhr) {
if (!data.error) {
i18n.source = data.result.texts;
result = true;
}
}
$.ajax(request);
return result;
};
if (!retrieve()) {
throw new Error('Couldn\'t receive translations');
}
translations.update = retrieve;
return translations;
});
|