зеркало из https://github.com/mozilla/bedrock.git
Fix Bug 1058265 - Re-enable the Translation Bar using navigator.languages
This commit is contained in:
Родитель
2b0b6fab5b
Коммит
8b139390cf
|
@ -1027,7 +1027,7 @@ FIREFOX_TWITTER_ACCOUNTS = {
|
|||
# Mapbox token for spaces and communities pages
|
||||
MAPBOX_TOKEN = 'examples.map-i86nkdio'
|
||||
|
||||
# TABZILLA_INFOBAR_OPTIONS = 'translation'
|
||||
TABZILLA_INFOBAR_OPTIONS = 'translation'
|
||||
|
||||
# Optimize.ly project code for base template JS snippet
|
||||
OPTIMIZELY_PROJECT_ID = None
|
||||
|
|
|
@ -193,22 +193,6 @@ var Tabzilla = (function (Tabzilla) {
|
|||
var removeCompactModeEvents = function () {
|
||||
nav.off('.submenu');
|
||||
};
|
||||
Tabzilla.user = {};
|
||||
Tabzilla.detectUserLang = function (callback) {
|
||||
// Expose the user's accept languages in the HTTP Accept-Language
|
||||
// request header, because the navigator.language property is just the
|
||||
// application's locale on some browsers and the new navigator.languages
|
||||
// property is not widely implemented yet.
|
||||
$.ajax({ url: '/en-US/tabzilla/userlang.jsonp',
|
||||
cache: true, crossDomain: true, dataType: 'jsonp',
|
||||
jsonpCallback: "_", success: function (data) {
|
||||
var lang = Tabzilla.user.languages = data.languages;
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(lang);
|
||||
}
|
||||
}});
|
||||
};
|
||||
Tabzilla.open = function () {
|
||||
opened = true;
|
||||
panel.toggleClass('open');
|
||||
|
@ -392,7 +376,12 @@ var Tabzilla = (function (Tabzilla) {
|
|||
Infobar.prototype.oncancel = {};
|
||||
Tabzilla.setupTransbar = function (userLangs, pageLang) {
|
||||
var transbar = new Infobar('transbar', 'Translation Bar');
|
||||
userLangs = userLangs || Tabzilla.user.languages;
|
||||
|
||||
// Note that navigator.language doesn't always work because it's just
|
||||
// the application's locale on some browsers. navigator.languages has
|
||||
// not been widely implemented yet, but the new property provides an
|
||||
// array of the user's accept languages that we'd like to see.
|
||||
userLangs = userLangs || navigator.languages;
|
||||
pageLang = pageLang || document.documentElement.lang;
|
||||
|
||||
if (transbar.disabled || !userLangs || !pageLang) {
|
||||
|
@ -614,9 +603,7 @@ var Tabzilla = (function (Tabzilla) {
|
|||
|
||||
// Information Bars in order of priority
|
||||
var infobars = {
|
||||
translation: function () {
|
||||
Tabzilla.detectUserLang(Tabzilla.setupTransbar);
|
||||
}
|
||||
translation: Tabzilla.setupTransbar
|
||||
};
|
||||
$.each((tab.data('infobar') || '').split(' '), function (index, value) {
|
||||
var setup = infobars[value];
|
||||
|
|
|
@ -10,5 +10,4 @@ import views
|
|||
urlpatterns = patterns('',
|
||||
url(r'^tabzilla\.js$', views.tabzilla_js, name='tabzilla'),
|
||||
url(r'^transbar\.jsonp$', views.transbar_jsonp, name='transbar'),
|
||||
url(r'^userlang\.jsonp$', views.userlang_jsonp, name='userlang'),
|
||||
)
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import json
|
||||
import os.path
|
||||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.template import loader
|
||||
from django.views.decorators.http import last_modified
|
||||
from django.views.decorators.vary import vary_on_headers
|
||||
|
||||
from lib import l10n_utils
|
||||
|
||||
|
@ -62,16 +60,3 @@ def transbar_jsonp(request):
|
|||
resp = _resp(request, 'tabzilla/transbar.jsonp', 'application/javascript')
|
||||
resp['Access-Control-Allow-Origin'] = '*'
|
||||
return resp
|
||||
|
||||
|
||||
@cache_control_expires(24 * 30)
|
||||
@vary_on_headers('Accept-Language')
|
||||
def userlang_jsonp(request):
|
||||
data = {
|
||||
'languages': l10n_utils.get_accept_languages(request)
|
||||
}
|
||||
resp = HttpResponse('_({0});'.format(json.dumps(data)),
|
||||
content_type='application/javascript')
|
||||
resp['Access-Control-Allow-Origin'] = '*'
|
||||
|
||||
return resp
|
||||
|
|
|
@ -79,12 +79,4 @@ Adding the Translation Bar extension to Tabzilla requires:
|
|||
|
||||
<a href="https://www.mozilla.org/" id="tabzilla" data-infobar="translation">mozilla</a>
|
||||
|
||||
The Translation Bar relies on ``Tabzilla.user.languages`` and this data can be used for other purposes. In your JavaScript code:
|
||||
|
||||
if (Tabzilla.user.languages) {
|
||||
doSomething(Tabzilla.user.languages);
|
||||
} else {
|
||||
Tabzilla.detectUserLang(doSomething);
|
||||
}
|
||||
|
||||
.. note:: Though the Translation Bar is currently implemented as an extension of Tabzilla, it might be moved to a standalone language utility in the future.
|
||||
|
|
Загрузка…
Ссылка в новой задаче