I have two database tables for multilinguality in my project:
Word -ID- -En- -Ge-
1 Hello Hallo
2 Yes Ja
Lang -ID- -Name- -FlagFileName-
1 English flag-en.jpg
2 Deutsch flag-ge.jpg
But, I need to be able to add new languages into the system. I can add a new row to Lang table and a new column to Word table, but I cannot update the DBContext object in my ASP.NET MVC3 project. My DB Objects in my Model.
public class Word
{
public int ID { get; set; }
public string English { get; set; }
public string Deutsch { get; set; }
}
public class Language
{
public int ID { get; set; }
public string Name { get; set; }
public string ImageFileName { get; set; }
}
I need a way to define Word as new languages can be added to it. How can I update the Word object? Is this even doable in some way?
I also have problems dealing with dynamic Views:
@{
Type objectType = Type.GetType(typeof(MyProjectNamespace.Models.Word).AssemblyQualifiedName);
System.Reflection.PropertyInfo[] fields = objectType.GetProperties();
}
<table>
@foreach (System.Reflection.PropertyInfo f in fields)
{
<th> @f.Name.ToString() </th>
}
@foreach (var item in Model) {
<tr>
@foreach (System.Reflection.PropertyInfo f in fields)
{
<td>@Html.DisplayFor(modelItem => item.English)</td>
<td>@Html.DisplayFor(modelItem => item.Deutsch)</td>
<td>//How can I display for a new Language here?</td>
}
</tr>
}
</table>
I can get every attribute of Word and print out them as Headers with the code below, but how can I print the values in these dynamic attributes? Is this doable?
I appreciate any ideas, I am even ready to recreate tables.
I decided to go simple. It’s maybe doable, but not worth it, to deal with dynamic Model objects and get their dynamic attributes. So I decided I need a Word table like:
As the Words won’t be standing in a mathematical index as new languages are added such as:
And the computers cannot understand the meaning of a word with %100 reliability, I decided to hold a Meaning table, which only holds English words:
And bind the meanings with actual Words:
I was assigning WordID’s to new dynamic elements, such as “a new type”, which will be used to fill a dropdown box somewhere. Now I’ll bind it to a MeaningID.
This solution is clear, understandable and easily-implementable, I guess. I won’t accept my own answer for a week, in case some clear solutions might be presented to my current tables.