تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2948 أدوات العرض

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
مارس 24
1561
2
مارس 24
1640
0
نوفمبر 23
1239
2
مارس 24
5986
3
مارس 24
5039