:SetVar Function "AUX:LocalizedText.X2"
:r $(DropFunctionScript_AUX)
create function [$(Function)]
(
   @DefaultText      $(dt_String_AUX),
   @InMainLanguage   $(dt_String_AUX) = null,
   @XLangText_1      $(dt_String_AUX) = null,
   @XLangText_2      $(dt_String_AUX) = null
)
returns $(dt_String_AUX)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOCALIZED TEXT (PLUS TWO ADDITIONAL LANGUAGES):
#
# === Usage: ===
# dbo.[AUX:LocalizedText.X2]( <Default text>, null, null, null )
# dbo.[AUX:LocalizedText.X2]( <Default text>, <Text in main language>, null, null )
# dbo.[AUX:LocalizedText.X2]( <Default text>, <Text in main language>,
#                             <Local text-1>, null )
# dbo.[AUX:LocalizedText.X2]( <Default text>, <Text in main language>,
#                             <Local text-1>, <Local text-2> )
#
==================================================================================================*/

if dbo.[AUX:OverrideLanguageWithMain]() = 1
   return ISNULL( @InMainLanguage, @DefaultText )

return
   case dbo.[AUX:ActiveLanguage]()
      when $(num_MainLanguageId_AUX) then @InMainLanguage
      when -1 then @XLangText_1
      when -2 then @XLangText_2
      else IIF( dbo.[AUX:UseMainLanguageForFallback]()=1, @InMainLanguage, @DefaultText )
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:LocalizedText.X2]( N'Привет!', null, null, null ) 'Greeting'
select dbo.[AUX:LocalizedText.X2]( 'Hello!', N'Привет!', null, null ) 'Greeting'
*/
