Creating bidi interface

samarsultan 9 years ago
parent c663389139
commit ea72fe3ff5

@ -0,0 +1,114 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'bidi/numericshaping',
'moment-hijri',
], function (numericshaping, moment){
"use strict";
var calendarType="";
var textDir="";
var shaperType="";
var _setCalendarType = function (val){
calendarType=val;
};
var _getcalendarType = function (){
return calendarType;
};
var _setTextDir = function (dir){
textDir=dir;
};
var _setNumericShaping = function (val){
shaperType=val;
};
var _flags= {
NS: 1,
CALENDAR : 2
};
/*
* Test the UI Language
*/
var _uiLang= function (){
return navigator.language.toLowerCase();
};
/*
* TODO: this function cannot be invoked once ,as moment has different formats for the date .
* It needs improvements.
*/
var _getGlobalizedDate = function (date) {
var lang = _uiLang();
if (calendarType === "hijri" || lang ==='ar-sa') {
} else if (calendarType === "hebrew") {
}
return;
};
/*
* check if the locale exists provided by moment
*/
var _hasLocale = function (lang) {
if (lang == 'af'||'ar-ma'||'ar-sa'||'ar'||'az'||'be'||'bg' ||'bn'||'bo'||'br'||'bs'||'ca'||'cs'||'cv'||'cy'||'da'||'de-at'||'de'||'el'||'en-au'||'en-ca'||'en-gb'||'eo'||'es'||'et'||'eu'||'fa'||'fi'||'fo'||'fr-ca'||'fr'||'gl'||'he'||'hi'||'hr'||'hu'||'hy-am'||'id'||'is'||'it'||'ja'||'ka'||'km'||'ko'||'lb'||'lt'||'lv'||'mk'||'ml'||'mr'||'ms-my'||'my'||'nb'||'ne'||'nl'||'nn'||'pl'||'pt-br'||'pt'||'ro'||'ru'||'sk'||'sl'||'sq'||'sr-cyrl'||'sr'||'sv'||'ta'||'th'||'tl-ph'||'tr'||'tzm-latn'||'tzm'||'uk'||'uz'||'vi'||'zh-cn'||'zh-tw' ) {
return true;
}
else{
return false;
}
};
/*
* to load the required locale
*/
var _loadLocale = function (lang) {
if ( _hasLocale(lang)){
return requirejs(['components/moment/locale/'+lang], function (){});
}
else{
return requirejs(['components/moment'], function (){});
}
};
/*
* TODO: to add the other RTL languages
*/
var _isMirroringEnabled= function() {
if(new RegExp("^(ar|he)").test(_uiLang())){
$("body").attr("dir","rtl");
}
return;
};
var _applyBidi = function (value , flag) {
if(flag & _flags.NS == _flags.NS) {
value = numericshaping.shapeNumerals(value, shaperType, textDir);
return value;
}
if(flag & _flags.CALENDAR == _flags.CALENDAR) {
value = _getGlobalizedDate(value);
console.log("Calendar ");
return value;
}
return value;
};
var bidi = {
isMirroringEnabled : _isMirroringEnabled,
setNumericShaping : _setNumericShaping,
setCalendarType: _setCalendarType,
getcalendarType : _getcalendarType,
setTextDir : _setTextDir,
getGlobalizedDate: _getGlobalizedDate,
flags : _flags,
applyBidi : _applyBidi,
uiLang : _uiLang,
loadLocale : _loadLocale,
};
return bidi;
});

@ -7,9 +7,10 @@ define([
'base/js/dialog',
'base/js/keyboard',
'moment',
], function($, utils, dialog, keyboard, moment) {
'bidi/bidi',
], function($, utils, dialog, keyboard, moment ,bidi) {
"use strict";
bidi.loadLocale(bidi.uiLang());
var SaveWidget = function (selector, options) {
this.editor = undefined;
this.selector = selector;
@ -108,6 +109,7 @@ define([
SaveWidget.prototype.update_filename = function (filename) {
filename = bidi.applyBidi(filename , bidi.flags.NS);
this.element.find('span.filename').text(filename);
};

@ -7,7 +7,8 @@ define([
'base/js/dialog',
'base/js/keyboard',
'moment',
], function($, utils, dialog, keyboard, moment) {
'bidi/bidi',
], function($, utils, dialog, keyboard, moment ,bidi) {
"use strict";
var SaveWidget = function (selector, options) {
@ -130,6 +131,7 @@ define([
SaveWidget.prototype.update_notebook_name = function () {
var nbname = this.notebook.get_notebook_name();
nbname = bidi.applyBidi(nbname , bidi.flags.NS);
this.element.find('span.filename').text(nbname);
};

@ -8,8 +8,9 @@ define([
'base/js/dialog',
'base/js/events',
'base/js/keyboard',
'moment'
], function($, IPython, utils, dialog, events, keyboard, moment) {
'moment',
'bidi/bidi',
], function($, IPython, utils, dialog, events, keyboard, moment , bidi) {
"use strict";
var NotebookList = function (selector, options) {
@ -643,6 +644,7 @@ define([
select_all.data('indeterminate', true);
}
// Update total counter
checked = bidi.applyBidi(checked , bidi.flags.NS);
$('#counter-select-all').html(checked===0 ? ' ' : checked);
// If at aleast on item is selected, hide the selection instructions.
@ -658,7 +660,8 @@ define([
name = model.name,
modified = model.last_modified;
var running = (model.type === 'notebook' && this.sessions[path] !== undefined);
name = bidi.applyBidi(name , bidi.flags.NS);
item.data('name', name);
item.data('path', path);
item.data('modified', modified);
@ -697,6 +700,11 @@ define([
// Add in the date that the file was last modified
item.find(".item_modified").text(utils.format_datetime(modified));
if (bidi.getcalendarType()==="hijri"){
require(['moment-hijri'],function (moment_hijri){
item.find(".item_modified").attr("title", moment_hijri(modified).format("iYYYY-iMM-iDD HH:mm"));
});
}
item.find(".item_modified").attr("title", moment(modified).format("YYYY-MM-DD HH:mm"));
};

Loading…
Cancel
Save