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

341
Views
Vue i18n: objeto con variables de traducción en el archivo js

Estoy trabajando con Vue, Vue i18n y Quasar.

Entonces, tengo un archivo js que contiene un objeto con identificación y nombre, que uso en las opciones q-select. Quiero que cuando cambie el idioma (en el menú desplegable de idiomas), el nombre de la etiqueta de los meses también cambie. Pero esto sucede solo si actualizo la página. Uso el mismo archivo js en otros componentes.

Componente Vue:

 <q-select v-model="monthValue" :options="monthOptions()" map-options emit-value option-value="id" option-label="name" outlined dense />
 import {getMonths} from "../../components/basic/Months.js"; computed: { monthOptions() { return getMonths; },

Meses.js

 import { i18n } from "../../boot/i18n.js"; export const getMonths = () => [ { id: "January", name: i18n.t("MONTHS.JANUARY") }, { id: "February", name: i18n.t("MONTHS.FEBRUARY") }, { id: "March", name: i18n.t("MONTHS.MARCH") }, { id: "April", name: i18n.t("MONTHS.APRIL") }, { id: "May", name: i18n.t("MONTHS.MAY") }, { id: "June", name: i18n.t("MONTHS.JUNE") }, { id: "July", name: i18n.t("MONTHS.JULY") }, { id: "August", name: i18n.t("MONTHS.AUGUST") }, { id: "September", name: i18n.t("MONTHS.SEPTEMBER") }, { id: "October", name: i18n.t("MONTHS.OCTOBER") }, { id: "November", name: i18n.t("MONTHS.NOVEMBER") }, { id: "December", name: i18n.t("MONTHS.DECEMBER") } ];

He intentado tantas cosas, pero fue en vano... ¿Alguien tiene sugerencias? Gracias.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Que los months se definan fuera de la propiedad calculada desactiva la reactividad de t . La matriz debe crearse dentro monthOptions . Si se reutiliza entre componentes, Months.js debería exportar una función que devuelva una matriz en lugar de una matriz:

 export const getMonths = () => [{...}]
about 4 years ago · Santiago Gelvez Report

0

así que intenté como dijo Estus, pero no sé por qué no funcionó. Entonces, encuentro otra manera. Dejé que la traducción suceda en el componente. Como esto:

 const getMonths = () => [ { id: "January", name: "MONTHS.JANUARY" }, { id: "February", name: "MONTHS.FEBRUARY" }, { id: "March", name: "MONTHS.MARCH" }, { id: "April", name: "MONTHS.APRIL" }, { id: "May", name: "MONTHS.MAY" }, { id: "June", name: "MONTHS.JUNE" }, { id: "July", name: "MONTHS.JULY" }, { id: "August", name: "MONTHS.AUGUST" }, { id: "September", name: "MONTHS.SEPTEMBER" }, { id: "October", name: "MONTHS.OCTOBER" }, { id: "November", name: "MONTHS.NOVEMBER" }, { id: "December", name: "MONTHS.DECEMBER" } ];

Y

 computed: monthOptions() { return getMonths().map(months => ({ ...months, name: this.$t(months.name) })) },

¡Gracias!

about 4 years ago · Santiago Gelvez Report
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!