Option Strict On
Option Explicit On

Namespace Nexamas.UI.Localization

    ''' <summary>
    ''' Describes text-expansion pressure for a localized string key.
    ''' </summary>
    Friend NotInheritable Class MASLocalizationExpansionSample
        Friend Sub New(key As String,
                       sourceCultureName As String,
                       targetCultureName As String,
                       sourceText As String,
                       targetText As String)
            Me.Key = Normalize(key)
            Me.SourceCultureName = Normalize(sourceCultureName)
            Me.TargetCultureName = Normalize(targetCultureName)
            Me.SourceText = Normalize(sourceText)
            Me.TargetText = Normalize(targetText)
        End Sub

        Friend ReadOnly Property Key As String
        Friend ReadOnly Property SourceCultureName As String
        Friend ReadOnly Property TargetCultureName As String
        Friend ReadOnly Property SourceText As String
        Friend ReadOnly Property TargetText As String

        Friend ReadOnly Property ExpansionRatio As Double
            Get
                If SourceText.Length = 0 Then Return 0.0R
                Return CDbl(TargetText.Length) / CDbl(SourceText.Length)
            End Get
        End Property

        Friend ReadOnly Property RequiresFlexibleLayout As Boolean
            Get
                Return ExpansionRatio >= 1.35R
            End Get
        End Property

        Private Shared Function Normalize(value As String) As String
            Return If(value, String.Empty).Trim()
        End Function
    End Class

End Namespace
