Comments (3)
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.
OK - I think your idea is a simpler option and will review how to implement this and get back to you.
from angularjs-localizationservice.
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)
- Why 'localize' service is always running HOT 4
- Fall back on default resource file when key is not present in localized resource file HOT 3
- Translating placeholder attributes HOT 1
- dictionary returns undefined HOT 2
- Dynamic model and translate HOT 1
- PRoblem with IE8 HOT 3
- Changing file extension for dictionaries from .js to .json HOT 1
- Wrong URL for resources-locale_default.js HOT 1
- HTML in JSON not rendered HOT 1
- using i18n for localization does not show translation in internet explorer (IE) 9 HOT 2
- Further thoughts and scope of localization on larger applications
- Could not able to parse French special characters HOT 4
- i18n filter HOT 8
- getLocalizedString filter returns an array!
- Not compatible with angular 1.3 HOT 1
- How to add a i18n label in a js file HOT 1
- Dynamic Dom HOT 1
- Pre-included localization .js files HOT 2
- i18nAttr not updated HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularjs-localizationservice.