Coder Social home page Coder Social logo

Comments (3)

lavinjj avatar lavinjj commented on June 13, 2024

You could do that, but I would probably just use additional tags in the dictionary object itself that include the path to the image and then use the i18nAttr directive to set the src attribute. But your way will also work. If you want fork the current code and add the functionality and send me a pull request and I'll be happy to include it in the current code stream.

from angularjs-localizationservice.

MarkAPhillips avatar MarkAPhillips commented on June 13, 2024

OK - I think your idea is a simpler option and will review how to implement this and get back to you.

from angularjs-localizationservice.

MarkAPhillips avatar MarkAPhillips commented on June 13, 2024

I decided to try the initial approach as follows:

  // builds the url for locating an image
                buildImgUrl: function(imageUrl) {
                    return $http({ method: "GET", url: imageUrl, cache: false });
                },

  // translation directive that handles the localization of images.
    // usage <img data-i18n-img-src="IMAGE" />
    .directive('i18nImgSrc', [
        'localize', function(localize) {
            var i18NImageDirective = {
                restrict: 'A',
                link: function(scope, element, attrs) {
                    var i18Nsrc = attrs.i18nImgSrc;
                    var imagePath = '/i18N/images/' + localize.language + '/';
                    var imageUrl = imagePath + i18Nsrc;
                    localize.buildImgUrl(imageUrl).success(function() {
                        element[0].src = imageUrl;
                    }).error(function() { element[0].src = '/i18N/images/default/' + i18Nsrc; });
                }
            };
            return i18NImageDirective;
        }
    ]);

This was a first iteration - but would be interested in any feedback in relation to improving the code Thanks.

from angularjs-localizationservice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.