Skip to content

Commit

Permalink
Autodiscover preferred browser language, enhances modernxmpp#4
Browse files Browse the repository at this point in the history
  • Loading branch information
magicbrothers committed Jun 28, 2021
1 parent fe94735 commit 4598d83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
config.js
2 changes: 2 additions & 0 deletions config.js.dist
@@ -0,0 +1,2 @@
var supportedLanguages = ['de', 'en', 'fr', 'ro']
var defaultLanguage = 'en'
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -37,6 +37,7 @@ <h3 class="text-center" id="heading"></h3>
<p class="hint" id="xmppis"></p>
</div>
<script src="scripts/i18n-text.min.js"></script>
<script src="config.js"></script>
<script src="scripts/main.js"></script>
<script src="scripts/qrcode.min.js"></script>
</body>
Expand Down
14 changes: 13 additions & 1 deletion scripts/main.js
Expand Up @@ -94,7 +94,19 @@
i18n.once(I18nText.event.LOCALE_CHANGE, function (data) {
rehash();
});
i18n.setLocale('en');

var preferredLocale, setLocale = false;
for (preferredLocale of navigator.languages) {
if (supportedLanguages.includes(preferredLocale)) {
i18n.setLocale(preferredLocale);
setLocale = true;
break;
}
}
if (!setLocale) {
i18n.setLocale(defaultLocale);
}


// functionality
if (navigator.userAgent.indexOf("Android") >= 0) {
Expand Down

0 comments on commit 4598d83

Please sign in to comment.