Translations in Laravel and InertiaJS applications

Поділитися
Вставка
  • Опубліковано 8 лис 2024

КОМЕНТАРІ • 33

  • @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! 😀

  • @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

  • @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?

  • @magicoflaravel
    @magicoflaravel Рік тому

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

  • @topalek
    @topalek Рік тому +1

    Awesome tutorial!!! Thanx a lot

  • @samehdoush385
    @samehdoush385 2 роки тому +2

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

  • @Fraps224
    @Fraps224 9 місяців тому

    This is sooo awesoome!! Thank you

  • @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

  • @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?

  • @hbend1li
    @hbend1li 2 роки тому +1

    big thank for this tutorial is very helpful.

    • @cdruc
      @cdruc  2 роки тому

      Glad it was helpful!

  • @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 👍

  • @politlab1
    @politlab1 Рік тому

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

  • @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.

  • @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

  • @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

  • @afulay-hy2oy
    @afulay-hy2oy 11 місяців тому

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

  • @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())]);