Skip to content

Commit

Permalink
Merge pull request #10923 from codyrancher/remove-i18n-middleware
Browse files Browse the repository at this point in the history
Removing the i18n middleware from the application
  • Loading branch information
codyrancher authored May 3, 2024
2 parents 6ca6174 + 5312b64 commit be9cb77
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

Vue.config.productionTip = false;
Vue.use(i18n);
Vue.use(i18n, { store: { dispatch() {} } });
Vue.use(VTooltip);
Vue.use(VCleanTooltip);
Vue.component('v-select', vSelect);
Expand Down
3 changes: 0 additions & 3 deletions shell/config/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ const middleware = {};
middleware['authenticated'] = require('../middleware/authenticated.js');
middleware['authenticated'] = middleware['authenticated'].default || middleware['authenticated'];

middleware['i18n'] = require('../middleware/i18n.js');
middleware['i18n'] = middleware['i18n'].default || middleware['i18n'];

export default middleware;
8 changes: 4 additions & 4 deletions shell/initialize/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Taken from @nuxt/vue-app/template/App.js
import {
getMatchedComponentsInstances, getChildrenComponentInstancesUsingFetch, promisify, globalHandleError, sanitizeComponent
} from '../utils/nuxt';
import NuxtError from '../components/templates/error.vue';
import NuxtLoading from '../components/nav/GlobalLoading.vue';
} from '@shell/utils/nuxt';
import NuxtError from '@shell/components/templates/error.vue';
import NuxtLoading from '@shell/components/nav/GlobalLoading.vue';

import '../assets/styles/app.scss';
import '@shell/assets/styles/app.scss';

export default {
render(h) {
Expand Down
2 changes: 1 addition & 1 deletion shell/initialize/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const errorHandler = Vue.config.errorHandler || console.error; // eslint-disable
createApp(nuxt.publicRuntimeConfig).then(mountApp).catch(errorHandler); // eslint-disable-line no-undef

function callMiddleware(Components, context) {
let midd = ['i18n'];
let midd = [];
let unknownMiddleware = false;

Components.forEach((Component) => {
Expand Down
5 changes: 3 additions & 2 deletions shell/initialize/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import version from '@shell/plugins/version';
import emberCookie from '@shell/plugins/ember-cookie';

export async function installPlugins(app, inject, Vue) {
Vue.use(i18n);

const pluginDefinitions = [cookieUniversalNuxt, axios, plugins, pluginsLoader, axiosShell, intNumber, positiveIntNumber, nuxtClientInit, replaceAll, backButton, plugin, codeMirror, version, steveCreateWorker, emberCookie];

const installations = pluginDefinitions.map(async(pluginDefinition) => {
Expand All @@ -40,4 +38,7 @@ export async function installPlugins(app, inject, Vue) {
});

await Promise.all(installations);

// Order matters here. This is coming after the other plugins specifically so $cookies can be installed. i18n/init relies on prefs/get which relies on $cookies.
Vue.use(i18n, { store: app.store });
}
10 changes: 0 additions & 10 deletions shell/middleware/i18n.js

This file was deleted.

13 changes: 11 additions & 2 deletions shell/plugins/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export function directiveSsr(vnode, binding) {
}

const i18n = {
name: 'i18n',
install: (Vue, _options) => {
_options?.store?.dispatch('i18n/init');

if (Vue.prototype.t && Vue.directive('t') && Vue.component('t')) {
// eslint-disable-next-line no-console
console.debug('Skipping i18n install. Directive, component, and option already exist.');
Expand Down Expand Up @@ -129,6 +132,12 @@ const i18n = {

export default i18n;

console.warn('The implicit addition of i18n options has been deprecated in Rancher Shell and will be removed in a future version. Make sure to invoke `Vue.use(i18n)` to maintain compatibility.');
// This is being done for backwards compatibility with our extensions that have written tests and didn't properly make use of Vue.use() when importing and mocking translations
// Example failing test https://github.com/rancher/dashboard/actions/runs/8927503474/job/24521022320?pr=10923
const isThisFileBeingExecutedInATest = process.env.NODE_ENV === 'test';

Vue.use(i18n);
if (isThisFileBeingExecutedInATest) {
// Go take a look at our jest.setup.js to see how we make use of Vue.use(i18n, ...)
console.warn('The implicit addition of i18n options has been deprecated in Rancher Shell and will be removed in a future version. Make sure to invoke `Vue.use(i18n)` to maintain compatibility.');
Vue.use(i18n);
}
1 change: 0 additions & 1 deletion shell/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ export const actions = {
}

res = await allHash(promises);
dispatch('i18n/init');
const isMultiCluster = getters['isMultiCluster'];

// If the local cluster is a Harvester cluster and 'rancher-manager-support' is true, it means that the embedded Rancher is being used.
Expand Down

0 comments on commit be9cb77

Please sign in to comment.