Working solely with CDNs, harness Vuetify alongside i18n for enhanced features

Currently, I am developing a Vue project within a static environment that lacks Node or Vue-cli support. In order to utilize Vue, Vuetify, and vue-i18n, we are incorporating them through CDNs.

Our goal is to translate the Vuetify components using Vue-i18n, as demonstrated here.

For reference, you can view a Codepen here, showcasing my attempt at translating the pagination section at the bottom.

Despite my efforts to utilize Vue.use(), I encountered difficulties getting it to function properly. There were no errors reported in the console, yet the translations did not reflect on the page.

import App from '../components/App.vue.js';
import i18n from '../lang/languages.js';
import store from './store/store.js';

Vue.filter('toUpperCase', function(value) {
  return value.toUpperCase();
});

Vue.config.devtools = true;

Vue.use(Vuetify, {
  lang: {
    t: (key, ...params) => i18n.t(key, params)
  }
});

new Vue({
  i18n,
  store,
  el: '#app',
  render: (h) => h(App)
});

The file lang/languages.js contains the following:

import { russian } from './languages/russian.js';
import { chineseSimple } from './languages/chinese-simple.js';
import { german } from './languages/german.js';
import { portuguese} from './languages/portuguese.js';

const languages = {
  'ru': russian,
  'zh-Hans': chineseSimple,
  'de': german,
  'pt': portuguese,
};

const i18n = new VueI18n({
  locale: 'en',
  messages: languages
});

export default i18n;

Answer №1

The item you are seeking is not included in CDN distributions. Wondering why?

Take a look at this snippet of code:

const Vuetify: VuetifyPlugin = {
  install (Vue: VueConstructor, args?: VuetifyUseOptions): void {
    Vue.use(VuetifyComponent, {
      components,
      directives,
      ...args
    })
  },
  version: __VUETIFY_VERSION__
}

if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(Vuetify)
}

Specifically pay attention to this section:

if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(Vuetify)
}

This segment automatically installs Vuetify without any customization like language settings, therefore your Vue.use(Vuetify, {..}) will not be executed since Vue avoids duplicate plugin installations!

So what can you do now?

  1. Clone the Vuetify repository and modify that part of the code to create a new distribution for yourself.
  2. Save the file as vuetify.dist.js and make necessary adjustments.
  3. Explore some unconventional workarounds (which I advise against), but I have prepared a sample for you.

Here's an example on CodePen link, showing my approach:

  1. Load Vue.js file using script tags
  2. Utilize fetch API to download content from vuetify.dist.min.js
  3. Modify window.Vue to a different value to prevent automatic installation of vuetify
  4. Evaluate the altered code

I STRONGLY DISCOURAGE THIS METHOD

