fix to make actions list i18n ready and Japanese translation

This commit is contained in:
Hiroyasu Nishiyama
2022-01-15 20:39:05 +09:00
parent 81a4fe59d9
commit 58f3a76da7
3 changed files with 184 additions and 12 deletions

View File

@@ -164,11 +164,26 @@ RED.actionList = (function() {
searchResults.editableList('empty');
results = [];
var actions = RED.actions.list();
actions.forEach(function (sc) {
var id = sc.id.replace(/^.*:/,"");
var key = "action-list."+id;
var translation = RED._(key);
if (translation !== key) {
sc.translation = translation;
}
});
actions.sort(function(A,B) {
return A.id.localeCompare(B.id);
var Aid = A.translation ? A.translation : A.id;
var Bid = B.translation ? B.translation : B.id;
return Aid.localeCompare(Bid);
});
actions.forEach(function(action) {
action.label = action.id.replace(/:/,": ").replace(/-/g," ").replace(/(^| )./g,function() { return arguments[0].toUpperCase()});
if (action.translation) {
action.label = action.translation;
}
else {
action.label = action.id.replace(/:/,": ").replace(/-/g," ").replace(/(^| )./g,function() { return arguments[0].toUpperCase()});
}
action._label = action.label.toLowerCase();
searchResults.editableList('addItem',action)
})

View File

@@ -588,13 +588,16 @@ RED.keyboard = (function() {
var item = $('<div class="keyboard-shortcut-entry">').appendTo(container);
container.data('data',object);
var text = object.id.replace(/(^.+:([a-z]))|(-([a-z]))/g,function() {
if (arguments[5] === 0) {
return arguments[2].toUpperCase();
} else {
return " "+arguments[4].toUpperCase();
}
});
var text = object.translation;
if (!object.translation) {
text = object.id.replace(/(^.+:([a-z]))|(-([a-z]))/g,function() {
if (arguments[5] === 0) {
return arguments[2].toUpperCase();
} else {
return " "+arguments[4].toUpperCase();
}
});
}
var label = $('<div>').addClass("keyboard-shortcut-entry-text").text(text).appendTo(item);
var user = $('<i class="fa fa-user"></i>').prependTo(label);
@@ -635,7 +638,14 @@ RED.keyboard = (function() {
} else {
filterValue = filterValue.replace(/\s/g,"");
shortcutList.editableList('filter', function(data) {
return data.id.toLowerCase().replace(/^.*:/,"").replace("-","").indexOf(filterValue) > -1;
var label;
if (data.translation) {
label = data.translation.toLowerCase();
}
else {
label = data.id.toLowerCase().replace(/^.*:/,"").replace("-","");
}
return label.indexOf(filterValue) > -1;
})
}
}
@@ -656,9 +666,24 @@ RED.keyboard = (function() {
});
var shortcuts = RED.actions.list();
var missing = [];
shortcuts.forEach(function (sc) {
var id = sc.id.replace(/^.*:/,"");
var key = "action-list."+id;
var translation = RED._(key);
if (translation !== key) {
sc.translation = translation;
}
else {
missing.push(id);
}
});
// console.log("; missing:", missing);
shortcuts.sort(function(A,B) {
var Aid = A.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
var Bid = B.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
var Aid = A.translation ? A.translation : A.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
var Bid = B.translation ? B.translation : B.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
return Aid.localeCompare(Bid);
});
knownShortcuts = new Set();