Skip to content

Commit b884ff9

Browse files
authored
Merge pull request #2866 from rgbkrk/fix-dynamic-locale
load locale dynamically only when not en-us
2 parents b2edf89 + 11e578f commit b884ff9

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

notebook/static/bidi/bidi.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,57 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
define([
5-
'bidi/numericshaping',
6-
], function (numericshaping){
7-
"use strict";
8-
9-
var shaperType="";
10-
var textDir="";
11-
12-
var _uiLang= function (){
13-
return navigator.language.toLowerCase();
14-
};
15-
16-
var _loadLocale = function () {
17-
if(_isMirroringEnabled()){
18-
$("body").attr("dir","rtl");
19-
}
20-
requirejs(['components/moment/locale/'+_uiLang()], function (err){
21-
console.warn("Error loading the required locale");
22-
console.warn(err);
23-
});
24-
shaperType= _uiLang()=='ar'? "national" : "defaultNumeral";
25-
};
26-
27-
var _isMirroringEnabled= function() {
28-
return (new RegExp("^(ar|he)").test(_uiLang()));
29-
};
30-
31-
/**
4+
define(['bidi/numericshaping'], function(numericshaping) {
5+
'use strict';
6+
7+
var shaperType = '';
8+
var textDir = '';
9+
10+
var _uiLang = function() {
11+
return navigator.language.toLowerCase();
12+
};
13+
14+
var _loadLocale = function() {
15+
if (_isMirroringEnabled()) {
16+
$('body').attr('dir', 'rtl');
17+
}
18+
var uiLang = _uiLang();
19+
20+
if (uiLang !== 'en' && uiLang !== 'en-us') {
21+
// moment does not ship with a separate file for locale/en or locale/en-us
22+
// so we must skip dynamically requiring it
23+
requirejs(['components/moment/locale/' + _uiLang()], function(err) {
24+
console.warn('Error loading the required locale');
25+
console.warn(err);
26+
});
27+
}
28+
29+
shaperType = _uiLang() == 'ar' ? 'national' : 'defaultNumeral';
30+
};
31+
32+
var _isMirroringEnabled = function() {
33+
return new RegExp('^(ar|he)').test(_uiLang());
34+
};
35+
36+
/**
3237
* NS : for digit Shaping.
3338
* BTD : for future work in case of Base Text Direction Addition.
34-
*/
35-
/*var _flags= {
36-
NS: 1,
37-
BTD : 2
38-
};*/
39-
40-
/**
39+
*/
40+
41+
/**
4142
* @param value : the string to apply the bidi-support on it.
4243
* @param flag :indicates the type of bidi-support (Numeric-shaping ,Base-text-dir ).
4344
*/
44-
var _applyBidi = function (value /*, flag*/) {
45-
value = numericshaping.shapeNumerals(value, shaperType);
46-
return value;
47-
};
48-
49-
var bidi = {
50-
applyBidi : _applyBidi,
51-
isMirroringEnabled : _isMirroringEnabled,
52-
loadLocale : _loadLocale,
53-
};
54-
55-
return bidi;
45+
var _applyBidi = function(value /*, flag*/) {
46+
value = numericshaping.shapeNumerals(value, shaperType);
47+
return value;
48+
};
49+
50+
var bidi = {
51+
applyBidi: _applyBidi,
52+
isMirroringEnabled: _isMirroringEnabled,
53+
loadLocale: _loadLocale,
54+
};
55+
56+
return bidi;
5657
});

0 commit comments

Comments
 (0)