How to include a definition language file in javascript?
I have a big javascript file common.js with all my functions and stuff...and i would like to write a separate file Js to store only the definitions for all the alert/courtesy messages etc spread along the file...i don't want to seek and change one by one...
i have created something like this in php开发者_如何学C, where I have my file, en.php / fr.php /de.php for each language i need...
i was wondering:
1. if i can do the same in Js
2. if there is any way to use the php instead...so woudl be even better to have just one and only file to edit
thanks
Sure -- all you need to do is to create a definitions file for each language that just creates an object with the needed name: value
pairs. Your existing JS can then insert defsObject["name"]
wherever needed. Your PHP would then determine which of the JS definition files to load by changing the src
value of the script tag.
If you are unfamiliar with the object notation, there's loads of examples available on Stack Overflow (tagged JSON).
I don't believe there's a satisfying way using js to include the definitions.
精彩评论