forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.js
36 lines (30 loc) · 1.47 KB
/
i18n.js
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
module.exports = function(input){
throw "Should not ever make it to the actual i18n loader because those resources don't exist";
}
// This adapts the functionality of an old require-js plugin that would scope down
// the i18nObj when required with a given format require('i18n!some_scope'). We
// should probably phase this out over time in favor of not specifying loaders
// in require statements, but it seems to replace the functionality for now.
module.exports.pitch = function(remainingRequest, precedingRequest, data) {
this.cacheable();
var scopeName = this.query.replace("?", "");
// translations generated by i18nliner have these prefixes that we can just
// snip out before loading the scope
//
// plugins have their plugin name in the midst of app.gems.plugins.analytics.app.views.jst.something
// so we need a regex that will filter those out too
scopeName = scopeName.
replace(/^[^\s]*\.app\.views\.jst\./,'').
replace(/^[^\s]*\.ember\.([^\s]*\.)templates\./,'$1')
if(scopeName.indexOf("ic_submission-download-dialog") > -1){
// TODO: I'm so, so sorry about this. Figure out how to scope
// correctly for this one exceptional case later
} else {
scopeName = scopeName.replace(/-/, '_');
}
var scopedJavascript = "" +
"define(['i18nObj', 'translations/"+ scopeName +"', 'translations/_core', 'translations/_core_en'], function(I18n) {" +
" return I18n.scoped('" + scopeName + "');" +
"});";
return scopedJavascript;
};