1

We are developing a website that should work in Portuguese and English! For this we create the following architecture:

  • Each class (Product, Service, Contact ..) has a field for pt-br and one for en-us. Here's an example: http://chopapp.com/#1u9no3qw

  • For the View to be displayed in correct language, the approach we use: Solution

Remover.cshtml and Remover.us-en.cshtml

There is no difference between the views!

@using Resources
@using Dicionario = Semep.Recursos.Admin.Pagina.Remover
@model PaginaViewModel

@section css {
    @Script.StylesForms()
    <link href="~/Areas/Admin/Content/controller/paginas/remover.css" rel="stylesheet" type="text/css" />
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <legend>@Dicionario.DesejaRemoverEstaPagina</legend>
    <fieldset>
        @Html.ValidationSummary(false, Strings.VerifiqueOsErrosAbaixo)
        @Html.DisplayForModel()
    </fieldset>

    <div class="buttons">
        @Html.ActionLink("Cancelar", "Index", "Solucoes")
        <input type="submit" value="SIM" />
    </div>
}

DisplayTemplates\PaginaViewModel.cshtml

Displays the fields pt-br!

@model PaginaViewModel

@Html.DisplayFor(p => p.ID)

<div class="display-label">
    @Html.LabelFor(p => p.Link)
</div>
<div class="display-field">
    @Html.DisplayFor(p => p.Link)
</div>

<div class="display-label">
    @Html.LabelFor(p => p.Nome)
</div>
<div class="display-field">
    @Html.DisplayFor(p => p.Nome)
</div>

<div class="display-label">
    @Html.LabelFor(p => p.Texto)
</div>
<div class="display-field">
    @Html.DisplayFor(p => p.Texto)
</div>

DisplayTemplates\PaginaViewModel.en-us.cshtml

Displays the fields en-us!

@model PaginaViewModel

@Html.DisplayFor(p => p.ID)

<div class="display-label">
    @Html.LabelFor(p => p.Link)
</div>
<div class="display-field">
    @Html.DisplayFor(p => p.Link)
</div>

<div class="display-label">
    @Html.LabelFor(p => p.NomeEn)
</div>
<div class="display-field">
    @Html.DisplayFor(p => p.NomeEn)
</div>

<div class="display-label">
    @Html.LabelFor(p => p.TextoEn)
</div>
<div class="display-field">
    @Html.DisplayFor(p => p.TextoEn)
</div>

Question

However, the data come only in "pt-br".
How to work with DisplayTemplates and globalization in asp.net mvc?

Notes

I know this is not the best way to structure the data to work with globalization.
But the whole system is so, and I have to maintain this standard!

4

0 回答 0