Add setLocale support

pull/989/head
Piero Toffanin 2021-05-28 11:21:24 -04:00
rodzic 4e63afa3e7
commit 82f1868db3
4 zmienionych plików z 33 dodań i 1 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
import React from 'react';
import $ from 'jquery';
import PluginsAPI from './classes/plugins/API';
import { setLocale } from './translations/functions';
// Main is always executed first in the page
@ -12,6 +13,9 @@ import PluginsAPI from './classes/plugins/API';
window.ReactDOM = ReactDOM;
window.React = React;
// Expose set locale function globally
window.setLocale = setLocale;
$(function(){
PluginsAPI.App.triggerReady();
});

Wyświetl plik

@ -0,0 +1,20 @@
import $ from 'jquery';
function setLocale(locale){
var fd = new FormData();
fd.append('language', locale);
$.ajax({
url: `/i18n/setlang/`,
contentType: false,
processData: false,
data: fd,
type: 'POST'
}).done(function(){
location.reload(true);
}).fail(function(e){
console.error("Cannot set locale", e);
});
}
export { setLocale };

Wyświetl plik

@ -12,7 +12,7 @@
<form class="form-inline" style="margin-top: 32px;">
<strong>{% trans 'Current Locale:' %}</strong> {{ current_locale }}<br/>
<small>{% trans "To change locale, modify your browser's locale settings, then refresh the page." %}</small>
<small>{% trans "To change locale, modify your browser's locale settings, then refresh the page, or use the set locale button below." %}</small>
<br/><br/>
<div class="form-group margin-bottom">
<label for="transFiles">{% trans 'Translation Files (.zip):' %}</label>
@ -22,6 +22,13 @@
<button type="button" class="btn btn-danger" onClick="javascript:execute(this, 'reloadTranslation', document.getElementById('transFiles').value)"><i class="fa fa-language"></i> {% trans 'Download and Replace Translation Files' %}</button>
</div>
</form>
<form class="form-inline" style="margin-top: 32px;" onsubmit="return false;">
<div class="form-group margin-bottom">
<label for="targetLocale">{% trans 'Set locale:' %}</label>
<input id='targetLocale' type="text" class="form-control" size="6" value="it-IT">
<button class="btn btn-primary" onclick="window.setLocale(document.getElementById('targetLocale').value);"><i class="fa fa-globe"></i> {% trans 'Apply' %}</button>
</div>
</form>
<div id="action-loading" style="display: none; margin-top: 12px">
<i class="fa fa-circle-notch fa-spin fa-fw"></i> {% trans 'Executing… do not refresh the page! This could take a while.' %}
</div>

Wyświetl plik

@ -44,6 +44,7 @@ urlpatterns = [
# TODO: add caching: https://docs.djangoproject.com/en/3.1/topics/i18n/translation/#note-on-performance
url(r'^jsi18n/', JavaScriptCatalog.as_view(packages=['app']), name='javascript-catalog'),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
handler404 = app_views.handler404