How toRemove a Pre-Installed Language

Remove a Pre-Installed Language

SQL Script

  • Locate the variable @LanguageId in the script below and set the value to the Id of the language that has to be removed.The language id's can be found in the Languages table in the Sana Commerce database. This script can also be downloaded as a sql file.
  • Execute the SQL script on the Sana Commerce database to remove the specified language.

    CREATE FUNCTION remfld19823
    (
     @xml XML,
     @field nvarchar(50)
    )
    RETURNS nvarchar(MAX)
    AS
    BEGIN
     DECLARE @value nvarchar(MAX);
     SELECT @value = N'<FieldsDictionary>'+CONVERT(nvarchar(max),@xml.query('
            for $v in /FieldsDictionary/*[@name != sql:variable("@field")]
            return $v'))+N'</FieldsDictionary>';
     RETURN @value;
    END
    GO
    BEGIN TRANSACTION
     BEGIN TRY
      DECLARE @languageId int;
      SET @languageId = 2070;
      IF ((SELECT count(id) FROM Websites WHERE DefaultLanguageId = @languageId) > 0)
      BEGIN
       raiserror('ERROR: language %d is used as default for website!', 11, 1, @languageId)
      END
      --Delete NavigationItems
      DELETE FROM dbo.NavigationItems
      WHERE NavigationId IN (SELECT Id
             FROM dbo.Navigation
             WHERE LanguageId = @languageId);
      --Delete Navigation
      DELETE FROM dbo.Navigation
      WHERE LanguageId = @languageId;
      --Delete ProductEnrichments
      DELETE FROM ProductEnrichments
      WHERE LanguageId = @languageId;
      --Delete ChannelReferences
      DELETE FROM ChannelReferences
      WHERE (WebsiteLanguageId IN (SELECT Id
                FROM WebsiteLanguages
                WHERE LanguageId = @languageId))
      --Delete ContentLandingPages
      DELETE FROM ContentLandingPages
      WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = ContentLandingPages.Id) = 0)
      --Delete WebsiteLanguages
      DELETE FROM WebsiteLanguages
      WHERE LanguageId = @languageId
      --Delete SanaText
      DELETE FROM SanaText
      WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = SanaText.Id) = 0)
      --Delete NewsItems
      DELETE FROM NewsItems
      WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = NewsItems.Id) = 0)
      --Delete ContentPages
      DELETE FROM ContentPages
      WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = ContentPages.Id) = 0)
      --Delete ProductLandingPage
      DELETE FROM ProductLandingPage
      WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = ProductLandingPage.Id) = 0)
      --Delete ProductListPage
      DElETE FROM ProductListPage
      WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = ProductListPage.Id) = 0)
      --Delete MailTemplates
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'MailTemplate')
       DELETE FROM MailTemplate
       WHERE ((SELECT count(*) FROM ChannelReferences WHERE ChannelReferences.ItemId = MailTemplate.Id) = 0)
      --Delete ProductCategoryTranslation
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'ProductCategoryTranslation')
       DELETE FROM ProductCategoryTranslation
       WHERE LanguageId = @languageId
      --Delete ProductTranslation
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'ProductTranslation')
       DELETE FROM ProductTranslation
       WHERE LanguageId = @languageId
      --Delete VariantComponentGroupTranslation
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'VariantComponentGroupTranslation')
       DELETE FROM VariantComponentGroupTranslation
       WHERE LanguageId = @languageId
      --Delete VariantComponentTranslation
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'VariantComponentTranslation')
       DELETE FROM VariantComponentTranslation
       WHERE LanguageId = @languageId
      --Delete Translations
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'Translations')
       DELETE FROM Translations
       WHERE LanguageId = @languageId
      --Delete LanguagePreference from ShopAccount
      IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' and [name] = 'ShopAccount')
       UPDATE dbo.ShopAccount SET Fields = dbo.remfld19823(Fields,'LanguagePreference')
       WHERE CAST( Fields
         .query('
          for $descr in /FieldsDictionary/*[@name = "LanguagePreference"]
          return string($descr)
         ')
         .value('/', 'nvarchar(max)') AS xml)
         .value('/', 'nvarchar(max)') = @languageId
      --Delete Languages
      DELETE FROM Languages
      WHERE Id = @languageId;
     END TRY
     BEGIN CATCH
      PRINT ERROR_MESSAGE() + ' Transaction rolled back.'
      IF @@TRANCOUNT > 0
       ROLLBACK TRANSACTION
     END CATCH
    GO
    IF @@TRANCOUNT > 0
     COMMIT TRANSACTION
    GO
    IF EXISTS (
        SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES
        WHERE ROUTINE_NAME = 'remfld19823'
        AND ROUTINE_TYPE = 'FUNCTION'
    )
        DROP FUNCTION remfld19823
    GO
How toRemove a Pre-Installed Language