diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 29da6724..54e622ae 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -43,11 +43,13 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $compil # $httpProvider.responseInterceptors.push('authHttpIntercept') -init = ($log, $rootScope) -> +init = ($log, $i18n, $config, $rootscope) -> + $i18n.initialize($config.get("defaultLanguage")) $log.debug("Initialize application") + configure.$inject = ["$routeProvider", "$locationProvider", "$httpProvider"] -init.$inject = ["$log", "$rootScope"] +init.$inject = ["$log", "$tgI18n", "$tgConfig","$rootScope"] modules = [ # Main Modules diff --git a/app/coffee/config.coffee b/app/coffee/config.coffee index 5e569821..d3660e2c 100644 --- a/app/coffee/config.coffee +++ b/app/coffee/config.coffee @@ -34,9 +34,9 @@ class ConfigService get: (key, defaultValue=null) -> return @.config[key] || defaultValue - +# Initialize config loading local configuration. init = ($log, localconfig, config) -> - $log.debug("Initializing configuration") + $log.debug("Initializing configuration", localconfig) config.initialize(localconfig) module = angular.module("taigaConfig", ["taigaLocalConfig"]) diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee index 79c289ce..9c91a272 100644 --- a/app/coffee/modules/base.coffee +++ b/app/coffee/modules/base.coffee @@ -1 +1,22 @@ -module = angular.module("taigaBase", []) +### +# Copyright (C) 2014 Andrey Antukh +# Copyright (C) 2014 Jesús Espino Garcia +# Copyright (C) 2014 David Barragán Merino +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: modules/base.coffee +### + +module = angular.module("taigaBase", ["taigaLocales"]) diff --git a/app/coffee/modules/base/i18n.coffee b/app/coffee/modules/base/i18n.coffee new file mode 100644 index 00000000..553d847f --- /dev/null +++ b/app/coffee/modules/base/i18n.coffee @@ -0,0 +1,76 @@ +### +# Copyright (C) 2014 Andrey Antukh +# Copyright (C) 2014 Jesús Espino Garcia +# Copyright (C) 2014 David Barragán Merino +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: modules/base/i18n.coffee +### + +taiga = @.taiga +bindOnce = @.taiga.bindOnce + +defaults = { + ns: "app" + fallbackLng: "en" + async: false +} + + +class I18nService extends taiga.TaigaService + @.$inject = ["$rootScope", "localeEnglish"] + constructor: (@rootscope, @localeEn) -> + + setLanguage: (language) -> + options = _.clone(defaults, true) + i18n.setLng(language, options) + + @rootscope.currentLang = language + @rootscope.$broadcast("i18n:changeLang", language) + + initialize: (defaultLang="en") -> + options = _.clone(defaults, true) + options.lng = defaultLang + options.resStore = { + en: { app: @localeEn } + } + i18n.init(options) + @rootscope.t = i18n.t + + +I18nDirective = ($rootscope, $i18n) -> + link = ($scope, $el, $attrs) -> + values = $attrs.tgI18n.split(",") + options = $attrs.tgI18nOptions or '{}' + + applyTranslation = -> + opts = $scope.$eval(options) + + for v in values + if v.indexOf(":") == -1 + element.html($scope.t(v, opts)) + else + [ns, v] = v.split(":") + element.attr(ns, $scope.t(v, opts)) + + bindOnce(scope, "t", applyTranslation) + $scope.$on("i18n:changeLang", applyTranslation) + + return {link: link} + + +module = angular.module("taigaBase") +module.service("$tgI18n", ["$rootScope", I18nService]) +module.directive("tgI18n", ["$rootScope", "$tgI18n", I18nDirective])