From 10beb33ea66577ba3210eaed40dbab509e4f5dbd Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 10 Aug 2014 12:25:03 +0300 Subject: HTML: show translated words dynamically from JSON translation file. Make HTML exports Multilingual by showing dynamically the HTML words from JSON files. The needed words are translated using the translation API in subsurface. Signed-off-by: Gehad elrobey Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- theme/dive_export.html | 32 +++++++----- theme/list_lib.js | 135 +++++++++++++++++++++++++++++-------------------- 2 files changed, 100 insertions(+), 67 deletions(-) (limited to 'theme') diff --git a/theme/dive_export.html b/theme/dive_export.html index 065a8a4f1..fd98ba442 100644 --- a/theme/dive_export.html +++ b/theme/dive_export.html @@ -38,6 +38,10 @@ function load_scripts() fileref.setAttribute("src", location.pathname + "_files/stat.json"); document.getElementsByTagName("head")[0].appendChild(fileref); + fileref=document.createElement('script'); + fileref.setAttribute("src", location.pathname + "_files/translation.json"); + document.getElementsByTagName("head")[0].appendChild(fileref); + fileref=document.createElement('script'); fileref.setAttribute("src", location.pathname + "_files/settings.json"); document.getElementsByTagName("head")[0].appendChild(fileref); @@ -127,6 +131,9 @@ window.onload=function(){ document.body.style.visibility='visible'; document.onkeydown = switchDives; + + //translate Page + translate_page(); } function changeAdvSearch(e){ @@ -145,7 +152,8 @@ function changeAdvSearch(e){
- Advanced Search + + Advanced Search
@@ -188,7 +196,7 @@ function changeAdvSearch(e){
- +
@@ -197,7 +205,7 @@ function changeAdvSearch(e){

-

Dive profile

+

Dive profile

@@ -224,7 +232,7 @@ function changeAdvSearch(e){
- +
diff --git a/theme/list_lib.js b/theme/list_lib.js index 089f8bfd0..8c2faca92 100644 --- a/theme/list_lib.js +++ b/theme/list_lib.js @@ -126,7 +126,7 @@ function next_page() function view_pagging(start, end) { var page = document.getElementById("pagging"); - page.innerHTML = (start + 1) + ' to ' + (end + 1) + ' of ' + (itemsToShow.length) + ' dives'; + page.innerHTML = (start + 1) + ' to ' + (end + 1) + ' of ' + (itemsToShow.length) + '' + translate.dives; } /** @@ -134,12 +134,14 @@ function view_pagging(start, end) */ function expandAll() { + console.time('expnadAll'); for (var i = start; i < start + sizeofpage; i++) { if (i >= itemsToShow.length) break; unexpand(document.getElementById(itemsToShow[i])); items[itemsToShow[i]].expanded = false; } + console.timeEnd('expnadAll'); } /** @@ -204,22 +206,22 @@ function getlimited(dive) function getExpanded(dive) { - var res = '
Date: ' + dive.date + - '     Time: ' + dive.time + - '     Location: ' + '' + dive.location + '' + - '
'; + for (var i = 0; i < divestat.length; i++) { + res += ''; } return res; } -function stats_row_highlight(row){ +function stats_row_highlight(row) +{ row.style.backgroundColor = "rgba(125,125,125,0.7)"; } -function stats_row_unhighlight(row){ +function stats_row_unhighlight(row) +{ row.style.backgroundColor = "rgba(125,125,125,0.3)"; } @@ -806,7 +812,7 @@ function get_weight_HTML(weight) function get_weights_HTML(dive) { var result = ""; - result += '
Rating:' + putRating(dive.rating) + - '   Visibilty:' + putRating(dive.visibility) + + var res = '
' + translate.Date + ': ' + dive.date + + '     ' + translate.Time + ': ' + dive.time + + '     ' + translate.Locaiton + ': ' + '' + dive.location + '' + + '
' + translate.Rating + ':' + putRating(dive.rating) + + '   ' + translate.Visibility + ':' + putRating(dive.visibility) + '
' + - '
Air temp: ' + dive.temperature.air + - '    Water temp: ' + dive.temperature.water + - '
Duration: ' + dive.dive_duration + - '
DiveMaster: ' + dive.divemaster + - '

Buddy:

' + dive.buddy + - '
Suit: ' + dive.suit + - '
Tags: ' + putTags(dive.tags) + - '

Notes:

' + dive.notes + '
'; + '
' + translate.Air_Temp + ': ' + dive.temperature.air + + '    ' + translate.Water_Temp + ': ' + dive.temperature.water + + '
' + translate.Duration + ': ' + dive.dive_duration + + '
' + translate.DiveMaster + ': ' + dive.divemaster + + '

' + translate.Buddy + ':

' + dive.buddy + + '
' + translate.Suit + ': ' + dive.suit + + '
' + translate.Tags + ': ' + putTags(dive.tags) + + '

' + translate.Notes + ':

' + dive.notes + '
'; if (settings.listOnly === '0') { - res += '
Show more details
'; + res += '
' + translate.Show_more_details + '
'; } return res; }; @@ -660,11 +662,11 @@ function toggleStats() if (statsShows) { statsShows = false; stats_button.style.backgroundColor = "#dfdfdf"; - document.getElementById('diveListPanel').style.display='block'; - document.getElementById('diveStat').style.display='none'; + document.getElementById('diveListPanel').style.display = 'block'; + document.getElementById('diveStat').style.display = 'none'; } else { - document.getElementById('diveListPanel').style.display='none'; - document.getElementById('diveStat').style.display='block'; + document.getElementById('diveListPanel').style.display = 'none'; + document.getElementById('diveStat').style.display = 'block'; stats_button.style.backgroundColor = "#5f7f8f"; statsShows = true; showStats(); @@ -677,29 +679,33 @@ function showStats() document.getElementById('diveStatsData').innerHTML += getDiveStats(); } -function getDiveStats(){ +function getDiveStats() +{ var res = ""; res += ''; - res += ''; + res += ''; res += ''; res += getStatsRows(); res += '
Year#Total TimeAverage TimeShortest TimeLongest TimeAverage DepthMin DepthMax DepthAverage SACMin SACMax SACAverage TempMin TempMax Temp' + translate.Year + '#' + translate.Total_Time + '' + translate.Average_Time + '' + translate.Shortest_Time + '' + translate.Longest_Time + '' + translate.Average_Depth + '' + translate.Min_Depth + '' + translate.Max_Depth + '' + translate.Average_SAC + '' + translate.Min_SAC + '' + translate.Max_SAC + '' + translate.Average_Temp + '' + translate.Min_Temp + '' + translate.Max_Temp + '
'; return res; } -function getStatsRows(){ +function getStatsRows() +{ var res = ""; - for(var i = 0; i < divestat.length ; i++) { - res += '
'+divestat[i].YEAR+''+divestat[i].DIVES+''+divestat[i].TOTAL_TIME+''+divestat[i].AVERAGE_TIME+''+divestat[i].SHORTEST_TIME+''+divestat[i].LONGEST_TIME+''+divestat[i].AVG_DEPTH+''+divestat[i].MIN_DEPTH+''+divestat[i].MAX_DEPTH+''+divestat[i].AVG_SAC+''+divestat[i].MIN_SAC+''+divestat[i].MAX_SAC+''+divestat[i].AVG_TEMP+''+divestat[i].MIN_TEMP+''+divestat[i].MAX_TEMP+'
' + divestat[i].YEAR + '' + divestat[i].DIVES + '' + divestat[i].TOTAL_TIME + '' + divestat[i].AVERAGE_TIME + '' + divestat[i].SHORTEST_TIME + '' + divestat[i].LONGEST_TIME + '' + divestat[i].AVG_DEPTH + '' + divestat[i].MIN_DEPTH + '' + divestat[i].MAX_DEPTH + '' + divestat[i].AVG_SAC + '' + divestat[i].MIN_SAC + '' + divestat[i].MAX_SAC + '' + divestat[i].AVG_TEMP + '' + divestat[i].MIN_TEMP + '' + divestat[i].MAX_TEMP + '
'; + result += '
WeightType
'; for (var i in dive.Weights) { result += get_weight_HTML(dive.Weights[i]); } @@ -840,7 +846,7 @@ function get_cylinder_HTML(cylinder) function get_cylinders_HTML(dive) { var result = ""; - result += '

Dive equipments

' + translate.Weight + '' + translate.Type + '
'; + result += '

' + translate.Dive_equipments + '

TypeSizeWork PressureStart PressureEnd PressureO2
'; for (var i in dive.Cylinders) { result += get_cylinder_HTML(dive.Cylinders[i]); } @@ -877,7 +883,7 @@ function get_bookmarks_HTML(dive) if (dive.events <= 0) return ""; var result = ""; - result += '

Events

' + translate.Type + '' + translate.Size + '' + translate.Work_Pressure + '' + translate.Start_Pressure + '' + translate.End_Pressure + 'O2
'; + result += '

' + translate.Events + '

NameTimeValue
'; for (var i in dive.events) { result += get_bookmark_HTML(dive.events[i]); } @@ -890,21 +896,21 @@ function get_bookmarks_HTML(dive) */ function get_dive_HTML(dive) { - return '

Dive Information

' + translate.Name + '' + translate.Time + '' + translate.Value + '
Date: ' + dive.date + - '     Time: ' + dive.time + - '     Location: ' + '' + - dive.location + '' + - '
Rating:' + putRating(dive.rating) + - '   Visibilty:' + putRating(dive.visibility) + - '
' + - '
Air temp: ' + dive.temperature.air + - '    Water temp: ' + dive.temperature.water + - '
Duration: ' + dive.dive_duration + - '
DiveMaster: ' + dive.divemaster + - '

Buddy:

' + dive.buddy + - '
Suit: ' + dive.suit + - '
Tags: ' + putTags(dive.tags) + - '

Notes:

' + dive.notes + '
'; + var res = '

' + translate.Dive_information + '

' + translate.Date + ': ' + dive.date + + '     ' + translate.Time + ': ' + dive.time + + '     ' + translate.Locaiton + ': ' + '' + dive.location + '' + + '
' + translate.Rating + ':' + putRating(dive.rating) + + '   ' + translate.Visibility + ':' + putRating(dive.visibility) + + '
' + + '
' + translate.Air_Temp + ': ' + dive.temperature.air + + '    ' + translate.Water_Temp + ': ' + dive.temperature.water + + '
' + translate.Duration + ': ' + dive.dive_duration + + '
' + translate.DiveMaster + ': ' + dive.divemaster + + '

' + translate.Buddy + ':

' + dive.buddy + + '
' + translate.Suit + ': ' + dive.suit + + '
' + translate.Tags + ': ' + putTags(dive.tags) + + '

' + translate.Notes + ':

' + dive.notes + '
'; + return res; }; /** @@ -912,10 +918,9 @@ function get_dive_HTML(dive) */ function get_status_HTML(dive) { - return '

Dive Status

Sac: ' + ml_to_litre(dive.sac) + + return '

' + translate.Dive_Status + '

Sac: ' + ml_to_litre(dive.sac) + ' l/min' + '     Otu: ' + dive.otu + - '     Cns: ' + dive.cns + - '
'; + '
     Cns: ' + dive.cns + '
'; }; function get_dive_photos(dive) @@ -927,8 +932,8 @@ function get_dive_photos(dive) var slider = ""; document.getElementById("divephotos").style.display = 'block'; for (var i = 0; i < dive.photos.length; i++) { - slider += ''; + slider += ''; } return slider; } @@ -1034,8 +1039,7 @@ function canvas_draw() 0 ]); } - if (plot1) - { + if (plot1) { $('chart1').unbind(); plot1.destroy(); } @@ -1166,7 +1170,7 @@ function showDiveDetails(dive) function setDiveTitle(dive) { - document.getElementById("dive_no").innerHTML = "Dive No. " + (settings.subsurfaceNumbers === '0' ? + document.getElementById("dive_no").innerHTML = translate.Dive_No + (settings.subsurfaceNumbers === '0' ? dive.number + 1 : dive.subsurface_number); document.getElementById("dive_location").innerHTML = dive.location; } @@ -1214,7 +1218,28 @@ function switchDives(e) } } -window.onresize = function(event) { - if (plot1) - plot1.replot( { resetAxes: true } ); +window.onresize = function(event) +{ + if (plot1) + plot1.replot({ + resetAxes : true + }); }; + +function translate_page() +{ + document.getElementById("number_header").innerHTML = translate.Number; + document.getElementById("date_header").innerHTML = translate.Date; + document.getElementById("time_header").innerHTML = translate.Time; + document.getElementById("location_header").innerHTML = translate.Locaiton; + document.getElementById("air_temp_header").innerHTML = translate.Air_Temp; + document.getElementById("water_temp_header").innerHTML = translate.Water_Temp; + document.getElementById("adv_srch_sp").innerHTML = translate.Advanced_Search; + document.getElementById("expnd_all_btn").innerHTML = translate.Expand_All; + document.getElementById("claps_all_btn").innerHTML = translate.Collapse_All; + document.getElementById("trip_button").innerHTML = translate.trips; + document.getElementById("stats_button").innerHTML = translate.Statistics; + document.getElementById("div_profil_lbl").innerHTML = translate.Dive_profile; + document.getElementById("bk_to_ls_lbl").innerHTML = translate.Back_to_List; + document.getElementById("bk_to_ls_lbl2").innerHTML = translate.Back_to_List; +} -- cgit v1.2.3-70-g09d2