Multi-Language Laravel: Part 2 - DB Models with 'title_en'

preview_player
Показать описание
In this video, I'm testing in live-coding mode, whether it's bad to have DB fields like "title_en" and "full_text_en" in the DB table. What do you think, do you agree with my opinion?

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

Please use MultiByte mb_ functions, because newbies can make an annoying mistake :) Especially in multilanguage (non-english) projects. I really enjoy your videos as a native-only PHP "developer", so i started to learn Laravel too.

legyes
Автор

Really interesting, never thought about this approach

helderneves
Автор

I have a different approach to this job. My way is probably much more easier and flexible, while its performance can be a little bit lower.

1. Add language_id column to the posts table and create a new record for each post in a different language.
2. Create many-to-many polymorphic relations. Let's say I have 3 languages with ids 1, 2, 3, and 3 posts with ids 10, 20, 30. My translations table will have 6 rows like:

columns: content_id, translatable_id, translatable_language_id, translatable_type.

10-20-2
10-30-3
20-10-1
20-30-3
30-10-1
30-20-2

In only a few rare cases we will have to query the translations table. That's why keeping content tables smaller is more important IMO.

bulent
Автор

Well Sir i think there is another approach json column which data do you want to translate make that field json type and store translation against locale like { "en" : "abc", "ar" : "xyz"}

MuhammadImran-vher
Автор

Nice one.. never thought it before. Thanks for sharing.

PranoySinha
Автор

Good Example for general to how make dynamic data

alila
Автор

I have used this method in a project. But then instead of adding getLocale() everywhere I used MySQL views to build one view per language. Every translatable column is aliased like this : "title_es AS title".
I then change the database table used by the model depending on the need.
And these simple sql views allows writing too. I update title in the code, but the column "_es" is saved.
What do you think of that method?

PaulGertz
Автор

Hi,

Very good tutorial, one thing I would like to in addition like default local should not include in URL, please guide me

for eg.
localhost/home (Default locale: en)
localhost/ar/home
localhost/es/home

zaighamali
Автор

Everything is good but when i'm typing text in input field it doesn't change ya translate language..?

neejurajpoot
Автор

you can make 2 table
table 1 => languages
table 2 => Sentence
and get Sentence with name and language code

alirezaprogrammer
Автор

please make a video of" laravel sanctum abilities"....please

sakirs
Автор

@Laravel, I need language swither options to be explained in depth. How to swith language, how to set up url.

pvaitonis
Автор

Very very good tutorial. Thank y so much :)

aomo
Автор

Greate video. Tks you so much for tutorial, your video helps me so much.

vietvietnguyen
Автор

Can you make a video about using the translations in javascript files? As in exposing all the translations to window object and making a custom __ function in JS. I have tons of translations and outputting all of them inside all blade files (<script>window.trans = { ... };</script>) seems pretty hacky. Maybe one with Vue as well?

dididi
Автор

Hello Mr. Povilas, Great tutorial as always! I just have a question, what do you think about graphQL with Laravel? There's only a few resources here on yt with that topic. So I just want to know your opinion. thanks

josepacheco
Автор

Hi sir, i got error "Missing parameter: id" when cast parameter

fauzifendhio
Автор

I have implemented with two tables:
i. posts
col => id, thumbnail, author, date
2. posts_translations
col => title, full_text, lang, post_id
Is this a bad schema?

juniordev
Автор

Does spatie laravel translate approach is good by using json for the field?

dndhndn
Автор

What's your opinion on non english (non-ascii) column names in SQL DB? I was given a project and previous developer used cyrillic characters in some column names. Should I rename it or keep it? It's Eloquent model so properties end up being in cyrillic too.

creeddm