angularjs-localizationservice
angularjs-localizationservice copied to clipboard
dictionary returns undefined
Hi everyone,
I know that it's maybe not an issue of the provided localization service, but I couldn't get help elsewhere. [http://codingsmackdown.tv/blog/2012/12/14/localizing-your-angularjs-app/#comments - This site doesn't accept new comments somehow :/ and I didn't manage to get a contact email-address].
I'm just quoting what i tried to post in the comments twice in several days:
"I'm new to Angular and web-development in general.
I'm trying to include this localization feature into my app, but I'm stuck for quite some time now. I think the error in my case occurs in the following code:
var entry = $filter('filter')(localize.dictionary, function(element) { return element.key === value; } )[0];
The dictionary is filled with the whole JSON-file, but the entry variable is set to "undefined" afterwards.
Does someone know whats going on there?
Kind regards from Germany
Nils"
It would be nice, if someone could help. If you think that this is the wrong place for this, don't hesitate to close/delete it ;).
It sounds as if the element.key is not matching the value being passed into as value. What is happening in the code you posted above is angular walks each item in the localize.dictionary array and checks to see if the element.key matches the passed in value and adds it to a result array that is returned from the call to $filter.
You can set a break point in the browser on the line return element.key === value; and should see it doing the comparison.
Hope this helps.
Huge thanks for your answer :)
I'm using Firefox 24.0 and Firebug. If i set a checkpoint on "return element.key === value;" it doesn't stop there. If I set the checkpoint on the line above and start debugging, it doesn't reach the line either.
edit: I'm using data-i18n="welcomeHeader" right now to call the service and the following language file:
[ { "key":"welcomeHeader", "value":"Welcome to CASCADE", "description":"Home page greeting text" }, { "key":"loginButton", "value":"Log In", "description":"login button text" } ]
The value which is compared with element.key is welcomeHeader