Skip to content

Commit

Permalink
Merge pull request 'feature/language-list' (#33) from feature/languag…
Browse files Browse the repository at this point in the history
…e-list into release/v8.2.0
  • Loading branch information
Julia Radzhabova committed Sep 18, 2024
2 parents b903384 + 3cfe5b5 commit b889f15
Show file tree
Hide file tree
Showing 23 changed files with 316 additions and 102 deletions.
44 changes: 28 additions & 16 deletions apps/common/main/lib/component/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ define([
displayField: 'displayValue',
valueField : 'value',
search : false,
searchFields: ['displayValue'], // Property name from the item to be searched by
placeHolder : '',
scrollAlwaysVisible: false,
takeFocusOnClose: false,
Expand Down Expand Up @@ -128,6 +129,7 @@ define([
this.valueField = me.options.valueField;
this.placeHolder = me.options.placeHolder;
this.search = me.options.search;
this.searchFields = me.options.searchFields;
this.scrollAlwaysVisible = me.options.scrollAlwaysVisible;
this.focusWhenNoSelection = (me.options.focusWhenNoSelection!==false);
this.restoreMenuHeight = me.options.restoreMenuHeight;
Expand Down Expand Up @@ -486,26 +488,36 @@ define([
},

selectCandidate: function() {
var index = (this._search.index && this._search.index != -1) ? this._search.index : 0,
var me = this,
index = (this._search.index && this._search.index != -1) ? this._search.index : 0,
re = new RegExp('^' + ((this._search.full) ? this._search.text : this._search.char), 'i'),
isFirstCharsEqual = re.test(this.store.at(index).get(this.displayField)),
isFirstCharsEqual = this.searchFields.some(function(field) {
return re.test(me.store.at(index).get(field));
}),
itemCandidate, idxCandidate;

for (var i=0; i<this.store.length; i++) {
var item = this.store.at(i);
if (re.test(item.get(this.displayField))) {
if (!itemCandidate) {
itemCandidate = item;
idxCandidate = i;
if(!isFirstCharsEqual)
break;
}
if (this._search.full && i==index || i>index) {
itemCandidate = item;
idxCandidate = i;
break;
var item = this.store.at(i),
isBreak = false;
this.searchFields.forEach(function(fieldName) {
if (item.get(fieldName) && re.test(item.get(fieldName))) {
if (!itemCandidate) {
itemCandidate = item;
idxCandidate = i;
if(!isFirstCharsEqual) {
isBreak = true;
return;
}
}
if (me._search.full && i==index || i>index) {
itemCandidate = item;
idxCandidate = i;
isBreak = true;
return;
}
}
}
});
if(isBreak) break;
}

if (itemCandidate) {
Expand Down Expand Up @@ -843,4 +855,4 @@ define([
this.cmpEl && this.cmpEl.find('.form-control').focus();
}
}, Common.UI.ComboBoxCustom || {}));
});
});
41 changes: 26 additions & 15 deletions apps/common/main/lib/component/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ define([
offset : [0, 0],
cyclic : true,
search : false,
searchFields: ['caption'], // Property name from the item to be searched by
scrollAlwaysVisible: true,
scrollToCheckedItem: true, // if true - scroll menu to checked item on menu show
focusToCheckedItem: false // if true - move focus to checked item on menu show
Expand Down Expand Up @@ -1100,26 +1101,36 @@ define([
},

selectCandidate: function() {
var index = (this._search.index && this._search.index != -1) ? this._search.index : 0,
var me = this,
index = (this._search.index && this._search.index != -1) ? this._search.index : 0,
re = new RegExp('^' + ((this._search.full) ? this._search.text : this._search.char), 'i'),
isFirstCharsEqual = re.test(this.items[index].caption),
isFirstCharsEqual = this.options.searchFields.some(function(field) {
return re.test(me.items[index][field]);
}),
itemCandidate, idxCandidate;

for (var i=0; i<this.items.length; i++) {
var item = this.items[i];
if (re.test(item.caption)) {
if (!itemCandidate) {
itemCandidate = item;
idxCandidate = i;
if(!isFirstCharsEqual)
break;
}
if (this._search.full && i==index || i>index) {
itemCandidate = item;
idxCandidate = i;
break;
var item = this.items[i],
isBreak = false;
this.options.searchFields.forEach(function(fieldName) {
if (item[fieldName] && re.test(item[fieldName])) {
if (!itemCandidate) {
itemCandidate = item;
idxCandidate = i;
if(!isFirstCharsEqual) {
isBreak = true;
return;
}
}
if (me._search.full && i==index || i>index) {
itemCandidate = item;
idxCandidate = i;
isBreak = true;
return;
}
}
}
});
if(isBreak) break;
}

if (itemCandidate) {
Expand Down
72 changes: 53 additions & 19 deletions apps/common/main/lib/util/LanguageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ Common.util.LanguageInfo = new(function() {
0x0445 : ["bn-IN", "বাংলা (ভারত)", "Bengali (India)"],
0x781A : ["bs", "bosanski"],
0x641A : ["bs-Cyrl", "Босански (Ћирилица)"],
0x201A : ["bs-Cyrl-BA", "Босански (Босна и Херцеговина)", "Bosnian (Cyrillic) (Bosnia and Herzegovina)"],
0x201A : ["bs-Cyrl-BA", "Босански (Босна и Херцеговина)", "Bosnian (Cyrillic, Bosnia and Herzegovina)"],
0x681A : ["bs-Latn", "Bosanski (Latinica)"],
0x141A : ["bs-Latn-BA", "Bosanski (Bosna i Hercegovina)", "Bosnian (Latin) (Bosnia and Herzegovina)"],
0x141A : ["bs-Latn-BA", "Bosanski (Bosna i Hercegovina)", "Bosnian (Latin, Bosnia and Herzegovina)"],
0x007E : ["br", "Brezhoneg"],
0x047E : ["br-FR", "Brezhoneg (Frañs)", "Breton (France)"],
0x0002 : ["bg", "Български"],
Expand Down Expand Up @@ -187,7 +187,7 @@ Common.util.LanguageInfo = new(function() {
0x0447 : ["gu-IN", "ગુજરાતી (ભારત)", "Gujarati (India)"],
0x0068 : ["ha", "Hausa"],
0x7C68 : ["ha-Latn", "Hausa (Latin)"],
0x0468 : ["ha-Latn-NG", "Hausa (Nigeria)", "Hausa (Latin) (Nigeria)"],
0x0468 : ["ha-Latn-NG", "Hausa (Nigeria)", "Hausa (Latin, Nigeria)"],
0x000D : ["he", "עברית‏"],
0x040D : ["he-IL", "עברית (ישראל)‏", "Hebrew (Israel)"],
0x0039 : ["hi", "हिंदी"],
Expand All @@ -202,7 +202,7 @@ Common.util.LanguageInfo = new(function() {
0x0421 : ["id-ID", "Bahasa Indonesia (Indonesia)", "Indonesian (Indonesia)"],
0x005D : ["iu", "Inuktitut"],
0x7C5D : ["iu-Latn", "Inuktitut (Qaliujaaqpait)"],
0x085D : ["iu-Latn-CA", "Inuktitut (Kanatami) (kanata)", "Inuktitut (Latin) (Canada)"],
0x085D : ["iu-Latn-CA", "Inuktitut (Kanatami, kanata)", "Inuktitut (Latin, Canada)"],
0x785D : ["iu-Cans", "ᐃᓄᒃᑎᑐᑦ (ᖃᓂᐅᔮᖅᐸᐃᑦ)"],
0x045D : ["iu-Cans-CA", "ᐃᓄᒃᑎᑐᑦ (ᑲᓇᑕᒥ)", "Inuktitut (Canada)"],
0x003C : ["ga", "Gaeilge"],
Expand Down Expand Up @@ -244,7 +244,7 @@ Common.util.LanguageInfo = new(function() {
0x082E : ["dsb-DE", "Dolnoserbšćina (Nimska)", "Lower Sorbian (Germany)"],
0x006E : ["lb", "Lëtzebuergesch"],
0x046E : ["lb-LU", "Lëtzebuergesch (Luxembourg)", "Luxembourgish (Luxembourg)"],
0x042F : ["mk-MK", "Македонски јазик (Македонија)", "Macedonian (Former Yugoslav Republic of Macedonia)"],
0x042F : ["mk-MK", "Македонски јазик (Македонија)", "Macedonian (Macedonia)"],
0x002F : ["mk", "Македонски јазик"],
0x003E : ["ms", "Bahasa Melayu"],
0x083E : ["ms-BN", "Bahasa Melayu (Brunei Darussalam)", "Malay (Brunei Darussalam)"],
Expand All @@ -265,7 +265,7 @@ Common.util.LanguageInfo = new(function() {
0x7850 : ["mn-Cyrl", "Монгол хэл"],
0x0450 : ["mn-MN", "Монгол хэл (Монгол улс)", "Mongolian (Cyrillic, Mongolia)"],
0x7C50 : ["mn-Mong", "ᠮᠤᠨᠭᠭᠤᠯ ᠬᠡᠯᠡ"],
0x0850 : ["mn-Mong-CN", "ᠮᠤᠨᠭᠭᠤᠯ ᠬᠡᠯᠡ (ᠪᠦᠭᠦᠳᠡ ᠨᠠᠢᠷᠠᠮᠳᠠᠬᠤ ᠳᠤᠮᠳᠠᠳᠤ ᠠᠷᠠᠳ ᠣᠯᠣᠰ)", "Mongolian (Traditional Mongolian) (People's Republic of China)"],
0x0850 : ["mn-Mong-CN", "ᠮᠤᠨᠭᠭᠤᠯ ᠬᠡᠯᠡ (ᠪᠦᠭᠦᠳᠡ ᠨᠠᠢᠷᠠᠮᠳᠠᠬᠤ ᠳᠤᠮᠳᠠᠳᠤ ᠠᠷᠠᠳ ᠣᠯᠣᠰ)", "Mongolian (People's Republic of China)"],
0x0061 : ["ne", "नेपाली"],
0x0461 : ["ne-NP", "नेपाली (नेपाल)", "Nepali (Nepal)"],
0x0861 : ["ne-IN", "नेपाली (भारत)", "Nepali (India)"],
Expand Down Expand Up @@ -302,26 +302,26 @@ Common.util.LanguageInfo = new(function() {
0x0419 : ["ru-RU", "Русский (Россия)", "Russian (Russia)"],
0x0819 : ["ru-MD", "Русский (Молдавия)", "Russian (Republic of Moldova)"],
0x703B : ["smn", "Sämikielâ"],
0x243B : ["smn-FI", "Sämikielâ (Suomâ)", "Sami (Inari) (Finland)"],
0x243B : ["smn-FI", "Sämikielâ (Suomâ)", "Sami (Inari, Finland)"],
0x7C3B : ["smj", "Julevusámegiella"],
0x103B : ["smj-NO", "Julevusámegiella (Vuodna)", "Sami (Lule) (Norway)"],
0x143B : ["smj-SE", "Julevusámegiella (Svierik)", "Sami (Lule) (Sweden)"],
0x103B : ["smj-NO", "Julevusámegiella (Vuodna)", "Sami (Lule, Norway)"],
0x143B : ["smj-SE", "Julevusámegiella (Svierik)", "Sami (Lule, Sweden)"],
0x003B : ["se", "Davvisámegiella"],
0x0C3B : ["se-FI", "Davvisámegiella (Suopma)", "Sami (Northern) (Finland)"],
0x043B : ["se-NO", "Davvisámegiella (Norga)", "Sami (Northern) (Norway)"],
0x083B : ["se-SE", "Davvisámegiella (Ruoŧŧa)", "Sami (Northern) (Sweden)"],
0x0C3B : ["se-FI", "Davvisámegiella (Suopma)", "Sami (Northern, Finland)"],
0x043B : ["se-NO", "Davvisámegiella (Norga)", "Sami (Northern, Norway)"],
0x083B : ["se-SE", "Davvisámegiella (Ruoŧŧa)", "Sami (Northern, Sweden)"],
0x743B : ["sms", "Sääm´ǩiõll"],
0x203B : ["sms-FI", "Sääm´ǩiõll (Lää´ddjânnam)", "Sami (Skolt) (Finland)"],
0x203B : ["sms-FI", "Sääm´ǩiõll (Lää´ddjânnam)", "Sami (Skolt, Finland)"],
0x783B : ["sma", "åarjelsaemiengiele"],
0x183B : ["sma-NO", "åarjelsaemiengiele (Nöörje)", "Sami (Southern) (Norway)"],
0x1C3B : ["sma-SE", "åarjelsaemiengiele (Sveerje)", "Sami (Southern) (Sweden)"],
0x183B : ["sma-NO", "åarjelsaemiengiele (Nöörje)", "Sami (Southern, Norway)"],
0x1C3B : ["sma-SE", "åarjelsaemiengiele (Sveerje)", "Sami (Southern, Sweden)"],
0x004F : ["sa", "संस्कृत"],
0x044F : ["sa-IN", "संस्कृत (भारतम्)", "Sanskrit (India)"],
0x0091 : ["gd", "Gàidhlig"],
0x0491 : ["gd-GB", "Gàidhlig (An Rìoghachd Aonaichte)", "Scottish Gaelic (United Kingdom)"],
0x7C1A : ["sr", "Srpski"],
0x6C1A : ["sr-Cyrl", "Српски (Ћирилица)"],
0x1C1A : ["sr-Cyrl-BA", "Српски (Босна и Херцеговина)", "Serbian (Cyrillic) (Bosnia and Herzegovina)"],
0x1C1A : ["sr-Cyrl-BA", "Српски (Босна и Херцеговина)", "Serbian (Cyrillic, Bosnia and Herzegovina)"],
0x301A : ["sr-Cyrl-ME", "Српски (Црна Гора)", "Serbian (Cyrillic, Montenegro)"],
0x0C1A : ["sr-Cyrl-CS", "Српски (Србија и Црна Гора (Претходно))", "Serbian (Cyrillic, Serbia and Montenegro (Former))"],
0x281A : ["sr-Cyrl-RS", "Српски (Србија)", "Serbian (Cyrillic, Serbia)"],
Expand Down Expand Up @@ -371,10 +371,10 @@ Common.util.LanguageInfo = new(function() {
0x045A : ["syr-SY", "ܣܘܪܝܝܐ (سوريا)‏", "Syriac (Syria)"],
0x0028 : ["tg", "Тоҷикӣ"],
0x7C28 : ["tg-Cyrl", "Тоҷикӣ"],
0x0428 : ["tg-Cyrl-TJ", "Тоҷикӣ (Тоҷикистон)", "Tajik (Cyrillic) (Tajikistan)"],
0x0428 : ["tg-Cyrl-TJ", "Тоҷикӣ (Тоҷикистон)", "Tajik (Cyrillic, Tajikistan)"],
0x005F : ["tzm", "Tamazight"],
0x7C5F : ["tzm-Latn", "Tamazight (Latin)"],
0x085F : ["tzm-Latn-DZ", "Tamazight (Djazaïr)", "Tamazight (Latin) (Algeria)"],
0x085F : ["tzm-Latn-DZ", "Tamazight (Djazaïr)", "Tamazight (Latin, Algeria)"],
0x0049 : ["ta", "தமிழ்"],
0x0449 : ["ta-IN", "தமிழ் (இந்தியா)", "Tamil (India)"],
0x0044 : ["tt", "Татар"],
Expand Down Expand Up @@ -456,8 +456,42 @@ Common.util.LanguageInfo = new(function() {
return null;
},

/**
* @typedef {Object} LangDisplayName
* @property {string} native - Native name
* @property {string} english - English name
*/
/**
* @param {string} code - Language code (example - 1025, 1026, ...).
* @returns {LangDisplayName|null} Object with a native language name (native) and an English name (english).
* If the English name is missing, returns an object with an empty string for English.
* Returns `null` if no language code is found.
*/
getLocalLanguageDisplayName: function(code) {
var lang = localLanguageName[code];
if(lang) {
var nativeName = lang[1];
var englishName = lang[2];
function replaceBrackets(text) {
let newText = text.replace('(', '– ');
let lastCloseBracketIndex = newText.lastIndexOf(')');
if (lastCloseBracketIndex !== -1) {
newText = newText.slice(0, lastCloseBracketIndex) + newText.slice(lastCloseBracketIndex + 1);
}
return newText;
}

if(englishName) {
return { native: replaceBrackets(nativeName), english: replaceBrackets(englishName) };
} else {
return { native: nativeName, english: ''};
}
}
return null;
},

getLanguages: function() {
return localLanguageName;
}
}
})();
})();
10 changes: 7 additions & 3 deletions apps/common/main/lib/view/LanguageDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ define([], function () { 'use strict';
'<% _.each(items, function(item) { %>',
'<li id="<%= item.id %>" data-value="<%= item.value %>">',
'<a tabindex="-1" type="menuitem" langval="<%= item.value %>">',
'<i class="icon <% if (item.spellcheck) { %> toolbar__icon btn-ic-docspell spellcheck-lang <% } %>"></i>',
'<%= scope.getDisplayValue(item) %>',
'<div>',
'<i class="icon <% if (item.spellcheck) { %> toolbar__icon btn-ic-docspell spellcheck-lang <% } %>"></i>',
'<%= item.displayValue %>',
'</div>',
'<label style="opacity: 0.6"><%= item.displayValueEn %></label>',
'</a>',
'</li>',
'<% }); %>',
Expand All @@ -101,6 +104,7 @@ define([], function () { 'use strict';
data: this.options.languages,
takeFocusOnClose: true,
search: true,
searchFields: ['displayValue', 'displayValueEn'],
scrollAlwaysVisible: true
});

Expand Down Expand Up @@ -155,4 +159,4 @@ define([], function () { 'use strict';

labelSelect : 'Select document language'
}, Common.Views.LanguageDialog || {}))
});
});
4 changes: 2 additions & 2 deletions apps/common/main/resources/less/language-dialog.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

li {
.icon.spellcheck-lang {
margin: -3px 4px 0 -24px;
margin: -1px 4px 0 -24px;
.rtl & {
margin: -3px -24px 0 4px;
margin: -1px -24px 0 4px;
}
}

Expand Down
16 changes: 10 additions & 6 deletions apps/documenteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2722,12 +2722,16 @@ define([
for (var code in allLangs) {
if (allLangs.hasOwnProperty(code)) {
info = allLangs[code];
info[2] && langs.push({
displayValue: info[1],
value: info[0],
code: parseInt(code),
spellcheck: _.indexOf(apiLangs, code)>-1
});
if(info[2]) {
var displayName = Common.util.LanguageInfo.getLocalLanguageDisplayName(code);
langs.push({
displayValue: displayName.native,
displayValueEn: displayName.english,
value: info[0],
code: parseInt(code),
spellcheck: _.indexOf(apiLangs, code)>-1
});
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions apps/documenteditor/main/app/controller/Statusbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ define([

_onTextLanguage: function(langId) {
var info = Common.util.LanguageInfo.getLocalLanguageName(langId);
var displayName = Common.util.LanguageInfo.getLocalLanguageDisplayName(langId);
this.statusbar.setLanguage({
value: info[0],
displayValue: info[1],
code: langId
value: info[0],
displayValue: (displayName ? displayName.native : ''),
code: langId
});
},

Expand Down Expand Up @@ -372,4 +373,4 @@ define([
textSetTrackChanges: 'You are in Track Changes mode',
textDisconnect: '<b>Connection is lost</b><br>Trying to connect. Please check connection settings.'
}, DE.Controllers.Statusbar || {}));
});
});
Loading

0 comments on commit b889f15

Please sign in to comment.