Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter van den Dungen 66 posts 365 karma points
    Jun 30, 2020 @ 14:58
    Peter van den Dungen
    0

    Umbraco localize one button in BO

    Hi,

    I used the Config/Lang/nl_NL.user.xml to translate several BO action buttons. Those translations are applied on all buttons, but I want to change one translation for one specific button.

    How can I do that?

  • iNETZO 133 posts 496 karma points c-trib
    Jun 30, 2020 @ 21:35
    iNETZO
    100

    Hi Peter,

    I sometimes change the text of a button or a label or other element by using an angular interceptor to catch the view html and simply replace it the output-html via javascript.

    For example:

    angular.module('umbraco.services').config([
        '$httpProvider',
        function ($httpProvider) {
    
            $httpProvider.interceptors.push(function ($q) {
                return {
                    'response': function (response) {
    
                        if (response.config.url.indexOf("views/propertyeditors/listview/listview.html") === 0) {
    
                            response.data = response.data.replace('current-button-text', 'new-button-text');
    
                        }
    
                        return response;
                    }
                };
            });
    
        }]);
    

    When the text is not in a view but in a directive, than it's a lot more difficult to change it because, as far as i know, an directive can not be intercepted.

    Best regards,

    iNETZO

  • Peter van den Dungen 66 posts 365 karma points
    Jul 01, 2020 @ 08:30
    Peter van den Dungen
    0

    Hi iNETZO,

    I got it all working, thanks for the reply.

    For others: I created a 'Tweaks' folder inside the App_Plugins folder, with a package.manifest and tweaks.js. (here I pasted the code of iNETZO)

    Find more info here: https://24days.in/umbraco-cms/2015/umbraco-7-back-office-tweaks/

  • Peter van den Dungen 66 posts 365 karma points
    Jul 01, 2020 @ 11:22
    Peter van den Dungen
    0

    One little question, inside the response I am not able to read the ID of the current content I am editing, is this possible some way?

    angular.module('umbraco.services').config([
    '$httpProvider',
    function ($httpProvider) {
        $httpProvider.interceptors.push(function ($q) {
            return {
                'response': function (response) {
    
                    if (response.config.url.indexOf("views/propertyeditors/listview/listview.html") === 0) {
    
                            response.data = response.data.replace('<localize key="actions_create">Create</localize>', 'Nieuwe');
    
                    }
    
                    return response;
                }
            };
        });
    
    }]);
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 01, 2020 @ 20:19
    Jan Skovgaard
    0

    Hi Peter

    Just out of curiosity - What is the exact version number of Umbraco 8 where you're doing this? The reason I'm asking is that since Umbraco 8.1.0 the interceptor approach should not really work anymore according to Nathan's post here https://nathanw.com.au/post/replacing-interceptors-with-directive-injection/

    But of course if it's an earlier release of v8 then no problem :-) Just be aware that this approach might stop working if the solution is ever upgraded.

    /Jan

  • iNETZO 133 posts 496 karma points c-trib
    Jul 01, 2020 @ 20:25
    iNETZO
    0

    Hi Jan,

    Thanks for this tip. While I'm still succesfully using interceptors in 8.6.3, i will take a look if it's possible to convert mines to directives.

    Cheers

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 01, 2020 @ 20:55
    Jan Skovgaard
    0

    Interesting - I recently did a content app where the interceptors approach would have been very useful but ran into the issue Nathan mentioned but I guess it depends what you're doing whether the approach still works or not.

    Good to know :-)

    Cheers!

  • Peter van den Dungen 66 posts 365 karma points
    Jul 01, 2020 @ 21:41
    Peter van den Dungen
    0

    Hi Jan,

    The Umbraco version is on 8.6.2 and its working ok it seems!

  • iNETZO 133 posts 496 karma points c-trib
    Jul 01, 2020 @ 20:01
    iNETZO
    0

    The only way i can think of is extracting it from the url. As far as I know there is no (easy) way to inject an editorState. Perhaps something like this?

                        var nodeId = (window.location.href.match(/edit\/(\d+)$/) || []).pop();
                        if (nodeId) {
                            // Do something with the node id
                        }
    

    Can you give some more context what you want to do with it?

    Cheers

  • Peter van den Dungen 66 posts 365 karma points
    Jul 01, 2020 @ 21:48
    Peter van den Dungen
    0

    Hi iNTENSO,

    I will give it a try tomorrow!

    In the Umbraco backend there are lots of document types with child nodes, inside the list view there is a button to create new nodes, the 'action_create' button.

    I want to override the default 'New' localization in the button for only one single document type.

    The interceptor is changing the text for all of them, I also played a bit with JS there to get the ID extracted from the URL, but it failed in the angular.js, some issue with a angular promises and didn't figure it out yet.

Please Sign in or register to post replies

Write your reply to:

Draft