Multi Language ASP.NET MVC

2

I have an ASP.NET MVC application.

And you need to make it multi-language, using a database.

I thought of two approaches:

Livro
     Titulo
     Subtitulo
     Idioma

OR

Livro
     Titulo
     TituloEN
     Subtitulo
     SubtituloEN

But I do not know the best approach, or if there is a better approach. I think the second one is better, because I force the existence of the two languages. At first the system will have only two languages.

I would like to know if for each column in the database I need to create a new column for the language, and how I work with it in ASP.NET MVC.

    
asked by anonymous 23.07.2014 / 14:55

2 answers

1

The most succinct way is the first, in some increments:

public class Livro 
{
     [Key]
     public int LivroId { get; set; }

     [Required]
     public String Titulo { get; set; }
     public String Subtitulo { get; set; }
     [Required]
     [DefaultValue(Enums.Idioma.Portugues)]
     public Idioma Idioma { get; set; }
}

Create a Enum for Idioma :

public enum Idioma
{
    Portugues,
    Ingles,
    ...
}

You can start with only two languages, and expand the enumerable when new languages are registered.

An alternative way is to make a table of languages register, if they are many languages and with the possibility to register of more languages with the time. Thus, replace the enumerable with a foreign key.

    
26.07.2014 / 00:04
2

If you are not going to save number of books, and other information other than text. The ideal is to do the first form. Now, if you need to save number of books and other information. I think the ideal would be to split the same object into two tables. Placing what is not text along with the record Id. And in the other table the information that can be translated, such as price, book name, description.

Of course this second solution would have a much bigger job and if the idea is not an expandable system. Where I can add more languages than just English and Portuguese. It would be a futile effort.

EDIT

Let's say that the structure of your Table book in a single language would be as follows:

Livro
    Id
    Titulo
    Subtitulo
    Preco
    Quantidade_Estoque
    Imagem
    ImagemNome
    Idioma

So I'd split it into two tables, like this:

Livro_Principal
    Id
    Quantidade_Estoque
    Imagem

Livro_Traduzido
    IdLivro
    Titulo
    Subtitulo
    Preco
    ImagemNome
    Idioma
    
23.07.2014 / 16:39