diff --git a/src/js/setupaccount.js b/src/js/setupaccount.js index d5cb3be37..ebfd05435 100644 --- a/src/js/setupaccount.js +++ b/src/js/setupaccount.js @@ -3,7 +3,7 @@ /* global angular, $, showdown */ // create main application module -var app = angular.module('Application', []); +var app = angular.module('Application', ['pascalprecht.translate', 'ngCookies']); app.filter('markdown2html', function () { var converter = new showdown.Converter({ @@ -23,7 +23,44 @@ app.config(function ($sceProvider) { $sceProvider.enabled(false); }); -app.controller('SetupAccountController', ['$scope', '$http', function ($scope, $http) { +app.config(['$translateProvider', function ($translateProvider) { + $translateProvider.useStaticFilesLoader({ + prefix: 'translation/', + suffix: '.json' + }); + $translateProvider.useLocalStorage(); + $translateProvider.preferredLanguage('en'); + $translateProvider.fallbackLanguage('en'); +}]); + +// Add shorthand "tr" filter to avoid having ot use "translate" +// This is a copy of the code at https://github.com/angular-translate/angular-translate/blob/master/src/filter/translate.js +// If we find out how to get that function handle somehow dynamically we can use that, otherwise the copy is required +function translateFilterFactory($parse, $translate) { + + 'use strict'; + + var translateFilter = function (translationId, interpolateParams, interpolation, forceLanguage) { + if (!angular.isObject(interpolateParams)) { + var ctx = this || { + '__SCOPE_IS_NOT_AVAILABLE': 'More info at https://github.com/angular/angular.js/commit/8863b9d04c722b278fa93c5d66ad1e578ad6eb1f' + }; + interpolateParams = $parse(interpolateParams)(ctx); + } + + return $translate.instant(translationId, interpolateParams, interpolation, forceLanguage); + }; + + if ($translate.statefulFilter()) { + translateFilter.$stateful = true; + } + + return translateFilter; +} +translateFilterFactory.displayName = 'translateFilterFactory'; +app.filter('tr', translateFilterFactory); + +app.controller('SetupAccountController', ['$scope', '$translate', '$http', function ($scope, $translate, $http) { // Stupid angular location provider either wants html5 location mode or not, do the query parsing on my own var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.indexOf('=') === -1 ? [item, true] : [item.slice(0, item.indexOf('=')), item.slice(item.indexOf('=')+1)]; }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {}); @@ -97,6 +134,8 @@ app.controller('SetupAccountController', ['$scope', '$http', function ($scope, $ if (status !== 200) return; + if (data.language) $translate.use(data.language); + $scope.status = data; }).error(function () { $scope.initialized = false; diff --git a/src/setupaccount.html b/src/setupaccount.html index 29a045fac..99dd17f81 100644 --- a/src/setupaccount.html +++ b/src/setupaccount.html @@ -13,7 +13,7 @@ - + @@ -29,13 +29,20 @@ + - + + + + + + + @@ -52,8 +59,8 @@

-

Welcome to {{ status.cloudronName || 'Cloudron' }}

-

Please setup your account

+

{{ 'setupAccount.welcomeTo' | tr }} {{ status.cloudronName || 'Cloudron' }}

+

{{ 'setupAccount.description' | tr }}


@@ -68,37 +75,37 @@
- +
- The username is too short - The username is too long - Not a valid username + {{ 'setupAccount.errorUsernameTooShort' | tr }} + {{ 'setupAccount.errorUsernameTooLong' | tr }} + {{ 'setupAccount.errorUsernameInvalid' | tr }}
- - + +
- +
- Password must be at least 8 characters + {{ 'setupAccount.errorPassword' | tr }}
- +
- +
- Passwords don't match + {{ 'setupAccount.errorPasswordNoMatch' | tr }}
- +
- + @@ -111,9 +118,9 @@

-

Invalid or Expired Invite Link

+

{{ 'setupAccount.invalidToken.title' | tr }}


-

Contact your server admin to get a new invite link.

+

{{ 'setupAccount.invalidToken.description' | tr }}

@@ -125,9 +132,9 @@

-

Your Account is ready

+

{{ 'setupAccount.success.title' | tr }}


- Open Dashboard + {{ 'setupAccount.success.openDashboardAction' | tr }}
diff --git a/src/translation/en.json b/src/translation/en.json index bbd6a5974..1bfcdbd58 100644 --- a/src/translation/en.json +++ b/src/translation/en.json @@ -1293,5 +1293,27 @@ "title": "Password changed", "openDashboardAction": "Open Dashboard" } + }, + "setupAccount": { + "welcomeTo": "Welcome to", + "description": "Please setup your account", + "username": "Username", + "errorUsernameTooShort": "The username is too short", + "errorUsernameTooLong": "The username is too long", + "errorUsernameInvalid": "Not a valid username", + "fullName": "Full Name", + "password": "New Password", + "passwordRepeat": "Repeat Password", + "errorPassword": "Password must be at least 8 characters", + "errorPasswordNoMatch": "Passwords don't match", + "setupAction": "Setup", + "invalidToken": { + "title": "Invalid or Expired Invite Link", + "description": "Contact your server admin to get a new invite link." + }, + "success": { + "title": "Your Account is ready", + "openDashboardAction": "Open Dashboard" + } } }