This would include:
If you structure your data like this:
MessageToken DisplayText LangCode
firewood Fire wood en
firewood Bois de chauffage fr
When you make your query, just supply the default languageId (if blank) or the supplied languageId. Use a standard list of tokens for the messages.
Select DisplayText from (some table) where MessageToken = 'firewood' and LangId = 'en'
After studying the problem in detail I have found the following:
I could use the SET CONTEXT_INFO
, but I would have to inject some SQL to solve the problem.
The best option would be not to store localized data in the look-up tables. Instead, store some identification strings, and use custom localization logic in the application to match the strings to localized data. For the .NET framework it would be implemented by using resources, with a custom resource provider if I want to retreive localized information from a databse.
Thank you for your answers.
Since there are no user-defined global variables in SQL Server, you'll have to use one of two approaches:
Example context_info t-sql:
declare @languagein varchar(30), @contextin varbinary(128),
@languageout varchar(30), @contextout varbinary(128)
select @languagein = 'ro-RO'
select @contextin = cast(@languagein as varbinary(128))
set context_info @contextin
--do whatever you like here: queries, stored procs.
--context_info stays 'ro-RO' for the duration of the session/connection
select @contextout = context_info()
set @languageout = replace(cast(@contextout as varchar(30)),0x00, '')
print @languageout
Another technique I've used in localization is a three part coalesce to insure a result. Check for language-region first, then language, then a default. Based on your query:
SELECT COALESCE(langregion.LookupValue, lang.LookupValue, fallback.LookupValue) LookupVal
FROM LookupTable1 fallback
LEFT OUTER JOIN LookupTable1 lang
ON lang.ID = fallback.ID AND lang.Lang = @language
LEFT OUTER JOIN LookupTable1 langregion
ON langregion.ID = fallback.ID AND langregion.Lang = @languagewithregion
WHERE fallback.ID = @Lookup_ID
AND fallback.Lang = @defaultlanguage