C# application to read in and translate other applications - c#

I am trying to build a Translation Assistant which can read in other compiled C# application (.exe), and display the forms from the EXE, are displayed individually, along with a table next to it with english column which will show the current english words on display, and another column for the value, which a translator can enter. Once completed translations, the translator can export the translations a resx file, to add to a project and also as an excel file for record purposes.
I am new to C# and hence am not sure if my strucute is correct, i have designed in such that a dll is inserted into the .exe during compilator, and then using this dll, the translation application can extract the string. This works for most strings, but it is getting stuck where there are several string that can apear in the same textbox at different times [e.g. disconnected, connected etc]. I have tried searching everywhere, but I am not able to find information on how i will be able to pull out all strings from an application, and be able to identify which form they belong to, in order to create my application?
the other issue i am faced with is, actually displaying the translated strings, the application i am building would benifit greatly if it could display a example of how the translated strings would look, as translations in some languages could be excessivly long. but i have found that i am only able to read in the aspects of the compiled applications and create an instance, but am not able to translate it.
I am reading in the exe using Reflection, and have understood from online that i need to use reflection.emit to modify the form. but i am finding every sting that is idenfitied from the form, is extracted as an instance, hence changing the string is only changing the instance of the strings , and not the instance of the form itself. hence i am not able so a correct display.
I have been trying for 3 weeks to solve these last two questions, Thanks in advance for helping me solve this.

I think you can't find a general solution to your problem with the texts that may appear in the textbox. Here is why:
If the texts are in the resource file, you could read them, but you still don't know where they are used. You would need to do a complex analysis of the source code to know, where the text is displayed. Just imagine this little scenario:
textBox.Text = GetCorrectText(connection.State);
GetCorrectText could look like this:
string GetCorrectText(ConnectionState state)
{
return string.Format(Resources.ConnectionState, state);
}
Resources.ConnectionState might be "The connection is in the state {0}".
Its a simple example, but you would need to know or extract a lot of things:
The text property of the TextBox class is the string that is shown to the user
The Method GetCorrectText returns the text, so you need to parse it.
The Method string.Format returns the text. Now you either would need to hardcode that for string.Format it should use the first parameter as the text that is displayed or you would have to parse string.Format to learn that fact.
The example shows something else: You wouldn't be able to translate the whole string that is being displayed, because part of it is the name of the enum value.
What I want to show you is that you need to make trade offs.

Related

Dynamic Localization on the fly

I have strings that admin user can input into database.
User can select language, I want to localize this text according to it.
I do not want translate strings as I want to keep semantics same.
Also I have researched but I have found examples for only static strings.
Below question is relevant but I do not know string at compile time.
User can insert any string.
Relevant stackoverflow question
If I understand your question correctly, there is no easy way to do this.
All UI localization tools are concerned with localizing texts stored in your application, like the text on a button, or an error message.
If your application shows texts from a database, this a completely different problem.
Normally, you would have to allow for a multilingual text in your database schema and give your admin user a way to enter a localized text. Probably, you would have to define a translations table with
the original text (or a text ID)
a language ID
the localized text
In your application you would have to fetch the localized text from translations table.
If you use the original text as the key into the translations table, you will not have to modify the original table. If you use an ID, you would need to store this ID in the original table. Both have pros and cons.
If you are not too worried about the quality and consistency of the translations, you could use an online translation service. There are APIs for both the Google and Bing translator. Technically they are both paid services, but - at least with Bing - I think you have to pass a monthly threshold before they actually charge you anything.

Connecting To A Website To Look Up A Word(Compiling Mass Data/Webcrawler)

