Efficient way to translate an application - vb.net

So i have developed an application in vb.net but recently i came across the requisite of allowing multiple languages for it. I dont know if there is any 'common' way of doing this kind of things, but my approach to accomplish that is the following:
I'll need to search in the code for components, error messages and everything that is displayed in the GUI of the application to be translated.
Secondly i will create a class in which i'll store in memory a dictionary of everything that will be translated
after, i'll replace the stuff to be translated withing an entry of the dictionary
then when the application start i'll load the dictionary
later on, i'll replace the static dictionary and will load it in memory from the database
So for example, my dictionary class:
Dim dictionary As New Dictionary(Of String, String)
dictionary.Add("00011", "hello there!")
Somewhere in my code i'll replace:
mylabel.text = "hello there!"
With:
mylabel.text = dictionary.item("00011")
Later on i will, instead of having a static dictionary, create that dictionary getting the information from a database like this (and load it at the start of the application:
_______________________________________
word_code ### word_EN ### word_FR
_______________________________________
00011 ### hello there ### bonjour il
I will load the dictionary considering which language is selected.
I'm not very confortable with this approach and i have no idea if this is the right thing to do, but if so i have a couple of questions:
is a dictionary the best data-structure to do so?
will this be memory-heavy considering i'll have 1000 entries, 1m entries or 10m entries?
is there any logic and faster way of accomplish the same?
Thank you so much in advanced,
J

It's a common way of doing it - having a system name along side a language code being used to look up a translated value. However, generally speaking I'd only advice you to do this for something like system texts and smaller text segments.
The reason is that in for example CMS/ecommerce systems, pages with lots of text likely will need to be translated in a data model to support it to begin with; and then you already have the language division.
So in that situation, you're better off making a page structure with a translated data model where the detail will be language specific per language for your current website.
For example, you'll have a product -> product_detail where detail keeps the translated values for said product. Similar for article -> article_detail and so on.
But for general translations and system texts which needs to be displayed, it's a common way to do it.
And as you suggest yourself, structures like like dictionary would be a good structures to to make fast look ups and can be cached in the system so you do not need to retrieve them all the time.
Some ways you can expand on it, is by sub dividing your translations into sub groups; say you have an order page and a product page. Then you can have translations assigned to "product" and to "order" with a "common" group as well.
It will also make it easier to build smaller cache objects, extract less data from your data storage etc, so a page which only revolves around orders don't need to worry about product translations.
It will require memory, but unless you put entire CMS systems into the translations, it should be "minor".
I would however question a need of 10 million entities of translations and wonder whether or not your system actually requires that many and if it does, then maybe consider an alternate approach and whether it might be better to make multiple versions of the "page" to eliminate the need for translations.
I would also advice you to not use "00011" as a system code to begin, and go for a more "readable" version (like "hello") to ease the readability and maintainability of your code. Then if you want a 'system value' which is like "00011", it's easy to do a search/replace.

Related

How to store an equation and/or random number generator inside of a SQL database?

I'm still in college and I'm trying my hand at designing my own applications, for practice and also for funsies, but I'm having some big questions.
Currently, I'm attempting to design an application that uses a relational database backend to store records related to a pen-and-paper RPG that a friend and I have been designing. It will need to store characters, weapons, items, etc. Since it's based off of a sci-fi universe, there are guns, etc.
Now, I'm stuck in the conceptual stages here because I'm not sure how I would store some of the weirder to grasp types of information here. Since it's a tabletop RPG, there are dice involved, typically referred to as D4, D6, D10, D20, etc. and a lot of these weapons, for example, have several kinds of attacks each (they're guns, so it's like firing modes, etc.) and a typical attack would be something like "D20 + 20."
Now, I know that I could just store it as a string variable, but I was hoping to design this in such a way that I could actually add some dice-rolling/etc. functionality to it. Is there a simple or effective way of storing a Math.random variable (not the result, mind you, but the actual range number) in a SQL record so that I could just grab it and use it real quick?
For extra context, I was hoping to have one table of the actual weapon templates & stats and another table of just actual instances of those weapons, so I could keep track of ammo in each gun, who owns it, etc.
I'm using Netbeans and a Derby database. Thanks for any help you guys.
As stated above, I don't know why you just wouldn't create a java/C#/any programming language application that can simulate the dice rolls for you. I mean, you could integrate the database into the application to retrieve information. Otherwise just simply make the ability to input information on weapons/Armour into the application in the form of popup dialog boxes (Or something along those lines).
A database is primarily used to store information in a structured way and automatically updates this information as needed. What you are suggesting to do is more dynamic and has nothing to do with storing information and more so with actually playing the game. Not wanting to change your idea about creating it. Just creating an actual application that utilizes a database can be written in a language other than SQL. (And much easier to do it this way as well.)
Your question is very broad, but I would not store a descriptive characteristic like "D20 + 20" in your database only yo parse it out in the app. Instead store that as two or three (depending on what it represents) attributes (columns) in your database, and let the app display it appropriately.
I don't know exactly what you mean by storing "equations" and "RNGs" in your database, but those belong in the application, not the database. You can store inputs or parameters that guide those equations, but not the equations themselves.

visual basic 2010 would a class or structure be better in this use case

As I mentioned before, I am hardly a programmer, so I once again need the expertise of those that are...
I am working on a program that will help me manage some data for a volunteer emergency communications group. In this program I currently have multiple different structures built for multiple different objects (if I am using the term correctly). I have a structure for Site Personnel, a structure for Members (yes they are different), a structure for Operation Info (considered its own object), and a structure for Facility. This was all fine and well, even having each element of the structure defined with <VBFixedString(nameOfConstant)> to ensure an equal record length.
And that is where I hit my problem. Each object (again I hope I'm not butchering this term as I am calling the Facility or the Site Personnel etc the 'object') is a set of fields for a random access file (I abandoned the Excel file idea, way too much headache and nothing but failures on that front, I'll use an in-house system). And, certainly to all of your dismays, I did finally decide to go with FileOpen, FileGet, FilePut, etc for my random access file management (I can already hear your teeth grinding and your skulls crackling to epic facepalms, but believe me I NEED to go simple for this presentation version and for the Version 1 Release which will be beta tested at a National Disaster Medical System exercise in May). The problem I encountered is that each file will need its own filenumber, its own position, and so on, and each one will need a Dim Temp as <structure> where <structure> is SitePersonnel, OpInfo, MemberData, or other relevant structure. Each file will also need its own file handling controls, such as GetRecord, PutRecord, DeleteRecord, NextRecord, PreviousRecord, AddRecord, and so on, and each file will need its own functions for file opening and finding the last record. The reason each structure will need its own copies of this code is that I cannot find a way to pass in a variable to a module-level function such as Public Function FileOpener(ByVal FileNum as Integer, ByVal StructureName as String, ByVal FileName as String, ByVal AccessType as String) and in the code define Dim Temp as (StructureName) where StructureName would be a String value for the actual name of the structure. And finally, I decided to have the redundant file handlers in each object since at any time there can be two or more of these file open, reading, writing, and seeking. Last thing I need during an emergency is for a module-level function to get confused and return the wrong data.
Now that you have the background, this is where I really need some advice. I am aware that structures can have Functions, so I could code each of these functions into the structure. However, I have also started thinking that an object this complex and that can do so many different things may just belong in a class instead of a structure. I am not familiar with classes in Visual
Basic, but I am familiar with Classes from Java, if there is any similarity between the two on the OOP level. So my question is this: Would this example be better (and more reliably) handled in a Structure, or in a Class? And if in a class, would I be best off with each Class in its own file, or should I combine all of these classes into one Module (mainly for clarity and ease of maintenance)?
I apologize again for any permanent damage I have caused anyone here by my sub-newbieness and painful choice of code, and I thank you ahead of time for helping a sorta-noob get back into the swing of things (last Visual Basic program I wrote was when Visual Basic 4 was hot off the press, yep, that long...).
For a system like yours, to manage users and other objects, I recommend the use of classes. They usually get used for management system as they offer the abbility of hierachical variables and functions, so you don't accidentaly call an internal function or access a variable you shouldn't. Also, classes are more flexible than structurs, so you should preferable use them when you aren't sure wether a class or a structure is the better way.
As Plutonix pointed out before, this is not a platform for recommendations, it is for problems with code. So next time, please go to a VB.Net forum. The text written above is my opinion based on my knowledge about the difference between classes and structures and this msdn-article. Further internetresearch is still something you should do, maybe ask in forum or friends / other programmers you know.

How should I (if I should at all) implement Generic DB Tables without falling into the Inner-platform effect?

I have a db model like this:
tb_Computer (N - N) tb_Computer_Peripheral (N - 1) tb_Peripheral
Each computer has N peripherals. But each peripheral is different in nature, and will have different fields. A keyboard will have model, language, etc, and a network card has specification about speed and such.
But I don't think it's viable to create as many tables as there are peripherals. Because one day someone will come up with a very specific peripheral and I don't want him to be unable to add it just because it is not a keyboard neither a network card.
Is it a bad practice to create a field data inside tb_Peripheral which contains JSON data about a specific peripheral?
I could even create a tb_PeripheralType with specific information about which data a specific type of peripheral has.
I read about this in many places and found everywhere that this is a bad practice, but I can't think of any other way to implement this the way I want, completely dynamic.
What is the best way to achieve what I want? Is the current model wrong? What would you do ?
It's not a question of "good practices" or "bad practices". Making things completely dynamic has an upside and a downside. You have outlined the upside fairly well.
The downside of a completely dynamic design is that the process of turning the data into useful information is not nearly as routine as it is with a database that pins down the semantics of the data within the scope of the design.
Can you build a report and a report generating process that will adapt itself to the new structure of the data when you begin to add data about a new kind of peripheral? If you end up stuck with doing maintenance on the application when requirements change, what have you gained by making the database design completely dynamic?
PS: If the changes to the database design consist only of adding new tables, the "ripple effect" on your existing applications will be negligible.
I can think of four options.
The first is to create a table peripherals that would have all the information you could want about peripherals. This would have NULLs in the columns where the field is not appropriate to the type. When a new peripheral is added, you would have to add the descriptive columns.
The second is to create a separate table for each peripheral.
The third is to encode the information in something like JSON.
The fourth is to store the data as pairs. So each peripheral would have many different rows.
There are also hybrids for these approaches. For instance, you could store common fields in a single table (ala (1)) and then have key value pairs for other values.
The question is how this information is going to be used. I do most of my work directly in SQL, so the worst option for me is (3). I don't want to parse strange information formats to get something potentially useful to a SQL query.
Option (4) is the most flexible, but it also requires more work to get a complete picture of all the possible attributes.
If I were starting from scratch, and I had a pretty good idea of what fields I wanted, then I would start with (1), a single table for peripherals. If I had requirements where peripherals and attributes would be changing fairly regularly, then I would seriously consider (4). If the tables are only being used by applications, then I might consider (3), but I would probably reject it anyway.
Only one question to answer when you do this sort of design. JSON, a serialised object, xml, or heaven forbid a csv, doesn't really matter.
Do you want to consume them outside of the API that knows the structure?
If you want to say use sql to get all peripherals of type keyboard with a number of keys property >= 102 say.
If you do, it gets messy, much messier than extra tables.
No different to say having a table of pdfs or docs and trying to find all the ones which have more than 10 pages.
Gets even funnier if you want to version the content as your application evolves.
Have a look at a Nosql back end, it's designed for stuff like this, a relational database is not.

global variables, arrays, and search results

I am trying to write an app that searches a website, and takes all of the results and puts them into a customized table. I am an Objective-C and iPhone SDK noob, and am hoping that this logic is what I am trying to accomplish:
1) Searching multiple search engines and pulling all of the data off of each website, storing each into a different array (for example: Searching Google, Yahoo, and Bing for "Shoes", and taking all of the different search results, hyperlinks and all, and storing them into three different arrays)
2) Pulling the data out of each array, and putting into a table (Table view in Interface Builder)
I am assuming that I need to declare global variables, so that they can be called from different classes......right?
What's the syntax for doing this?
How do I set this up in IB?
Did I bite off more than I can chew for this first app?
Thanks for your help!
Aaron, I also think you're biting off more than you can chew WRT a single question on SO, but let me point you to a resource I wrote on a similar topic about how to structure your program.
As an Obj-C noob, you're going to need to take extra care to remember the Model-View-Controller pattern. Extracting data from a web site is a bit of work - and you want to keep that very separate from your display and control code.
Have a clean API model that extracts and sorts data, and have a clear view controller class that reads data from the API.
My advice is to write the whole app in psuedo-code first and try out your thinking on us.

