suhaibkhan / messageResource.js

Javascript library for loading and using message resource property files.
MIT License
22 stars 22 forks source link

messageResource.get not working #4

Closed eduvenson closed 9 years ago

eduvenson commented 9 years ago

var value = messageResource.get('sample.key', 'moduleName');

the function returns the key name and not the value.

suhaibkhan commented 9 years ago

This library works only if properties files can be accesed via a url. If a requested path is not available it will print some error messages in the browser console. So first check whether your file path is valid using browser console.

Code snippet specified below shows working usage of the library.

// initialize messageResource.js  
messageResource.init({
  // path to directory containing config.properties
  filePath : 'resource'
});

// load config.properties file
messageResource.load('config', function(){ 
  // load file callback 

  // get value corresponding  to a key from config.properties  
  var value = messageResource.get('key', 'config');
}); 
ghost commented 9 years ago

All files in same folder.

props.properties file: home.title = myhome home.welcome = welcomehome

JS file: function showPopup(){ messageResource.init({ //filePath: ''; filePath ignored since both js and html are in same local folder }); messageResource.load('props', function(){ var firstValue = messageResource.get('home.title', 'props'); alert(firstValue); }); }

1 The messageResource.get() always gives 'home.title' as a static value always, doesn't fetch 'myhome' from 'props.properties' file in the same folder. Infact, it works event without my props.properties file. How to get the value 'myhome' from props file ?

2 Which messageResource javascript file is used in this process. There are two js files in 'dist' and 'src' folders of the messageResource-master zip download. Should we use this js file or messageResource.min.js is enough? Please clarify.

Snapshot: msgrc