(This is a very minimized version of my actual project, that has much more tables that are linked together and a lot of more data and columns for each tabel).
- How would you recommend setting up the structure of a content management system that supports content in different languages? Is the following way a good option?
In my current project i have a database with articles, these articles are defined by the columns id, title and text. The title and text columns are forign keys to the table LanguageData on the column text_id. That table holds all the strings for the entire project. This table consists of the columns id, text_id, text and language_id.
Example:
Article : { id : 1, title : 1, text : 2 }
LanguageData : { id : 1, text_id : 1, text : "Title in english", language_id : 1 }
LanguageData : { id : 2, text_id : 1, text : "Tittel på svenska", language_id : 2 }
LanguageData : { id : 3, text_id : 2, text : "Text in english", language_id : 1 }
LanguageData : { id : 4, text_id : 2, text : "Texto en español", language_id : 3 }
- How do i make a fast webservices that return articles with a specified language?
In my project i also have a webservice that takes a language_id as input and returns all the articles with the correct language strings added. For this i connect to the database with entity framework and for each article in the database and each column that is a foreign key to LanguageData, i call a method:
GetLanguageString(text_id, language_id)
return LanguageData.First(ld => ld.text_id == text_id && ld.language_id == language_id)
- This seems to be very slow when i want to go through 600 articles with a lot of columns that are linked to LanguageData. Is there a better way of doing this? Some columns that arent mentioned here are often repeated from article to article (for example the column category). Should i save the result of the lambda questions so that they dont need to be executed again if i already have searched the string for the same text and same language? And does it mather if i use lambda expressions or LINQ? Are they equally fast?
Some documentation on the topic would be gladly recieved. I am new to backend programing and i dont seem to be able to find information about this on the net.
Many thanks.
I decided to do like this:
For each article I have an articleText, so I put all the information that is not language specific in the article table and then the rest in the articleText table. Every row is for a different article or language. Then I also have other tables, like a news table, and these also have a text table connected to them.
With this solution I only need to do one left join to get all the texts for a specific article in a specific language, compared to N left joins for N columns. And also before ALL texts were in one table, even texts for the homepage. Now everything has its own smaller table and the texts for the homepage will probably be in local files that I read in to a dictionary instead of doing lookups against the database.
If you see anything that could be done better, please tell me.
Hope this helps someone.