Which would be better? Storing/access data in a local text file, or in a database?

Basically, I'm still working on a puzzle-related website (micro-site really), and I'm making a tool that lets you input a word pattern (e.g. "r??n") and get all the matching words (in this case: rain, rein, ruin, etc.). Should I store the words in local text files (such as words5.txt, which would have a return-delimited list of 5-letter words), or in a database (such as the table Words5, which would again store 5-letter words)?
I'm looking at the problem in terms of data retrieval speeds and CPU server load. I could definitely try it both ways and record the times taken for several runs with both methods, but I'd rather hear it from people who might have had experience with this.
Which method is generally better overall?
The database will give you the best performance with the least amount of work. The built in index support and query analyzers will give you good performance for free while a textfile might give you excellent performance for a ton of work.
In the short term, I'd recommend creating a generic interface which would hide the difference between a database and a flat-file. Later on, you can benchmark which one will provide the best performance but I think the database will give you the best bang per hour of development.
For fast retrieval you certainly want some kind of index. If you don't want to write index code yourself, it's certainly easiest to use a database.
If you are using Java or .NET for your app, consider looking into db4o. It just stores any object as is with a single line of code and there are no setup costs for creating tables.
Storing data in a local text file (when you add new records to end of the file) always faster then storing in database. So, if you create high load application, you can save the data in a text file and copy data to a database later. However in most application you should use a database instead of text file, because database approach has many benefits.