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 20 posts 162 karma points
    1 week ago
    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 90 posts 379 karma points
    1 week ago
    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 20 posts 162 karma points
    1 week ago
    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 20 posts 162 karma points
    1 week ago
    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 11256 posts 23495 karma points MVP 7x admin c-trib
    1 week ago
    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 90 posts 379 karma points
    1 week ago
    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 11256 posts 23495 karma points MVP 7x admin c-trib
    1 week ago
    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 20 posts 162 karma points
    1 week ago
    Peter van den Dungen
    0

    Hi Jan,

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

  • iNETZO 90 posts 379 karma points
    1 week ago
    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 20 posts 162 karma points
    1 week ago
    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