Imports System.Globalization
Imports System.Threading
Imports Digitaldata.Modules.Logging
'''
''' Functions relating to i18n, Cultures, Translations
'''
Public Class LanguageEx
'''
''' Sets the Language of the current thread by setting CurrentCulture and CurrentUICulture
'''
''' A Logger instance
''' A language code in the form of 'de-DE'
''' A custom date pattern
Public Shared Sub SetApplicationLanguage(pLogger As Logger, pUserLanguage As String, Optional pUserDateFormat As String = Nothing)
Try
pLogger.Debug("Setting application language..")
Dim Culture As New CultureInfo(pUserLanguage)
If String.IsNullOrEmpty(pUserDateFormat) = False Then
Culture.DateTimeFormat.ShortDatePattern = pUserDateFormat
End If
pLogger.Debug("Culture object for language [{0}] created", pUserLanguage)
' The following line provides localization for data formats.
Thread.CurrentThread.CurrentCulture = Culture
' The following line provides localization for the application's user interface.
Thread.CurrentThread.CurrentUICulture = Culture
' Set this culture as the default culture for all threads in this application.
' Note: The following properties are supported in the .NET Framework 4.5+
CultureInfo.DefaultThreadCurrentCulture = Culture
CultureInfo.DefaultThreadCurrentUICulture = Culture
pLogger.Debug("Application language set to [{0}]", Culture.Name)
Catch ex As Exception
pLogger.Warn("Could not set application language!")
pLogger.Error(ex)
End Try
End Sub
'''
''' Logs the culture settings of the current thread
'''
''' A Logger instance
Public Shared Sub LogApplicationLanguage(pLogger As Logger)
pLogger.Debug("=== Application Language ===")
pLogger.Debug("Thread.CurrentThread.CurrentCulture: [{0}]", Thread.CurrentThread.CurrentCulture)
pLogger.Debug("Thread.CurrentThread.CurrentUICulture: [{0}]", Thread.CurrentThread.CurrentUICulture)
pLogger.Debug("CultureInfo.DefaultThreadCurrentCulture: [{0}]", CultureInfo.DefaultThreadCurrentCulture)
pLogger.Debug("CultureInfo.DefaultThreadCurrentUICulture: [{0}]", CultureInfo.DefaultThreadCurrentUICulture)
End Sub
End Class