Skip to content

Commit

Permalink
Merge pull request #154 from STEPBible/testlang
Browse files Browse the repository at this point in the history
Add foreign language support for Welcome panel, gloss and lexicon
  • Loading branch information
patricksptang authored Oct 21, 2024
2 parents 4bfbfcb + 70a0d09 commit 10cb184
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 199 deletions.
43 changes: 41 additions & 2 deletions step-web/src/main/webapp/js/backbone/views/view_display_passage.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ var PassageDisplayView = DisplayView.extend({
}
});
//needs to happen after appending to DOM

this.updateSTEPColor();
this._addForeignLangToInterLinear();
this._doChromeHack(passageHtml, interlinearMode, options);
this.doInterlinearVerseNumbers(passageHtml, interlinearMode, options);
this.scrollToTargetLocation(passageContainer);
Expand Down Expand Up @@ -177,6 +176,46 @@ var PassageDisplayView = DisplayView.extend({
}
}
},

_addForeignLangToInterLinear: function () {
var currentUserLang = step.userLanguageCode.toLowerCase();
if (step.defaults.langWithTranslatedLex.indexOf(currentUserLang) > -1) {
var strongsToElmts = {};
var elementsToReview = $(".interlinear").find(".w ").find("span.strongs");
for (var i = 0; i < elementsToReview.length; i++) {
var curElement = $(elementsToReview[i]);
var curStrong = curElement.parent().attr("strong");
if ((typeof curStrong !== "string") || (curStrong === "")) {
if (curElement.text() === "Eng Vocab")
curElement.html("Eng Vocab<br>" + currentUserLang.substring(0,1).toUpperCase() + currentUserLang.substring(1,2) + " Vocab");
continue;
}
curStrong = curStrong.split(" ")[0]; // Take the first Strong
if (curStrong in strongsToElmts)
strongsToElmts[curStrong].push(curElement);
else
strongsToElmts[curStrong] = [ curElement ];
}
for (var key in strongsToElmts) {
fetch("https://us.stepbible.org/html/lexicon/" + currentUserLang + "_json/" +
key + ".json")
.then(function(response) {
return response.json();
})
.then(function(data) {
var gloss = data.gloss.trim();
var pos = gloss.indexOf(":");
if (pos > -1)
gloss = gloss.substring(pos+1).trim();
for (var i = 0; i < strongsToElmts[data.strong].length; i++) {
var thisElmnt = strongsToElmts[data.strong][i];
thisElmnt.html(thisElmnt.text() + "<br>" + gloss);
}
});
}
}
},

