Laravel Translations: Store in PHP or JSON Files?

  Рет қаралды 19,629

Laravel Daily

Laravel Daily

Жыл бұрын

One free lesson from my newest course about Multi-language Laravel.
Full course: laraveldaily.com/course/multi...
- - - - -
Support the channel by checking out my products:
- My Laravel courses: laraveldaily.com/courses
- Laravel QuickAdminPanel: quickadminpanel.com
- Livewire Kit Components: livewirekit.com
- - - - -
Other places to follow:
- My weekly Laravel newsletter: us11.campaign-archive.com/hom...
- My personal Twitter: / povilaskorop

Пікірлер: 44
@MPDubois11
@MPDubois11 3 ай бұрын
I just wanted to say a big thank you to you for all your videos. They are amazing.
@MPDubois11
@MPDubois11 3 ай бұрын
I just wanted to say a big thank you for all your videos. They are amazing.
@danygagnon8446
@danygagnon8446 Жыл бұрын
In production, I use a JSON file for the simple reason that it is universal. Not only that, but typically, translators are used to translate JSON files, not PHP files. Also, for JavaScript, I can just grab the JSON file and obtain free types for the file in TypeScript. There are drawbacks, but they are easily fixable if you create a dashboard to manage translations that can read, update, etc., this JSON file. One of the useful features is the search option to see if a given translation is present.
@ElJuniorSenior
@ElJuniorSenior Жыл бұрын
JSON file is better, i like that.
@J87NL
@J87NL Жыл бұрын
For blade files there is the @lang(…) directive as well. For more flexibility and to give clients the possibility to update/edit the translations I’ve seen in projects that the translations were stored in the database (and retrieved and hopefully cached into translation files).
@nobel1378
@nobel1378 10 ай бұрын
Thanks a lot for this great explanation.
@ercank1137
@ercank1137 Жыл бұрын
Thank you!
@development2301
@development2301 Жыл бұрын
Thank you
@tharushafernando6688
@tharushafernando6688 4 ай бұрын
I worked on a project where they had entire module for adding new languages and translations. All the translation were stored in the db and cached with a scheduled job. In the helper the get the cached translations and get the appropriate translation. Seems to be lot of work but it worked fine and didn't had any performance issues either
@cardboarddignity
@cardboarddignity Жыл бұрын
Just a few notes to add. 1. I suggest to stick to one single folder, preferably /lang, since if you already have /lang folder and some plugin will publish their own lang files into /resources/lang (BTW the case with laraveldaily/invoices package as I recently discovered), all your translations from /lang folder won't be visible. So keep it in mind, since Laravel (yes, even new one) prioritizes /resources/lang for some reason. 2. For translations by non-developers, there are packages that adds strings to DB so they can translate it on live via user interface; 3. NEVER EVER mix both methods in a single method. If your team uses php, use php. If your team uses json, use json. Project's code should be consistent and standardized
@momahdy
@momahdy Жыл бұрын
Good video, you can also use multiple json files under en/ directory
@giacomogaravaglia6742
@giacomogaravaglia6742 Жыл бұрын
I personally use php. In my case i say to the dev team to "don't translate" the dot syntax, then run a custom command that puts dot translation in proper file (if not already contained). Using this method i can focus on development process instead of translation, and all the translation are automatically added in all languages.
@RexTangle4
@RexTangle4 Жыл бұрын
We use PHP, but we've just added a vue frontend and I wish we had json files so we could re-use them
@DeTechDivus
@DeTechDivus Жыл бұрын
How would you handle multi lang translations, whould you use spatie translations or json based ones with way to load translations from file designed by user?
@medilies
@medilies Жыл бұрын
I made this package elaborate-code/laravel-json-tongue that helps split a large JSON to many and gives freedom in naming the files
@akinoreh
@akinoreh Жыл бұрын
What about gettext & po files?
@MatejSK1
@MatejSK1 Жыл бұрын
What if i have placeholders which are given by js file to the laravel blade? How can i make an lang text for those placeholders, so when the user on the website will switch the lang button it will aswell change the placeholders on the table?
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
You probably need to expose the translation files so you can fetch them, dynamic import them or straight up import them into the bundle
@emrekapukaya5795
@emrekapukaya5795 8 ай бұрын
First thanks for this great video, i want to manage my translations on admin panel so is there a any package for this ? I want update json or php file dynamicly.
@LaravelDaily
@LaravelDaily 8 ай бұрын
This is a video about one package: kzbin.info/www/bejne/oorOmIukrNOJmNk
@yacobee
@yacobee Жыл бұрын
and what is the best way for making admin for a title to be stored in database?
@LaravelDaily
@LaravelDaily Жыл бұрын
There are packages for that
@janfornication
@janfornication Жыл бұрын
The json files are a nightmare for third parties who translate them. Because the context is missing and that is in my experience the most effort when working with third parties, the question "in which context is this". With the PHP files, you can counteract this with nesting and comments. But that is not perfect either. The best thing I have seen so far is the language system of Qt together with the Qt Linguist.
@truewebdesign3263
@truewebdesign3263 Жыл бұрын
No. Pretty easy. Create a language tables to store all languages for edit. On edit from a views file/page. Allow users select the language to edit. And store to database table and as well convert data to update existing .json file.
@janfornication
@janfornication Жыл бұрын
Hey, you're missing the point. Of course you can offer a view. However, the Laravel Translator lacks context. You will notice this when working with translation agencies, because in many cases they cannot simply translate the "key" 1:1, because idioms and terms can differ. For this you need a third value and that is the context or a comment. The latter is only possible in a PHP file.
@necmettinb
@necmettinb Ай бұрын
What stops me from using auth.register.name in a json file?
@bulent2435
@bulent2435 Жыл бұрын
İt worth to mention there is nothing to stop us using whole sentence as key in PHP files.
@moauyameghari
@moauyameghari Жыл бұрын
Thats right! I use them and it works fine
@modestasmv
@modestasmv Жыл бұрын
You are technically correct. The only issue is what happens in these cases: - No translation key found. You'll get a `filename.YOUR Translation here` put out to the user. While in JSON you'll get `YOUR Translation here` without a key - much cleaner. - If you have a `period` in your translation. PHP based files will treat it as an attempt to go to a specific key, while JSON doesn't really care about it. So while you can, there are always tradeoffs. But you are free to choose :)
@jonkf7548
@jonkf7548 Жыл бұрын
For me when both developing and translating context is more important than making it look pretty when the translation isn't created yet and that's why I don't really like the "modern" way people translate their apps nowadays (not just Laravel but some JS frameworks too). Example: Imagine you have an application for trading Pokemon. In your navigation menu you have a list of free Pokemon: {{__("Free")}} And then next to your favourite Charizard you have a button to release/lliberate it: {{__("Free")}} In one language a word might have multiple meanings but in another language you might need to use different words. Even if the meaning can be translated, you might want to use different text on a menu link vs a button vs a data table depending on what fits in the context. And as an aside if you are searching for a bug, it's a lot easier to find occurrences of something like LOGIN_FORM_LABEL_FIRST_NAME than searching your whole project for occurences of the word "name"...
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
Translation is a joke everywhere, that's why I advise people to never use non-english for their OS because otherwise it's impossible to find settings while following tutorials
@Farbfilmstudio
@Farbfilmstudio Жыл бұрын
@@spicynoodle7419 You must be from the US...
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
@@Farbfilmstudio I'm from Easter Europe
@Darkness_7193
@Darkness_7193 3 ай бұрын
I don't think that an article rereading is strange. In voice format we can do some simple coding and other routine. Plus this is the channel promotion
@krims15
@krims15 Жыл бұрын
If you feed AI translator with PHP files it can actually translate them more precisely because of given context. For JSON translations you don't have any context.
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
PHP should be faster to parse
@LaravelDaily
@LaravelDaily Жыл бұрын
But I don't think regular users would actually feel those millisecond differences.
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
@@LaravelDaily yes, it's 2-3ms at most and isn't much in a world with serverless everywhere. Still I don't like the idea of parsing JSON to get a key and then encode it into JSON again for an API response. To me it feels unnecessary to take an extra step when it can be avoided at no cost
@webglobesolutions
@webglobesolutions Жыл бұрын
Hello sir.. is there any way to give a discount of your courses? $129/year looks a lot to me.. Just a request.. Thank you.
@LaravelDaily
@LaravelDaily Жыл бұрын
All discounts here: coupons.laraveldaily.com
@webglobesolutions
@webglobesolutions Жыл бұрын
@@LaravelDaily Thank you sir!
@yungifez
@yungifez Жыл бұрын
Who translates? Nobodyyyyyy
@rdvr
@rdvr Жыл бұрын
For large amount of content e.g. static about us page could one use multiple views e.g. return view($locale . '.about-us'); ?
@LaravelDaily
@LaravelDaily Жыл бұрын
Well yes, then you need to have those resources/views/en/about-us.blade.php and other languages.
Laravel Security: Top 7 Mistakes Developers Make
11:16
Laravel Daily
Рет қаралды 82 М.
18 Laravel/PHP Tips in 10 Minutes: June 2024
10:41
Laravel Daily
Рет қаралды 8 М.
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 80 МЛН
100❤️
00:19
MY💝No War🤝
Рет қаралды 23 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 6 МЛН
Самый Молодой Актёр Без Оскара 😂
00:13
Глеб Рандалайнен
Рет қаралды 9 МЛН
Laravel Roles and Permissions: All CORE Things You Need To Know
16:32
Laravel Daily
Рет қаралды 216 М.
Laravel Translation to any Language easy from UI
10:24
Tony Xhepa
Рет қаралды 2,5 М.
Translations in Laravel and InertiaJS applications
12:49
Laravel Eloquent: Deeper Relationships with One Query
10:37
Laravel Daily
Рет қаралды 138 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 168 М.
Why Don't We Have A Laravel For JavaScript?
12:36
Theo - t3․gg
Рет қаралды 91 М.
Laravel: Single to Multi-Language - Practical Demo
10:28
Laravel Daily
Рет қаралды 40 М.
Why aren't you using Fastify? Or Koa? Or NestJS?
9:58
Maximilian Schwarzmüller
Рет қаралды 42 М.
80 Year Olds Share Advice for Younger Self
12:22
Sprouht
Рет қаралды 1,4 МЛН
The Story of Next.js
12:13
uidotdev
Рет қаралды 556 М.
Машина Жириновского.  #shorts Лиса рулит
0:52
Лиса рулит shorts
Рет қаралды 5 МЛН
Love conquers all rules?
0:26
Den Do It
Рет қаралды 10 МЛН
20 июля 2024 г.
0:58
Моби Салон
Рет қаралды 3,1 МЛН
POR QUEEEEE DIVERTIDAMENTE !!! #shorts
0:15
LARISSALADA - LARISSA GOMES
Рет қаралды 20 МЛН
他们在说什么,不能当面说。#海贼王#路飞
0:15
路飞与唐舞桐
Рет қаралды 11 МЛН