Articles must be in the database in three languages.

How about designing a database, do I need to keep a list of supported languages ​​in a separate table, do I need to use a plugin (if yes, which one?), Or do I get away with Laravel features?

  • Just add the language field to the table with the article and everything, for example - andreymal
  • that is, one table with language_ru, laguage_eu ... articles? - a_mine
  • For Laravels I recommend this package github.com/dimsav/laravel-translatable - Anton Kucenko
  • Fields in the table EXACTLY not worth adding. but a separate sign - it is quite possible. - Manitikyl

2 answers 2

The question is quite general, since we do not know whether it is necessary to envisage the addition of other languages ​​in the future, etc.

Laravel out of the box provides localization of static data, so all static blocks can be implemented using it.

As for the dynamic data, for the articles I propose the following structure:

  • language table
  • table of articles (here all the information that can not be translated, ie, id, created_at, rating, etc.
  • content table. Add any columns here. For example: name, description, content. You give the editor access to write articles in different languages. In this case, of course, the table has article_id and language_id fields.

    Regarding the localization of the site I found a universal solution.

    • Table for languages. (Language)
    • Table for domains. (Domain) (For example for api, front and payment)
    • We write a service that gives us a list of languages ​​/ locales, it all caches, invalidates the cache, and so on.
    • We write singleton in the provider to get a list of languages ​​/ locales (We use the service)
    • We write middleware for localization by locale from a request / header (Locale)

    In the CRUD or Observer, we prescribe the logic of cache invalidation and caching.

    You can try to use the following packages, already used in other projects, a fairly simple implementation.

    In a separate table https://github.com/dimsav/laravel-translatable

    In json's https://github.com/spatie/laravel-translatable