I am currently developing a Word-Completion application in C# and after getting the UI up and running, keyboard hooks set, and other things of that nature, I came to the realization that I need a WordList. The only issue is, I cant seem to find one with the appropriate information. I also don't want to spend an entire week formatting and gathering a WordList by hand.
The information I want is something like "TheWord, The definition, verb/etc."
So, it hit me. Why not download a basic word list with nothing but words(Already did this; there are about 109,523 words), write a program that iterates through every word, connects to the internet, retrieves the data(definition etc) from some arbitrary site, and creates XML data from said information. It could be 100% automated, and I would only have to wait for maybe an hour depending on my internet connection speed.
This however, brought me to a few questions.
How should I connect to a site to look up these words? << This my actual question.
How would I read this information from the website?
Would I piss off my ISP or the website for that matter?
Is this a really bad idea? Lol.
How do you guys think I should go about this?
EDIT
Someone noticed that Dictionary.com uses the word as a suffix in the url. This will make it easy to iterate through the word file. I also see that the webpage is stored in XHTML(Or maybe just HTML). Here is the source for the Word "Cat". http://pastebin.com/hjZj6AC1
For what you marked as your actual question - you just need to download the data from the website and find what you need.
A great tool for this is CsQuery which allows you to use jquery selectors.
You could do something like this:
var dom = CQ.CreateFromUrl("http://www.jquery.com");
string definition = dom.Select(".definitionDiv").Text();

Replace strings with translations from reference table

I'm trying to pull some info off of a korean website and then make those korean characters usable and then put the info in a text file or the like. My idea was to create kind of a reference table (that would be done quickly, as there aren't too many sets of data that need that treatment, roughly 200).
My question is now,
first: if that is actually a solid idea or if there's a better or easier solution,
second: what format would I wanna use for such a table/sheet? csv, xml?
So far I'm getting the info via HtmlAgilityPacks XML/HTML stuff, which works quite well. Any help is appreciated, if you need any of my code, let me know so I'll edit it in.
.csv read slightly faster than .txt. But if only 200 characters, I think the difference is insignificant.
Have you considered using a resource file, normally used for exactly what you are doing and the appropriate translations will be loaded based on the default culture set on the users PC.
http://msdn.microsoft.com/en-us/library/y99d1cd3(v=vs.110).aspx

C# saving and loading all form elements?

I'm trying to design my C# winform application with a very generalized function to automatically go through all of the form elements and save their states/values in a text file so that I can load it later. I want it to be very generalized so that it'll be a cinch to reuse this code in future projects, as it wouldn't be heavily tied down to the specifics.
The form elements I want to save are text boxes, combo boxes, data grid views, list boxes and that's about it. I want to save their values and everything about them.
One way that I was going about it was to go through every possible form element and then detect eachs type, and then create the corresponding c# code to re-create its value ('tboxmine.value="blue elephant"'), and then writing the code to a file, so that I could load the code from the file and execute it using the CSCcompiler. My code so far doesn't seem to be working correctly and I'm having my doubts that this compiler is actually running the code inside my application (I think it's possibly creating a new thread?), and it just seems like there's probably a far more straightforward relatively standard way of doing this.
This seems a bit like the reverse "best practice" approach. If you dont't know about databinding I suggest you look into that.
Basically you create classes to represent your data and use databinding to associate controls with your objects. The controls will automatically show the right value and allow the user to change it. If the user has changed the value, your object gets automatically updated.
To save the data, you would use some kind of serialization to store your objects in a file. When loading, you let the Serializer rebuilt your class structure and (best case) you are good to go.
This is not exactly what you asked for, but I think it is something you could use well ;-)
N.B.: Not the complete state of the control is saved. e.g. in a Textbox your text would be saved but the BackColor won't.
To get you started look into this tutorial: http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial

Reading classic asp files and finding variables

I'm creating a console application to read classic asp page files and find certain functions. A lot of the functions I can use regex to get what I want which I then use the the text retrieved to query a database. An example of what I can already do -
This is a classic asp function (GetContentDirect) and I want to get the parameters which is easy to do with the below code. I would need to get the text CONTENT Logout and query the database with those words.
xsl.addText "Logout", obj_Content.GetContentDirect("CONTENT Logout")
The problem however is that the parameters for the functions are also variables or text and variables. Like the below code -
obj_node.appendChild obj_xml.createCDATASection(obj_Content.getContentDirect("CONTENT " & str_Temp))
I would need to get the value of str_Temp which is assigned elsewhere on the page. Whats the best way to go about doing this?
If your "variables" are actually constants, the solution is rather straightforward. Just let your console application know about the constants.
But, if they are truly variables, it seems the easiest way to get the values for all code paths would be to actually execute the code.
Modify your functions to log each time it is called, including the value of each parameter. Then crawl your site and run your console app against the resulting logs.

Categories

Resources