I know that this isn't exactly normalised, but bringing all of the localised data throughout my application into just a few tables will help me out a lot.
I have to be able to link some generic table to a LocalisedContent table which will contain different rows for each of the localised key-value pairs of the generic table joined to it... I guess you could say that it will be a one-to-many relationship.
The problem I've found is that I am not sure how to best model this... I can think of two ways and I am not sure which one is best:
My first option is:
AnExampleOfAGenericTable
------------
AnExampleOfAGenericTableID
...other non-localised data...
AnotherGenericTable
------------
AnotherGenericTableID
...other non-localised data...
LocalisedContent
----------------
LocalisedContentID
genericTablePKName
GenericTableID
LanguageID
field
content
In the above it would be possible to get out localised content for a generic table with an SQL query like:
SELECT AnExampleOfAGenericTableID, field, content
FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent
ON AnExampleOfAGenericTable.AnExampleOfAGenericTableID =
LocalisedContent.GenericTableID
WHERE genericTablePKName = 'AnExampleOfAGenericTableID'
Or:
SELECT AnotherGenericTableID, field, content
FROM AnotherGenericTable LEFT JOIN LocalisedContent
ON AnotherGenericTable.AnotherGenericTableID = LocalisedContent.GenericTableID
WHERE genericTablePKName = 'AnotherGenericTableID'
The second option seems to be, something like:
AnExampleOfAGenericTable
------------
AnExampleOfAGenericTableID
...other non-localised data...
localisedGroupID
AnotherGenericTable
------------
AnotherGenericTableID
...other non-localised data...
localisedGroupID
LocalisedContent
----------------
LocalisedContentID
localisedGroupID
LanguageID
field
content
And then I could use an SQL query like:
SELECT AnExampleOfAGenericTableID, field, content
FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent
ON AnExampleOfAGenericTable.localisedGroupID = LocalisedContent.localisedGroupID;
Or:
SELECT AnotherGenericTableID, field, content
FROM AnotherGenericTable LEFT JOIN LocalisedContent
ON AnotherGenericTable.localisedGroupID = LocalisedContent.localisedGroupID;
The second option seems more concise to me, but it does require me to join two FKs which seems a little strange. It also requires a lot of extra 'localisedGroupID' columns.
Ultimately both of the examples I've given may be wrong and I don't have the expertise to know the best solution to this. (Before you point out that this isn't fully normalised, I've already said I don't want hundreds of different localised data tables for each of my tables... I do want some amount of centralisation to the localisation even if it will lose me a little referential integrity.)
Ideas?