eventsService problem regarding Languagechange
# help-with-umbraco
l
I've never been able to really figure out what the correct solution is, but this works really well (in Umbraco 13): When initializing my angular controller, I set the current language: /** The current content language */ vm.contentLanguage = $routeParams.mculture Then I initialize an event handler that watches it: /** Initializes event handlers */ function initEventHandlers() { // Event handler for when the content language changes. This is needed to reload the dashboard when the editor changes the content language in the backoffice $scope.$watch(function () { return $routeParams.mculture; }, function (newLanguage, oldLanguage) { if (newLanguage !== oldLanguage) { vm.contentLanguage = newLanguage; reloadDashboard(); } }); }
t
That makes alot of sense, thanks. Different approach but it does what it needs to
l
Yeah it's just a shame it relies on the route parameters (in essence the querystring). So far it seems to work reliably, but still it's not the most elegant solution. I'd rather have an event, but the documentation is so minimal, I couldn't find it
t
I have been scratching my head at it, but this will work for now, I'll inform you if I find an easier way haha
the errors can be ignored, not relevant to my current problem
I already tried to remove the ChangeHandler out of updateContent
l
let me see if I can substract a full controller with only the essentials
This is the essentials:
Copy code
angular.module('umbraco').controller('controllername', function ($scope, $routeParams) {
    /** The viewmodel that is used on the view (html file) */
    let vm = this;

    /** Performs all functions that are needed on a first load */
    function init() {
        initEventHandlers();
    }

    /** Initializes event handlers */
    function initEventHandlers() {

        // Event handler for when the content language changes. This is needed to reload the dashboard when the editor changes the content language in the backoffice
        $scope.$watch(function () {
            return $routeParams.mculture;
        }, function (newLanguage, oldLanguage) {
            if (newLanguage !== oldLanguage) {
                vm.contentLanguage = newLanguage;
                
                //MAGIC HERE
            }
        });
    }

    init();
});
t
does the namesaking matter? like newLanguage & oldLanguage? because I cant seem to find any difference.
Except for putting the eventhandler in init() then calling init()
l
Do you call init() (last line)
It's an event handler, so it only needs to be registered once
t
yeah, I did that
I did some debugging and it doesnt reach the if statement of having a new language, and logging my curent language shows the wrong language
so maybe it goes wrong there
l
I don't think so, I don't have those names anywhere in the controller except there
Do you have the mculture in the querystring in the backoffice?
l
not sure if it's just different syntax, but my definition is like this: angular.module('umbraco').controller('#CONTROLLERNAME#', function ($scope, $http, $routeParams, appState, eventsService) {
t
I think I know the issue
mculture=nl-NL&cculture=en-GB I should be checking for the cculture I think
since Im changing the language up above
im working in a contentApp
that seems to have been the issue 😅 note to self: "give more context"
l
hmm, not sure, I thought the mculture is the content language and cculture the language of the backoffice
In this case it's the content language that changes, because I have a dashboard that depends on the selected content language
t
you make a fair point, I'd have to discuss what would make more sense in the context of what im building, but i'd like to thank you very much for your help <3
l
no problem. If you find a way to have an actual event for changing the language, I'd love to hear it 😛
t
will do o7
4 Views