简体   繁体   中英

Best way to store wordings in my web application?

Hi i want to store wordings used in my application where i could easily get them and use/reuse them.

Some example of wordings like loading messages or validation messages, or any information messages.

I have tried using .resx files to store some of these but one thing i hate about is i need to get that wording on the server which i get lazy after doing it so many times.

I also tried storing them in a javascript array but i realized that any user might be able to see all those wordings since it is stored on the client side. But i dont have anything to hide there. It is just i feel that it is not the right thing to do maybe?

Anybody has any good suggestions?

There is nothing wrong that the user can see your wordings, and there is no way to hide data from user in web app. If you need to store secure data, keep them on the server, otherwise user can get from researching your app.

If you want to store just some messages javascript is absolutely fine.

I may suggest you the following approach:

Create a js file as follows and name it messages.js

var messages = {
       "loading" : "Still loading",
       "validation1" : "Please fill the required field",
       "success" : "thats a success",
       "failure" : "some error",
       "custom1" : "custommsg1",
       "custom2" : "custommsg2"
}

Include it in your web page and use whichever custom message you want to use like for example when you want to use success use message.success and similarily message.loading and so on for other messages.

Make sure that the left hand side values are unique since these are key value pairs.

Create a JSON file called messages.json

and create a service to read from that by doing a HTTP request

$http.get("messages.json").then(function(response) {
        $scope.messages = response.data;
 });

Now scope has a property which is globally accessible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM