Angular localization service - When to call it?
# help-with-umbraco
a
When using the localization service in a controller, does it need to be called and a variable assigned at load time? I was hoping to be able to call the service on a callback, however when I try this I get no message returned. For example, the code below shows a success notification with no content:
Copy code
javascript
umbCheckoutStripeTaxRateResources.createTaxRate(configurationValues)
                    .then(function (response) {
                        localizationService.localize("umbcheckoutstripe_tax_rate_notification_created_title").then(function (value) {
                            vm.notificationTitle = value;
                        });
                        localizationService.localize("umbcheckoutstripe_tax_rate_notification_created_message").then(function (value) {
                            vm.notificationMessage = value;
                        });

                        vm.properties = response.data.properties
                        notificationsService.success(vm.notificationTitle, vm.notificationMessage);
                        vm.saveButtonState = "success";
                        $scope.taxRateForm.$dirty = false;
                        $location.path("/settings/UmbCheckout/StripeTaxRate/" + response.data.key);
                    })
However if I load it right at the top of the controller and assign it to a variable it works, but means tons of variables assign at load up
a
Hmm @AaronSadlerUK as far as I know it should work
Copy code
javascript

                    organizationMembersApiResource.createMemberGroup(vm.newMemberGroupName, $scope.model.org.id).then(function (response) {
                        if (response.succeeded) {
                            eventsService.emit("memberGroup.created", response.content);
                            editorService.closeAll();
                            localizationService.localize("pbiMember_memberGroupCreated").then(function (value) {
                                notificationsService.success("Success:", value);
                            });
This is from my own code, it worked in the past though (v10)
a
I wonder, does the value get disposed off 🤔... I mean it shouldn't after it's been assigned, well I hope not 😅
n
Localize is asynchronous, so your notification is displaying before the localized string is returned. I'd consider localizing on the server and returning on your first request, otherwise you quickly end up in callback hell (or convert it all to async/await)
a
I've nested them for now and it works, which is fine for the notifications. I know next to no Angularjs to this will do 😂 I didn't realise it was a async request though, so that answers that, thanks!
4 Views