How to transalte messages that comes from server in react native app - reactjs

I'm building a react-native app with spanish as default language, the problem is that I'm using a open source backend service to serve data and this data comes is in english by default. What I want is to transalate this data/messages that comes from server in my react-native app to show to the user the messages in spanish not in english.
This is the first time I am doing this process and it is not clear to me what are the steps or the flow that is generally followed for this kind of proces(translate messages that comes from server in my app).

You have many approaches to such a thing one comes to mind is
Catch the error/api response message which mostly server error messages comes in codes and messages.
set a condition statement if code equal 2 that means the server is down for example
Example:
You made a request to the server and there was an error with the server let say wrong username and password, now the server returns a message and a error code you have to get the code or the message and show your own message
.....made the request the server returned
{ code: 192, message: Wrong username/Password }
now in your code you will do the following
if(code == 192){
...do your message
}
P.S this is just on top my head since you didn't share any codes or responses from your server.
UPDATE :
If you want to translate all your strings/messages that comes from the server you would need to do another approche something like this
Create a file contain all the strings/codes from the server
compare messages/code comes from the server and the file will return the text you want
{ "102": "Hola", "103": "Bien", "104": "Nada", "105": "Si", }
now this file contain the error/message code all you have to do is when you receive the code grab the message from this file
let translation = {
"101": "Hola",
"102":"Si"
};
translation["102"]; // Result will be Si
Now this is the most accurate approach but you have to know all the messages/codes comes from the server, now if you want something to translate on the fly you might wanna use translation library and may not be accurate translation

Related

What is the maximum length of a parameter in loadrunner?

I am a beginner in loadrunner. I am working with Loadrunner 12.53. I have recorded one simple which will login to one application and Logout.(I recorded with user1 login id) I am testing it with different users say(user2, user3, user4,..., user10, user11). The script is passing successfully till user9 and it is failing from user10. I am getting below error: HTTP-Internal application error
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'ClearCurrentUserFormApplication'. The input source is not correctly formatted.
All the users are existed in that application. Is it because of the change in length of the parameter?
Record your site with User 10 settings. Compare to a recording for User9. The differences in structure will need to be addressed

Using satellizer to login via facebook and sending user information to server

I am attempting to send back to the sever the user information from satellizer.
I believe the call is as per this url:
https://github.com/sahat/satellizer#authauthenticatename-userdata
$auth.authenticate(name, [userData])
However when I use it :
$auth.authenticate('facebook', ['userData'])
my sever receives :
{ '0': 'userData',
code: 'AQB8ofHRuC',
clientId: '1625070294abcdef',
redirectUri: 'http://localhost:3000/' }
instead of actually receiving the userData.. what am i missing here ?
[userdata] is a kind of custom data, this means that you can put in it your data (some values). When you put $auth.authenticate('facebook', ['userData']) you put an array with one string element 'userData'. I think that it make sens to grab info on server by uid.
UPDATE
I found recent a link
https://github.com/sahat/satellizer/blob/master/examples/server/node/server.js#L537. You can translate node js code in your server programming language code.

How can I prevent accidentally overwriting an already existing database?

