Multi Language ASP.NET MVC

Asked

Viewed 942 times

2

I have an ASP.NET MVC application.

And I 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 what is the best approach, or if there is a better one. I believe that the second one is better, because I force the existence of both languages. At first the system will have only two languages.

I wonder 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.

  • 1

    If you do not need to use the bank, this question may help you: http://answall.com/questions/17594/internationaliza%C3%A7%C3%A3o-com-c-mvc

  • Thank you @Filipeoliveira, but I would also need how to work with the bank.

  • It’s not an answer but, in a project I’m developing, with content in several languages, I created a table containing the identification of the content ContentId and for each language a record a daughter table with ContentId LangId

  • @Caputo, I made a change to the question, with the two ways I thought to do.

  • 1

    I chose to do it the first way because I want to support n languages, but with a record defining the Book so that all variations of languages point to the same Book. Imagine that you decide to support books in Spanish. You would have to duplicate the columns again and then in Italian. The idea of a solution should be considered in the maintenance and growth of the implemented solution.

2 answers

2

If you will not save number of books, and other information other than text. Ideally do it the first way. Now , if it is necessary to save number of books and other information. I believe that the ideal would be to divide the same object into two tables. Putting what is not text together with the registration 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 you can add more languages than just English and Portuguese. It would be a useless 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

Then I would divide it into two tables, like this:

Livro_Principal
    Id
    Quantidade_Estoque
    Imagem

Livro_Traduzido
    IdLivro
    Titulo
    Subtitulo
    Preco
    ImagemNome
    Idioma
  • There will only be text field. But you will have fields that will be images as well. Where I store the image name.

  • The images can be placed in a separate table. The name of the image, if translated, can be placed next to the book name and the description. With a reference to the image table.

  • 1

    Could make an example of bank structure?

  • Yes, I will assemble here and I will edit the answer shortly

1


The most succinct way is the first, with a few 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 to the Idioma:

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

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

An alternative way is to make a table of language registration, if there are many languages and with the possibility of registering more languages over time. So replace the enumerable with a foreign key.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.