scrollToTargetLocation: function (passageContainer) {
var self = this;
if (!passageContainer) {
Expand Down
231 changes: 132 additions & 99 deletions step-web/src/main/webapp/js/backbone/views/view_examples.js

Large diffs are not rendered by default.

42 changes: 36 additions & 6 deletions step-web/src/main/webapp/js/backbone/views/view_quick_lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ var QuickLexicon = Backbone.View.extend({
'<%= item.stepGloss %>' +
'<% var urlLang = $.getUrlVar("lang") || ""; %>' +
'<% urlLang = urlLang.toLowerCase(); %>' +
'<% var currentLang = step.userLanguageCode.toLowerCase(); %>' +
// '<% var currentEnWithEsLexiconSetting = step.passages.findWhere({ passageId: step.util.activePassageId()}).get("isEnWithEsLexicon"); %>' +
// '<% if (currentEnWithEsLexiconSetting == undefined) currentEnWithEsLexiconSetting = false; %>' +
'<% if ((currentLang.indexOf("es") == 0) && (item._es_Gloss != undefined)) { %><span>,&nbsp;<%= item._es_Gloss %></span> <% } %>' +
'<% if ((currentLang.indexOf("km") == 0) && (item._km_Gloss != undefined)) { %><span>,&nbsp;<%= item._km_Gloss %></span> <% } %>' +
'<% if ((currentLang.indexOf("es") == 0) && (item._es_Gloss != undefined)) { %><span>,&nbsp;[<%= item._es_Gloss %>]</span> <% } %>' +
'<% if ((currentLang.indexOf("km") == 0) && (item._km_Gloss != undefined)) { %><span>,&nbsp;[<%= item._km_Gloss %>]</span> <% } %>' +
'<% if (step.defaults.langWithTranslatedLex.indexOf(currentLang) > -1) { %>&nbsp;<span class="quick_gloss_<%= item.strongNumber %>"></span> <% } %>' +
'<% if (urlLang === "zh_tw") { currentLang = "zh_tw"; } else if (urlLang === "zh") { currentLang = "zh"; } %>' +
'<% var currentEnWithZhLexiconSetting = step.passages.findWhere({ passageId: step.util.activePassageId()}).get("isEnWithZhLexicon"); %>' +
'<% if (currentEnWithZhLexiconSetting === undefined) currentEnWithZhLexiconSetting = false; %>' +
'<% if ( (currentLang === "zh_tw") && (item._zh_tw_Gloss != undefined) ) { %><span>&nbsp;<%= item._zh_tw_Gloss %></span> <% } else if ( (currentLang === "zh") && (item._zh_Gloss != undefined) ) { %><span>&nbsp;<%= item._zh_Gloss %></span> <% } %>' +
'<% if ( (currentLang === "zh_tw") && (item._zh_tw_Gloss != undefined) ) { %><span>&nbsp;[<%= item._zh_tw_Gloss %>]</span> <% } else if ( (currentLang === "zh") && (item._zh_Gloss != undefined) ) { %><span>&nbsp;[<%= item._zh_Gloss %>]</span> <% } %>' +
'&nbsp;(<span class="transliteration"><%= item.stepTransliteration %></span> - ' +
'<span class="<%= fontClass %>"><%= item.accentedUnicode %></span>) ' +
'</h1> ' +
Expand All @@ -30,6 +30,7 @@ var QuickLexicon = Backbone.View.extend({
'<span class="shortDef"><%= item.shortDef == undefined ? "" : item.shortDef %></span>' +
'<% if ((item.mediumDef != undefined) && (item.mediumDef !== "")) { %><div class="mediumDef"><%= item.mediumDef %></div> <% } %>' +
'<% } %>' +
'<% if (step.defaults.langWithTranslatedLex.indexOf(currentLang) > -1) { %><div class="quick_def_<%= item.strongNumber %>" class="mediumDef"></div> <% } %>' +
'<% var showClickWord = false; %>' +
'<% if ((item.versionCountOT != null) && (item.versionCountNT != null)) { showClickWord = true; %><span class="strongCount"> (<%= sprintf(__s.stats_occurs_times_in_specific_ot_nt_bible, item.versionCountOT, item.versionCountNT, view.version) %>.) <% } %>' +
'<% if ((item.versionCountOT != null) && (!showClickWord)) { showClickWord = true; %><span class="strongCount"> (<%= sprintf(__s.stats_occurs_times_in_specific_bible, item.versionCountOT, view.version) %>.) <% } %>' +
Expand Down Expand Up @@ -116,6 +117,7 @@ var QuickLexicon = Backbone.View.extend({
if (item) morph_information[counter] = self._createBriefMorphInfo(item);
}
var lexicon;
var currentUserLang = step.userLanguageCode.toLowerCase();
if (morphOnly)
lexicon = $(_.template(self.templateDef2)({ brief_morph_info: morph_information, view: self }));
else if (multipleStrongTextFromSearchModal !== "") {
Expand All @@ -141,7 +143,8 @@ var QuickLexicon = Backbone.View.extend({
lexicon = $(_.template(self.templateDef)({ data: data.vocabInfos,
brief_morph_info: morph_information,
fontClass: step.util.ui.getFontForStrong(self.strong),
view: self
view: self,
currentLang: currentUserLang
}));
}
if (step.touchDevice) $(lexicon).find(".clickMoreInfo").text(__s.more_info_on_touch_of_word);
Expand Down Expand Up @@ -187,6 +190,25 @@ var QuickLexicon = Backbone.View.extend({
self.showRelatedNumbers(data.vocabInfos[i].rawRelatedNumbers);
}
}
if (step.defaults.langWithTranslatedLex.indexOf(currentUserLang) > -1) {
for (var i = 0; i < (data.vocabInfos || []).length; i++) {
var curStrong = data.vocabInfos[i].strongNumber;
fetch("https://us.stepbible.org/html/lexicon/" + currentUserLang + "_json/" +
curStrong + ".json")
.then(function(response) {
return response.json();
})
.then(function(data) {
var gloss = data.gloss;
var pos = gloss.indexOf(":");
if (pos > -1)
gloss = gloss.substring(pos+1);
step.util.updateWhenRendered(".quick_gloss_" + data.strong, "[" + gloss.trim() + "]", 0);
step.util.updateWhenRendered(".quick_def_" + data.strong,
data.def.replace(/<\s?br\s?>/g, " ").replace(/<\s?br \/>/g, " ").trim(), 0, true);
});
}
}
}
},

Expand Down Expand Up @@ -297,6 +319,13 @@ var QuickLexicon = Backbone.View.extend({
$('#quickLexicon').css({'maxHeight':'200px','overflow-y':'auto'});
}
else {
if (step.defaults.langWithTranslatedLex.indexOf(step.userLanguageCode.toLowerCase()) > -1) {
safetyMargin += bottom; // Double the size if there is an additional definition for that langage
lexicon.css({"display": "none"});
step.util.delay(function () {
$("#quickLexicon").show();
}, 300, "showQuickLexicon");
}
if (step.touchDevice) {
var quickLexiconHeightForTouchDevices = Math.floor(self.height * .4);
if (quickLexiconHeightForTouchDevices < (bottom - top)) {
Expand All @@ -306,7 +335,8 @@ var QuickLexicon = Backbone.View.extend({
}
}
else {
if ((quickDefPositionAtTop) && (bottom + 20 > self.position)) {
var safetyMargin = 20;
if ((quickDefPositionAtTop) && (bottom + safetyMargin > self.position)) {
lexicon.css({"top": "", "bottom": "0"});
top = $("#quickLexicon").position().top; // The top position has changed
bottom = $("#quickLexicon").outerHeight(true) + top; // The bottom position has changed
Expand Down
Loading

0 comments on commit 10cb184

Please sign in to comment.