Browse Source

Allow easy extensions of supported languages.

pull/17/merge
Simon Eisenmann 12 years ago
parent
commit
a77297ab5a
  1. 2
      html/main.html
  2. 3
      src/app/spreed-speakfreely-server/main.go
  3. 8
      src/i18n/Makefile
  4. 13
      src/i18n/README.txt
  5. 18
      src/i18n/helpers/languages.py
  6. 41
      static/js/app.js
  7. 16
      static/js/directives/settings.js
  8. 4
      static/js/services/mediastream.js
  9. 6
      static/partials/settings.html
  10. 4
      static/translation/languages.js

2
html/main.html

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<%define "mainPage"%><!doctype html>
<html class="no-js" lang="<% index .Languages 0%>" itemscope="itemscope" itemtype="http://schema.org/WebPage">
<html class="no-js" itemscope="itemscope" itemtype="http://schema.org/WebPage">
<head>
<%template "head" .%>
</head>

3
src/app/spreed-speakfreely-server/main.go

@ -100,8 +100,7 @@ func handleRoomView(room string, w http.ResponseWriter, r *http.Request) { @@ -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")
}

8
src/i18n/Makefile

@ -8,6 +8,11 @@ ROOT := "$(CURDIR)/../.." @@ -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: @@ -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

13
src/i18n/README.txt

@ -0,0 +1,13 @@ @@ -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``

18
src/i18n/helpers/languages.py

@ -0,0 +1,18 @@ @@ -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()

41
static/js/app.js

@ -31,6 +31,8 @@ define([ @@ -31,6 +31,8 @@ define([
'filters/filters',
'controllers/controllers',
'translation/languages',
'ui-bootstrap',
'angular-sanitize',
'angular-animate',
@ -39,7 +41,7 @@ define([ @@ -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([ @@ -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([ @@ -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<browserLanguages.length; i++) {
if (languages.hasOwnProperty(browserLanguages[i])) {
lang = browserLanguages[i];
break;
}
}
}
if (!lang) {
lang = "en";
}
html.setAttribute("lang", lang);
return lang;
}());
// Prepare bootstrap function with injected locale data.

16
static/js/directives/settings.js

@ -18,11 +18,11 @@ @@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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) { @@ -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;

4
static/js/services/mediastream.js

@ -28,10 +28,8 @@ define([ @@ -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);

6
static/partials/settings.html

@ -54,11 +54,7 @@ @@ -54,11 +54,7 @@
<div class="form-group">
<label class="col-xs-4 control-label">{{_('Language')}}</label>
<div class="col-xs-8">
<select class="form-control" ng-model="user.settings.language">
<option value="">{{_('Use browser language')}}</option>
<option value="de">Deutsch</option>
<option value="en">English</option>
</select>
<select class="form-control" ng-model="user.settings.language" ng-options="l.code as l.name for l in availableLanguages | orderBy:'code'"></select>
<span class="help-block">{{_('Language changes become active on reload.')}}</span>
</div>
</div>

4
static/translation/languages.js

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
// This file is auto generated, do not modify.
define([], function() {
return {'de': 'Deutsch', 'en': 'English'};
});
Loading…
Cancel
Save