diff --git a/html/main.html b/html/main.html index 738c994d..1708524a 100644 --- a/html/main.html +++ b/html/main.html @@ -1,5 +1,5 @@ <%define "mainPage"%> - + <%template "head" .%> diff --git a/src/app/spreed-speakfreely-server/main.go b/src/app/spreed-speakfreely-server/main.go index 9265af23..fb1a68d8 100644 --- a/src/app/spreed-speakfreely-server/main.go +++ b/src/app/spreed-speakfreely-server/main.go @@ -100,8 +100,7 @@ func handleRoomView(room string, w http.ResponseWriter, r *http.Request) { } // Get languages from request. - // TODO(longsleep): Added supported and default language to configuration. - langs := getRequestLanguages(r, []string{"en", "de"}) + langs := getRequestLanguages(r, []string{}) if len(langs) == 0 { langs = append(langs, "en") } diff --git a/src/i18n/Makefile b/src/i18n/Makefile index 40da21ae..e94f4421 100644 --- a/src/i18n/Makefile +++ b/src/i18n/Makefile @@ -8,6 +8,11 @@ ROOT := "$(CURDIR)/../.." NODEJS := nodejs PYBABEL := pybabel NODE_PATH := /usr/local/lib/node_modules:/usr/lib/node_modules +PYTHON := python + +build: update + NODE_PATH=$(NODE_PATH) $(NODEJS) helpers/po2json messages-de.po $(ROOT)/static/translation/messages-de.json + $(PYTHON) helpers/languages.py >$(ROOT)/static/translation/languages.js extract: $(PYBABEL) extract -F babel.cfg -k _n:1,2 -k _ \ @@ -24,6 +29,3 @@ extract: update: $(PYBABEL) update -l de -i messages.pot -o messages-de.po - -build: update - NODE_PATH=$(NODE_PATH) $(NODEJS) helpers/po2json messages-de.po $(ROOT)/static/translation/messages-de.json \ No newline at end of file diff --git a/src/i18n/README.txt b/src/i18n/README.txt new file mode 100644 index 00000000..f360f61e --- /dev/null +++ b/src/i18n/README.txt @@ -0,0 +1,13 @@ +Rebuild pot file from source (only do that on template or JavaScript changes) + ``make extract`` + +Merge po files with pot file (always do this before translating) + ``make update`` + +Create JavaScript translation fiels from po files (do this when finished translating) + ``make build`` + +Create a new translation (obvious) + ``cp messages.pot messages-$(ISO-639-1).po`` + Add new ISO-639-1 line to helpers/languages.py including translated language name. + ``make build`` diff --git a/src/i18n/helpers/languages.py b/src/i18n/helpers/languages.py new file mode 100644 index 00000000..c0a61e73 --- /dev/null +++ b/src/i18n/helpers/languages.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# Generate simple languages JSON module. + +LANGUAGES = { + "en": "English", + "de": "Deutsch", +} + +def main(): + + print """// This file is auto generated, do not modify. +define([], function() { +return %r; +});""" % LANGUAGES + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/static/js/app.js b/static/js/app.js index 02bfa9bd..cd3cfe90 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -31,6 +31,8 @@ define([ 'filters/filters', 'controllers/controllers', + 'translation/languages', + 'ui-bootstrap', 'angular-sanitize', 'angular-animate', @@ -39,7 +41,7 @@ define([ 'mobile-events', 'dialogs' -], function(require, $, _, angular, modernizr, moment, services, directives, filters, controllers) { +], function(require, $, _, angular, modernizr, moment, services, directives, filters, controllers, languages) { var initialize = function(ms) { @@ -72,9 +74,14 @@ define([ mediaStream.initialize($rootScope, translation); }]); + app.constant("availableLanguages", languages); + angular.element(document).ready(function() { - // Detect language. + var globalContext = JSON.parse($("#globalcontext").text()); + app.constant("globalContext", globalContext); + + // Configure language. var lang = (function() { var lang; var html = document.getElementsByTagName("html")[0]; @@ -84,16 +91,28 @@ define([ lang = null; } } - if (lang) { - html.setAttribute("lang", lang); - return lang; - } else { - try { - return html.getAttribute("lang"); - } catch(e) { - return "en"; - }; + if (!lang) { + var browserLanguages = []; + // Expand browser languages with combined fallback. + _.each(globalContext.Languages, function(l) { + browserLanguages.push(l); + if (l.indexOf("-") != -1) { + browserLanguages.push(l.split("-")[0]) + } + }); + // Loop through browser languages and use first one we got. + for (var i=0; i. * */ -define(['text!partials/settings.html'], function(template) { +define(['underscore', 'text!partials/settings.html'], function(_, template) { return ["$compile", function($compile) { - var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', function($scope, desktopNotify, mediaSources, safeApply) { + var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation) { $scope.layout.settings = false; $scope.showAdvancedSettings = true; @@ -31,6 +31,18 @@ define(['text!partials/settings.html'], function(template) { $scope.rememberSettings = true; $scope.desktopNotify = desktopNotify; $scope.mediaSources = mediaSources; + $scope.availableLanguages = [ + { + code: "", + name: translation._("Use browser language") + } + ]; + _.each(availableLanguages, function(name, code) { + $scope.availableLanguages.push({ + code: code, + name: name + }); + }); var localStream = null; diff --git a/static/js/services/mediastream.js b/static/js/services/mediastream.js index 2867b6b8..dba3cc43 100644 --- a/static/js/services/mediastream.js +++ b/static/js/services/mediastream.js @@ -28,10 +28,8 @@ define([ ], function($, _, Connector, Api, WebRTC, tokens) { - return ["$route", "$location", "$window", "visibility", "alertify", "$http", "safeApply", "$timeout", function($route, $location, $window, visibility, alertify, $http, safeApply, $timeout) { + return ["globalContext", "$route", "$location", "$window", "visibility", "alertify", "$http", "safeApply", "$timeout", function(context, $route, $location, $window, visibility, alertify, $http, safeApply, $timeout) { - var globalcontext = $("#globalcontext").text(); - var context = JSON.parse(globalcontext); var url = (context.Ssl ? "wss" : "ws") + "://" + context.Host + (context.Cfg.B || "/") + "ws"; var version = context.Cfg.Version || "unknown"; console.log("Service version: "+version); diff --git a/static/partials/settings.html b/static/partials/settings.html index 6884d040..9e0ce4de 100644 --- a/static/partials/settings.html +++ b/static/partials/settings.html @@ -54,11 +54,7 @@
- + {{_('Language changes become active on reload.')}}
diff --git a/static/translation/languages.js b/static/translation/languages.js new file mode 100644 index 00000000..dcafd89d --- /dev/null +++ b/static/translation/languages.js @@ -0,0 +1,4 @@ +// This file is auto generated, do not modify. +define([], function() { +return {'de': 'Deutsch', 'en': 'English'}; +});