I am creating a hybrid mobile application using javascript. In order to support multiple languages, I created an object called "exchange" that contains the translations of variables, where "exchange" contains more than 200 variable. My question is that in scale of performance, what's best to use:
1- variables inside object like this:
var exchange = {
USERNAME_PASSWORD_UNMATCHED: "الاسم و كلمة المرور غير متطابقين",
NOT_APPROVED: " بانتظار تأكيد صلاحية الوصف",
ERROR_CONNECT: "فشل الاتصال بالخادم",
RE_LOGIN: "الرجاء اعادة الدخول",
INVALID_ACCESS_TOKEN: "رمز المرور غير صحيح",
.
.
.
};
or
2- variables inside function like this
var exchange = {
get_variable:function(name){
switch(name){
case "USERNAME_PASSWORD_UNMATCHED": return "الاسم و كلمة المرور غير متطابقين"; break;
case "NOT_APPROVED":return " بانتظار تأكيد صلاحية الوصف";
case "ERROR_CONNECT":return "فشل الاتصال بالخادم";
case "RE_LOGIN":return "الرجاء اعادة الدخول";
case "INVALID_ACCESS_TOKEN":return "رمز المرور غير صحيح";
}
}
};
exchangeandname. Notice also that you have a syntax error in your second example, it should beget_variable: function(name){; and thosebreaks after areturnare unnecessary.