I'm adding BaseX to an existing web application and currently writing code to import data into it. The documentation is crystal-clear that
An existing database will be overwritten.
Finding this behavior mindboggingly dangerous, I tried it with the hope that the documentation was wrong but unfortunately my test confirmed it. For instance, using basexclient I can do this:
> create db test
Database 'test' created in 12.03 ms.
> create db test
Database 'test' created in 32.43 ms.
>
I can also replicate this behavior with the Python client, which is I what I'm actually using for my application. Reducing my code to the essentials:
session = BaseXClient.Session("127.0.0.1", 1984, "admin", "admin")
session.create("test", "")
It does not matter whether test exists or not, the whole thing is overwritten if it exists.
How can I work around this dangerous default behavior? I'd would like to prevent the possibility of missteps in production.
You can issue a list command before you create your database. For instance with the command line client if the database does not exist:
> list foo
Database 'foo' was not found.
Whereas if the database exists:
> list test
Input Path Type Content-Type Size
------------------------------------
This is a database that is empty so it does not show any contents but at least you do not get the error message. When you use a client you have to check whether it errors out or not. With the Python client you could do:
def exists(session, db):
try:
session.execute("list " + db)
except IOError as ex:
if ex.message == "Database '{0}' was not found.".format(db):
return False
raise
return True
The client raises IOError if the server raises an error, which is a very generic way to report a problem. So you have to test the error message to figure out what is going on. We reraise if it happens that the error message is not the one which pertains to our test. This way we don't swallow exceptions caused by unrelated issues.
With that function you could do:
session = BaseXClient.Session("127.0.0.1", 1984, "admin", "admin")
if exists(session, "test"):
raise SomeRelevantException("Oi! You are about to overwrite your database!")
session.create("test", "")

D3 Connection issue using mvsp java api

I am trying to connect to D3 Database with MVSP java api. So far:
I have downloaded the mvapi.jar
added it in project lib folder
written the sample code for connection inside main method
String url = "jdbc:mv:d3:hostname:portNo";
Properties props = new Properties();
props.setProperty("username", "");
props.setProperty("password", "");
String account = "AGCO";
String password = "";
MVConnection connection = null;
try {
// Getting error at this point
connection = new MVConnection(url,props);
MVStatement mvStatement = connection.createStatement();
connection.logTo(account,password);
MVResultSet results = mvStatement.executeQuery(query);
}
com.tigr.mvapi.exceptions.MVException: server error with errorCode 1023.
I checked the console but I'm not able to figure out the actual cause or whether I am entering the wrong username, password.
Please suggest what I am doing wrong.
First, you have to set a breakpoint or trace which function is throwing the errors. Then check the routes, (FileName) probably you will have much more experience than I do, but keep in mind that giving the full route ("account,filename," where the last comma is important) is never a bad idea while keep you safer and is mandatory if the filename is in a different account that you are logged to.
And like always please verify these things:
You have enough licenses. Try to close any terminal you have opened for testing your queries. Yes you know is true. One connection one license. Sometimes MVSP let you two under the same IP but chek this.
MVSP service is running. See Pick D3 documentation.
Your USER and ACCOUNT are both ENABLED to access in the MVSP server otherwise you won't be able to access these files or login with the user through the API. See the documentation to enable in the MVSP.Menu account.
I hope this helps.

Opening/decrypting Webex Connect db3 file

So I have a lot of instant message logs/history that I want to back up from my chat client, Cisco WebEx Connect in Windows 7. These are stored under C:\Users\\AppData\Local\WebEx Connect\Archive and the file is called "myemailaddress".db3
After downloading SQLiteBrowser to open this file, I get the error:
SQLiteManager: Error in opening file "myfile".db3 - either the file is encrypted or corrupt
Exception Name: NS_ERROR_FILE_CORRUPTED
Exception Message: Component returned failure code: 0x8052000b (NS_ERROR_FILE_CORRUPTED) [mozIStorageService.openUnsharedDatabase]
The file isn't corrupted so I'm thinking perhaps it is encrypted in some way - opening the file in Notepad displays random characters like the following, with no recognisable text:
=¢^£ÍV¶»ñû‡«–
`×ÚµÏýº°ÎîÎL
Besides that file which contains the actual messages, there is another small 20kb file under the folder ConnectDB that has various config settings (such as create CacheTable) and it says on the first line (when opened in Notepad): "SQLite format 3" - so clearly this one isn't encrypted.
Is there any way to extract the data from the first file to something readable (ie, text)? It's only around 5MB in size so shouldn't be causing any memory issues.
Unfortunately I haven't found a way for decrypting this file, however if you're still able to access the messenger client and have a live account you can still export them person by person by clicking on the person in question (make sure you've got view offline people enabled if you're retriving offline user's chat history) > click on the history tab > click on "save as".
I hope this is of use to you.

Resources