locked
Returned data localization RRS feed

  • Question

  • User248084892 posted

    How can I localize data returned from the database? For example, I have a data-bound label for CompensationType. If it returns the value "2" how can I localize that "2"? I already have the resource files setup and ready.

    All the examples that I have seen localize static data, I can't find anything that localizes data returned from the database.

    BTW - I know how to dynamically create a drop-down list and bind the selected value, that works just fine. I just need to figure out what to do with the label...

    Thursday, April 5, 2012 3:24 AM

Answers

  • User248084892 posted

    Thanks for the reply mm10. In case anyone else has a similar problem, the following is the solution I decided on. I am using DNN so some of the code below may seem a little weird.

    On the DataBound event of the DetailsView, localize the data in the label control.

        Private Sub LocalizeCompTypeDataLabel()
            Try
                Dim lblCompensationTypeData As Label = CType(dvwOffer.FindControl("lblCompensationTypeData"), Label)
                If Not IsNothing(lblCompensationTypeData) Then
                    'Use the CompType resource file
                    Dim strResourceFilePath As String = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/CompType.ascx"
                    lblCompensationTypeData.Text = Localization.GetString(lblCompensationTypeData.Text, strResourceFilePath)
                End If

            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

    Some sample data from the RESX file:

    Name                    Value

    Charity.Text            Charity    
    Commission.Text    Commission    
    Salary.Text             Salary    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 8, 2012 1:07 AM

All replies

  • User-917364509 posted

    //Using IFormatProvider
    int val = 2;
    Label1.Text = val.ToString("N", new CultureInfo("fr-FR")));

     

    Saturday, April 7, 2012 1:54 PM
  • User248084892 posted

    Thanks for the reply mm10. In case anyone else has a similar problem, the following is the solution I decided on. I am using DNN so some of the code below may seem a little weird.

    On the DataBound event of the DetailsView, localize the data in the label control.

        Private Sub LocalizeCompTypeDataLabel()
            Try
                Dim lblCompensationTypeData As Label = CType(dvwOffer.FindControl("lblCompensationTypeData"), Label)
                If Not IsNothing(lblCompensationTypeData) Then
                    'Use the CompType resource file
                    Dim strResourceFilePath As String = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/CompType.ascx"
                    lblCompensationTypeData.Text = Localization.GetString(lblCompensationTypeData.Text, strResourceFilePath)
                End If

            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

    Some sample data from the RESX file:

    Name                    Value

    Charity.Text            Charity    
    Commission.Text    Commission    
    Salary.Text             Salary    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 8, 2012 1:07 AM