Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 0bc143c

Browse files
committed
Enable translations on index when language is changed
1 parent 7be7d4a commit 0bc143c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

index.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ <h2 class="txt-center">
8181
<i class="ion-android-sync spinner fontSize30 spinner-with-logo-icon"></i>
8282
</div>
8383
<div class="width100 positionTop">
84-
<a class="btn btn-txt rowTop10 marginRight10 pull-right js-indexReload"><i class="ion-android-sync"></i> <span class="js-translate">Reload</span></a>
85-
<a class="btn btn-txt rowTop10 marginRight10 pull-right" href="#home"><i class="ion-home"></i> <span class="js-translate">LoadIndex</span></a>
84+
<a class="btn btn-txt rowTop10 marginRight10 pull-right js-indexReload"><i class="ion-android-sync"></i> <span class="js-translate" data-translate="Reload"></span></a>
85+
<a class="btn btn-txt rowTop10 marginRight10 pull-right" href="#home"><i class="ion-home"></i> <span class="js-translate" data-translate="LoadIndex"></span></a>
8686
</div>
8787
</div>
8888

@@ -92,6 +92,13 @@ <h2 class="txt-center">
9292
<script>
9393
var app = require('./js/main'),
9494
remote = require('remote');
95+
96+
window.translateIndex = function(){
97+
$('.js-translate').each(function() {
98+
$(this).text(polyglot.t($(this).data("translate")));
99+
});
100+
};
101+
translateIndex();
95102
$('.js-closeIndexModal').on('click', function(){
96103
$(this).closest('.modal').addClass('hide');
97104
});
@@ -114,10 +121,6 @@ <h2 class="txt-center">
114121
$('.js-defaultServerIndexApp').on('click', function(){
115122
app.loadNewServer("http://localhost:18469/api/v1/");
116123
});
117-
$('.js-translate').each(function() {
118-
var translationKey = $(this).html();
119-
$(this).replaceWith(polyglot.t(translationKey));
120-
});
121124
</script>
122125
</body>
123126
</html>

js/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ user.on('change:language', function(md, lang) {
8585
window.lang = lang;
8686
extendPolyglot(lang);
8787
localStorage.setItem('lang', lang);
88+
//trigger translation function on index
89+
window.translateIndex();
90+
8891
});
8992

9093
//keep user and profile urls synced with the server configuration

0 commit comments

Comments
 (0)