fetch("https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.14/vuetify.min.js")
  .then(res => res.text())
  .then(vutify => {
    eval(vutify.replace("window.Vue", "window.Vue2"));

    Vue.use(Vuetify, {
      lang: {
        t: (key, ...params) => i18n.t(key, params)
      }
    });

    const App = Vue.component("app", {
      template: `

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error message 'command not found' pops up after successfully installing a package like mocha or pm2 in nodenv

For instance, I encountered an issue with the pm2 command on my nodenv nodejs setup. Whenever I try to run the pm2 command, I get the following error message: $ pm2 -v $ bash: pm2: command not found Moreover, when I run: $ which pm2 No output is returned ...

Prevent additional clicks on the image

Currently, I am dealing with a situation where I have a list containing a jQuery handler for mouse clicks. The dilemma is that I need to insert an image into the list, but I want clicking on the image to trigger a different function than clicking elsewhere ...

The intricacies of the Jscript ReadLine() function

I am trying to figure out how to read the complete content of a .txt file using JavaScript. I know that ReadLine() can be used to read a specific line from a file, but I need a method that will allow me to read the entire contents of the file. I have searc ...

VueJs: Variable modified in parent component but not reflected in child component

After a user triggers a post request from the parent component, I need to update a Boolean variable called isSubmited. This update will then activate a watch in the child component, leading to another post request that utilizes the ID obtained from the ini ...

What is causing the sorting table to fail in React when using useState?

import React, { useState } from "react"; import "./App.css"; const App = () => { const [data, setData] = useState([ { rank: 1, name: "John", age: 29, job: "Web developer", }, { rank: 2, name: "Micha ...

What is the method for triggering a JavaScript function by clicking a button within a CakePHP application?

<button type="button" id="addleetdata" class="btn btn-primary addleetdata float-left">Add</button> JS File $("#addleetdata").click(function () { console.log("entering into function") startLoading(); console.log("editin ...

A simple way to add a value from a select option into a textarea when there are several dropdown menus and select elements sharing the same

I have several divs with the same class names where I need to input a value from a dropdown menu into the textarea that belongs to the div where the select element is located. I want this function to work smoothly even with more than 10 divs, which is why ...

Vue: monitoring the 'value' of a v-model within a component

I have a component with a v-model directive that looks like this: <my-component v-model="someData.someProp"></my-component> My goal is to watch this specific piece of data within the component and make adjustments based on any change ...

How to Set a Background Image for a Div in React?

render(){ const { classes } = this.props; const { imageDescription } = this.props.imgDesc; const { currentIndex } = this.state; var fullPath = `../images/Large/${(imageDescription[currentIndex]).imagePath}.jpg`; con ...

Self-reference within a JavaScript object involves creating a property that points

Can you reference another part of a JSON object within the same JSON object? In the code snippet below, there is an object that refers to the "home" object within the "MapParameters" object. { "parameters": { "data": { "URL": "http://SC.json ...

When a user toggles one div, the other toggled div should automatically close

Below is a snippet of code where I have implemented a functionality using vue.js to toggle different divs based on button clicks. The current setup allows for toggling individual divs when their corresponding buttons are clicked. However, I am looking to ...

Dynamic text displayed on an image with hover effect using JavaScript

Currently, I am in the process of developing a website for a coding course that is part of my university curriculum. The project specifications require the use of JavaScript, so I have incorporated it to display text over images when they are hovered over ...

No results in AngularJS

I have two factory functions: Factories factory.getCurrEmployee = function() { data = {"api_token": authenticationFactory.getToken()}; url = GLOBALS.url + 'show/employee/' + $cookieStore.get('employeeid'); return requestFa ...

Attempting to download an image through an axios fetch call

There is an issue I am facing while trying to retrieve an image from the website www.thispersondoesnotexit.com. function getImage() { axios({ method: 'get', url: 'https://www.thispersondoesnotexist.com/image' }) ...

troubles with redirecting using jQuery

I'm encountering difficulties with redirecting a page using jQuery. I have a variable called url that holds the value localhost/abc#123. However, when I use document.location.href = url;, the page redirects to just localhost/abc without including #123 ...

Is there a way to retrieve an array generated within a JavaScript loop?

I've been working on retrieving column values from a database and storing them in an array, but I keep getting an empty array as the result. function FetchData(query, db) { var resultArray = new Array(); db.transaction(function(tx) { tx.executeSq ...

When using the HTML5 draw img feature, only the top 1/4 of the image will be

I am having trouble loading a full image into canvas. Currently, it only displays the top 1/4 of the image regardless of which one I use. Any help would be greatly appreciated. Here is the code snippet in question: var canvas = document.getElementById(&ap ...

Utilizing HTML5 to automatically refresh the page upon a change in geolocation

I have a web application built with AngularJS. One of the functionalities is activated only when the user is in close proximity to specific locations. To make this work, I can constantly refresh the page every 5 seconds and carry out calculations to dete ...

Prevent the creation of references to objects passed as function parameters in a separate list

I'm facing an issue with modifying items from an array and adding them to a new list of objects. The problem arises when I make changes to the item in the new list, it also reflects those changes in the original array. It seems like there is some ref ...

Issue: Headers cannot be set after they have been sent. This is a problem in node.js

I'm trying to create an application that allows users to execute commands via a URL, but I keep encountering this error message: _http_outgoing.js:346 throw new Error('Can\'t set headers after they are sent.'); ^Error: Can't ...