Translations in Laravel and InertiaJS applications

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 พ.ย. 2024

ความคิดเห็น • 33

  • @waiylkarim
    @waiylkarim 2 ปีที่แล้ว +2

    Been using almost the same approach but I like yours better especially the introduction of replacements. Keep up the good work

  • @tomaserlebach9760
    @tomaserlebach9760 2 ปีที่แล้ว +1

    I love your approach! It is so clear and maintainable! I can adjust every single inch to my project needs. Thanks a lot for that!

    • @cdruc
      @cdruc  2 ปีที่แล้ว

      Glad you found it helpful! 😀

  • @topalek
    @topalek ปีที่แล้ว +1

    Awesome tutorial!!! Thanx a lot

  • @magicoflaravel
    @magicoflaravel ปีที่แล้ว

    You are the life saver man.... Lots of love

  • @yasirarafat-dev
    @yasirarafat-dev 3 ปีที่แล้ว +3

    hi. that was a really great video. can you make a video on how to build a laravel package?

  • @Fraps224
    @Fraps224 9 หลายเดือนก่อน

    This is sooo awesoome!! Thank you

  • @samehdoush385
    @samehdoush385 2 ปีที่แล้ว +2

    Thank you, but not working in ssr mode , Is there any way to make it work with ssr ?

  • @hbend1li
    @hbend1li 2 ปีที่แล้ว +1

    big thank for this tutorial is very helpful.

    • @cdruc
      @cdruc  2 ปีที่แล้ว

      Glad it was helpful!

  • @afulay-hy2oy
    @afulay-hy2oy 11 หลายเดือนก่อน

    Laravel + Inertia + Vue: localization/translation in this stack is tricky. There are only 2 documents about it on internet

  • @abelgetu4860
    @abelgetu4860 3 ปีที่แล้ว +5

    it is really nice video but can you show us how to change the language(switch locals)?

    • @waiylkarim
      @waiylkarim 2 ปีที่แล้ว

      It's quite easy just add a route to your routes/web.php and fill in the following code
      Route::get('language/{language}', function ($language) {
      Session()->put('locale', $language);
      \App::setLocale($language);
      return redirect()->back();
      })->name('language');
      Make sure to use inertia link to switch the language instead of ahref or axios for the page to be reloaded
      On your vue add the following link
      Arabic

    • @bentomlin
      @bentomlin 2 ปีที่แล้ว

      @@waiylkarim That should be a put request form submission not a get request, no? Can't see a reason their browser would need to actually visit the address

    • @waiylkarim
      @waiylkarim 2 ปีที่แล้ว

      @@bentomlin That could work too, but since you are not interacting with the database, it's better to use GET over PUT

    • @bentomlin
      @bentomlin 2 ปีที่แล้ว

      @@waiylkarim Where do you imagine you'd store locale/language preferences on the servers if not in the database?

    • @waiylkarim
      @waiylkarim 2 ปีที่แล้ว

      @@bentomlin It's what Cookies are for, mate

  • @politlab1
    @politlab1 ปีที่แล้ว

    What about other translation features like pluralization, choice() etc? Maybe after 2 years some packages appeared in which all this is implemented?

  • @MassimoSimonini
    @MassimoSimonini 2 ปีที่แล้ว

    Thank you, K.I.S.S. methodogy is still the best! Can you explain how to switch from Mixin to Composable on such cases?

  • @gotoslovakia
    @gotoslovakia 2 ปีที่แล้ว

    Unfortunately it doesn't work for component. I just see {{.__('Create') }} in title...

    • @gotoslovakia
      @gotoslovakia 2 ปีที่แล้ว +1

      Ok, the solution could be instead of

  • @MrMirbat
    @MrMirbat 7 หลายเดือนก่อน

    Thanks for this tutorial. I'm getting error message in translations.js file "Type annotatins can only be used in TypeScript files. ts(8010)". I try to implement your instructions in Laravel 11 Inertia and Vue. Difference is that lang folder is now in root application folder and I use base_path instead of resource path but that isn't a problem because I'm getting lang data (both php and json) in page source, so php code is ok. Problem is in javascript. I install Inertia and Vue using laravel/breeze package. Can you make same tutorial using Laravel 11 and breeze package with Inertia and Vue? Thanks in advance.

  • @EL_PANDA_742
    @EL_PANDA_742 2 ปีที่แล้ว +1

    Genius work I can see here, but something I can't understand:
    Why we include all the translations in script tag? Imagine we have 10.000 sentence with sessions etc ...
    The page will be like a snail.
    I loved your job

    • @bentomlin
      @bentomlin 2 ปีที่แล้ว +1

      Are you suggesting only sending the ones for the current page each time? Perhaps even building up a local cache as each page is visited?

    • @EL_PANDA_742
      @EL_PANDA_742 2 ปีที่แล้ว

      @@bentomlin It's partialy true but, better to get only the requested ones. This latter called lazy loading translations.

    • @SXsoft99
      @SXsoft99 ปีที่แล้ว

      @@EL_PANDA_742 i am about to do this on a new project, and was thinking about injecting them from inertiajs middleware based on the page i am on, based on the route name based on the page i am on, additionally caching them in the state manager and only retrieving them if the page was never accessed before on the current visit

  • @ahmeddeghady4510
    @ahmeddeghady4510 ปีที่แล้ว

    This is one amazing tutorial. Thank you so much for this!
    I have a bit of newbie question here, as I was learning vue, the instructor suggested not to use mixins as they are fraud upon in the community. Since this is a 2 years old video, would you recommend an alternative approach?

    • @cdruc
      @cdruc  ปีที่แล้ว

      Yes, with Vue 3 mixins are kind of obsolete/outdated - nowadays I'd go with a composable instead 👍

  • @dgenerationx8203
    @dgenerationx8203 3 ปีที่แล้ว +2

    Next switch locale language , thanks

  • @gotoslovakia
    @gotoslovakia 2 ปีที่แล้ว +1

    One problem with phpsources - we need to prefix all keys with the name of the file, so not "failed" but "auth.failed".
    I'm looking for an elegant solution, but didn't find for now
    Maybe you can help?

    • @gotoslovakia
      @gotoslovakia 2 ปีที่แล้ว

      This is my solution: return Arr::dot([$file->getFilenameWithoutExtension() => File::getRequire($file->getRealPath())]);