code_junkie

How do you internationalise text in the database?

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. CREATE TABLE ProductType (
  2. Id int primary key,
  3. NamePhraseId int, -- link to the Phrase containing the name of this product type.
  4. DescriptionPhraseId int
  5. )
  6.  
  7. CREATE TABLE LocalizedPhrase (
  8. PhraseId int primary key,
  9. CultureCode varchar(8) primary key,
  10. Content nvarchar(255) -- the actual localized content
  11. )
  12.  
  13. CREATE TABLE GenderedLocalizedPhrase (
  14. PhraseId int primary key,
  15. CultureCode varchar(8) primary key,
  16. GenderCode char(1) primary key, -- 'm', 'f' or '?' - links to Gender table
  17. Content nvarchar(255)
  18. )
  19.  
  20. -- assume @MyCulture contains the culture code ('ca-FR') that we are looking for:
  21. SELECT
  22. Product.Id,
  23. Product.Name,
  24.  
  25. COALESCE(ProductStatusLocalizedPhrase.Content, ProductStatusPhrase.Content) as ProductStatus,
  26. COALESCE(ProductTypeLocalizedPhrase.Content, ProductTypePhrase.Content) as ProductType,
  27. FROM Product
  28.  
  29. INNER JOIN ProductStatus ON Product.StatusId = ProductStatus.Id
  30. INNER JOIN Phrase as ProductStatusPhrase ON ProductStatus.NamePhraseId = Phrase.Id
  31. LEFT JOIN LocalizedPhrase as ProductStatusLocalizedPhrase
  32. ON ProductStatus.NamePhraseId = ProductStatusLocalizedPhrase.Id and CultureCode = @MyCulture
  33.  
  34. INNER JOIN ProductType ON Product.TypeId = ProductType.Id
  35. INNER JOIN Phrase as ProductTypePhrase ON ProductType.NamePhraseId = Phrase.Id
  36. LEFT JOIN LocalizedPhrase as ProductTypeLocalizedPhrase
  37. ON ProductType.NamePhraseId = ProductTypeLocalizedPhrase.Id and CultureCode = @MyCulture
Add Comment
Please, Sign In to add comment