diff --git a/Gruntfile.js b/Gruntfile.js index c08c6ba..d3935ec 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -62,8 +62,9 @@ module.exports = function(grunt) { 'app/controllers/controller.js', 'app/controllers/config.controller.js', 'app/directives/archetypeproperty.js', - 'app/resources/propertyeditor.js', - 'app/filters/locale.js' + 'app/directives/localize.js', + 'app/services/localization.js', + 'app/resources/propertyeditor.js' ], dest: '<%= dest %>/js/archetype.js' } @@ -107,9 +108,7 @@ module.exports = function(grunt) { {expand: true, cwd: 'app/', src: ['package.manifest'], dest: '<%= dest %>', flatten: true}, {expand: true, cwd: 'app/views/', src: ['archetype.html', 'archetype.config.html'], dest: '<%= dest %>/views', flatten: true}, {expand: true, cwd: 'app/config/', src: ['propertyEditors.views.js'], dest: '<%= dest %>/js', flatten: true}, - {expand: true, cwd: 'app/config/', src: ['en-gb.js'], dest: '<%= dest %>/js', flatten: true}, - {expand: true, cwd: 'app/config/', src: ['en-us.js'], dest: '<%= dest %>/js', flatten: true}, - {expand: true, cwd: 'app/config/', src: ['fr-fr.js'], dest: '<%= dest %>/js', flatten: true}, + {expand: true, cwd: 'app/langs/', src: ['**'], dest: '<%= dest %>/langs', flatten: true}, {expand: true, cwd: 'app/Umbraco/Umbraco.Archetype/bin/Debug/', src: ['Archetype.dll'], dest: '<%= dest %>/bin', flatten: true} ] }, diff --git a/app/controllers/config.controller.js b/app/controllers/config.controller.js index 26c760b..9ad4d38 100644 --- a/app/controllers/config.controller.js +++ b/app/controllers/config.controller.js @@ -1,4 +1,4 @@ -angular.module("umbraco").controller("Imulus.ArchetypeConfigController", function ($scope, $http, assetsService, dialogService, archetypePropertyEditorResource, userService) { +angular.module("umbraco").controller("Imulus.ArchetypeConfigController", function ($scope, $http, assetsService, dialogService, archetypePropertyEditorResource) { //$scope.model.value = ""; //console.log($scope.model.value); @@ -10,7 +10,6 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio //ini the model $scope.model.value = $scope.model.value || defaultFieldsetConfigModel; - $scope.locales = {} //ini the render model initConfigRenderModel(); @@ -20,32 +19,6 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio $scope.availableDataTypes = data; }); - archetypePropertyEditorResource.getDefaultLocale().then(function(defaultLocale){ - $scope.locales.defaultLocale = defaultLocale; - }); - - //load the localization info - userService.getCurrentUser() - .then(function (user) { - return user.locale; - }) - .then(function(langIso){ - archetypePropertyEditorResource.getLocale(langIso) - .then(function(locale){ - $scope.locales.locale = locale; - }); - }); - - $scope.getLocales = function(){ - if($scope.locales){ - - if(!$scope.locales.locale) - $scope.locales.locale = $scope.locales.defaultLocale; - - return $scope.locales; - } - } - //iconPicker $scope.selectIcon = function(fieldset){ var dialog = dialogService.iconPicker({ @@ -53,7 +26,6 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio fieldset.icon = data; } }); - } //config for the sorting diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index 60c21b9..8355696 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -1,4 +1,4 @@ -angular.module("umbraco").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper) { +angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper) { function getFieldsetByAlias(fieldsets, alias) { diff --git a/app/directives/localize.js b/app/directives/localize.js new file mode 100644 index 0000000..9eae6b6 --- /dev/null +++ b/app/directives/localize.js @@ -0,0 +1,21 @@ +angular.module("umbraco.directives").directive('archetypeLocalize', function (archetypeLocalizationService) { + var linker = function (scope, element, attrs){ + + var key = scope.key; + + archetypeLocalizationService.localize(key).then(function(value){ + if(value){ + element.html(value); + } + }); + } + + return { + restrict: "E", + rep1ace: true, + link: linker, + scope: { + key: '@' + } + } +}); \ No newline at end of file diff --git a/app/config/en-GB.js b/app/langs/en-gb.js similarity index 100% rename from app/config/en-GB.js rename to app/langs/en-gb.js diff --git a/app/config/en-us.js b/app/langs/en-us.js similarity index 100% rename from app/config/en-us.js rename to app/langs/en-us.js diff --git a/app/config/fr-fr.js b/app/langs/fr-fr.js similarity index 100% rename from app/config/fr-fr.js rename to app/langs/fr-fr.js diff --git a/app/resources/propertyeditor.js b/app/resources/propertyeditor.js index a55d7dc..b26d8bb 100644 --- a/app/resources/propertyeditor.js +++ b/app/resources/propertyeditor.js @@ -7,7 +7,7 @@ angular.module('umbraco.resources').factory('archetypePropertyEditorResource', f ).then(function (data) { return data.map(function(d) { return { "id": d.id, "name": d.name } - }); + }); }); }, getDataType: function(id) { @@ -28,16 +28,6 @@ angular.module('umbraco.resources').factory('archetypePropertyEditorResource', f return ""; }); - }, - getLocale: function(langIso) { - return umbRequestHelper.resourcePromise( - $http.get("/App_plugins/Archetype/js/" + langIso.toLowerCase() + ".js"), 'Failed to retrieve locale' - ); - }, - getDefaultLocale: function() { - return umbRequestHelper.resourcePromise( - $http.get("/App_plugins/Archetype/js/en-us.js"), 'Failed to retrieve default locale' - ); } - }; -}); + } +}); \ No newline at end of file diff --git a/app/services/localization.js b/app/services/localization.js new file mode 100644 index 0000000..1f4fc51 --- /dev/null +++ b/app/services/localization.js @@ -0,0 +1,42 @@ +angular.module('umbraco.services').factory('archetypeLocalizationService', function($http, $q, userService){ + var service = { + resourceFileLoaded: false, + dictionary: {}, + localize: function(key) { + var deferred = $q.defer(); + + if(service.resourceFileLoaded){ + var value = service._lookup(key); + deferred.resolve(value); + } + else{ + service.initLocalizedResources().then(function(dictionary){ + var value = service._lookup(key); + deferred.resolve(value); + }); + } + + return deferred.promise; + }, + _lookup: function(key){ + return service.dictionary[key]; + }, + initLocalizedResources:function () { + var deferred = $q.defer(); + userService.getCurrentUser().then(function(user){ + $http.get("/App_plugins/Archetype/langs/" + user.locale + ".js") + .then(function(response){ + service.resourceFileLoaded = true; + service.dictionary = response.data; + + return deferred.resolve(service.dictionary); + }, function(err){ + return deferred.reject("Lang file missing"); + }); + }); + return deferred.promise; + } + } + + return service; +}); \ No newline at end of file diff --git a/app/views/archetype.config.html b/app/views/archetype.config.html index d2b7bba..187e5bb 100644 --- a/app/views/archetype.config.html +++ b/app/views/archetype.config.html @@ -10,23 +10,23 @@