10 months ago

Select proper value from array dynamically

Posted 10 months ago by nhayder

in my app i have page footer are where it supposed to show copyright message dynamically according the users reading language.

the copyright data with multiple languages values is already stored in array that looks like this

// copyrights array
id: 1,
  de: "Alle Rechte vorbehalten - 2019.",
  en: "All rights reserved - 2019",
  es: "Todos los derechos reservados - 2019.",
  fr: "Tous droits réservés - 2019.",

from my page footer component i can get the current language from array like this

<p v-html="copyrights.en"></p> // --> this will show footer copyright message in english

to get the current page language i have stored it on a locale variable and it returns the current reading language extension (en, fr, it ,.....)

console.log(locale) // returns proper value for example en or de, ...

so now i can choose which message to show on page footer dynamically because i have the current page locale and the multilanguage copyright array with all data i need

so i made a function that will return the correct data

<p v-html="message()"></p> // localized message should be shown here

// this is the function
    message : function(){

      var locale = this.pagesettings.language_id;
      return this.copyrights+locale; // is returning error but copyrights.en is returning correct data


can someone please write the correct code for my dynamic copyright function.


Please sign in or create an account to participate in this conversation.