Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Laravel, InertiaJS, make translate from Database function globally

I have made this helper function to translate proper column from database (MySQL). Database is like this.

 Id     name_en     name_fr    name_de
 1      Car         Auto       Auto
 2      Plane       Avion      Ebene

My helper function is like this..

import { Inertia } from "@inertiajs/inertia";

export default function translate(array, column) {

    let locale = Inertia.page.props.locale;
    let value = array[column + '_' + locale];

    return value ?? 'Missing Translation';

}

In my component i call this function like this and it works fine.

<script setup>
import translate from "@/Helpers/translateFromDb";

defineProps({
  object: {
    type: Object,
  },
});
</script>

<template>
  <ul class="flex justify-start space-x-6">
    <li v-for="item in object" :key="item.id">
      {{ translate(item, "name") }}
    </li>
  </ul>
</template>

<style scoped>
</style>

Is there a way to import this helper function globally instead to call it on every component?

EDIT: Yeah i know it the same result could be obtained by using a Trait in the ObjectResource, but i'm learning Vue and i was looking to do this with it.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!