跳至內容
選單
此問題已被標幟
1 回覆
2760 瀏覽次數

I am getting error when changing language,

Specifically, I use a module used to create a button to change the language.

when i change everything is ok except the Menu it is not changed until i f5 the page again.

I downloaded that module here: https://apps.odoo.com/apps/modules/16.0/web_systray_language/

This is what Js wrote:

/** @odoo-module **/
import {Dropdownfrom'@web/core/dropdown/dropdown';

import {DropdownItem} from'@web/core/dropdown/dropdown_item';

import {useService} from'@web/core/utils/hooks';

import {registry} from'@web/core/registry';

import {Component, onWillStart} from'@odoo/owl';

import {session} from'@web/session';

import {browser} from'@web/core/browser/browser';
export class SwitchLanguageMenu extends Component {

setup() {

this.langService = useService('lang');

this.ormService = useService('orm');
this.userLangCode = session.bundle_params.lang;


onWillStart(async () => {

this.langs = awaitthis.langService.getLangs();

this.lang = this.langs.find(l=>l.code === this.userLangCode);

 }

)

}


async switch(lang) {

if (this.lang === lang) {

return

}

await this.ormService.write('res.users', [session.uid], {

lang:lang.code,

});

browser.thread.refresh() }}


SwitchLanguageMenu.template = 'web_systray_language.SwitchLanguageMenu';

SwitchLanguageMenu.components = {Dropdown, DropdownItem};

export const languageSystrayItem = {

Component:SwitchLanguageMenu,

};

registry.category('systray').add('SwitchLanguageMenu', languageSystrayItem, {sequence:1});

頭像
捨棄
最佳答案
  1. Ensure that the language change is successfully being saved in the user's profile. You can check this by verifying the lang field in the res.users model for the user.

  2. Add a custom function to handle the language change and force Odoo to reload the session using JavaScript.

Here's a modified version of your JavaScript code that includes a function to reload the session after changing the language:

/** @odoo-module **/

import { Dropdown } from '@web/core/dropdown/dropdown';

import { DropdownItem } from '@web/core/dropdown/dropdown_item';

import { useService } from '@web/core/utils/hooks';

import { registry } from '@web/core/registry';

import { Component, onWillStart } from '@odoo/owl';

import { session } from '@web/session';

import { browser } from '@web/core/browser/browser';


export class SwitchLanguageMenu extends Component {

setup() {

this.langService = useService('lang');

this.ormService = useService('orm');

this.userLangCode = session.bundle_params.lang;


onWillStart(async () => {

this.langs = await this.langService.getLangs();

this.lang = this.langs.find((l) => l.code === this.userLangCode);

});

}


async switch(lang) {

if (this.lang === lang) {

return;

}


await this.ormService.write('res.users', [session.uid], {

lang: lang.code,

});


// Clear the language cache to force Odoo to apply the language change

session.lang = lang.code;

session.user_context.lang = lang.code;

browser.session.session_reload();


// Use the following if you want to refresh the whole page instead of just the session

// window.location.reload();

}

}


SwitchLanguageMenu.template



頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
3月 24
1470
2
3月 24
1473
0
11月 23
1144
2
3月 24
5755
3
3月 24
4870