Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Changing the error message language based on the selected language in a custom Odoo 17 API

Odebírat

Get notified when there's activity on this post

This question has been flagged
translationodoo17Odoo17
2406 Zobrazení
Avatar
chaher


In my Odoo 17 application, I have enabled the Arabic language in the backend. When I access the Odoo website and change the language to Arabic, the error messages are displayed correctly in this language.


However, I have developed a custom API and I want the error messages to change language based on the language chosen by the user. I have created a .po file with the translations and I have created this API to change the language:



@http.route('/api/lang/', type='http', auth="public",csrf=False, cors='*')
def change_lang(self, lang):
    """ :param lang: supposed to be value of `url_code` field """
    try:
        lang_code = request.env['res.lang']._lang_get_code(lang)
        # replace context with correct lang, to avoid that the url_for of request.redirect remove the
        # default lang in case we switch from /fr -> /en with /en as default lang.
        request.update_context(lang=lang_code)
        request.env.user.lang = lang_code
        request.future_response.set_cookie('frontend_lang', lang_code)
        return request.make_response(json.dumps({'success': True,'lang_code':lang_code, 'contxt':  request.env.context, 'env lang': request.env.lang, 'public user': request.env.user.lang}),
                              headers={'Content-Type': 'application/json'})
    except Exception as e:
        return {'success': False, 'error': str(e)}



When I call the URL `/api/lang/ar`, I receive the following response:



{
    "success": true,
    "lang_code": "ar_001",
    "contxt": {
        "lang": "ar_001"
    },
    "env lang": "ar_001",
    "public user": "ar_001"
}



Then, when I call the API that returns an error message, for example `/ar/api/login` or `/api/login`, I receive the following response:



{
    "jsonrpc": "2.0",
    "id": null,
    "result": {
        "success": false,
        "error": "Access denied"
    }
}


The problem is that the error message "Access denied" is not displayed in the selected language (Arabic in this case), but remains in English. [citation:1][citation:2][citation:3][citation:4][citation:5][citation:6][citation:7]


However, if I change the language of my admin account (Mitchell Admin), the error message is then displayed in the selected language. Note that I am not logged in at all, I am accessing as a public user. [citation:8][citation:9][citation:10]


How can I make the error message display in the selected language, even when I am a public user?

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Send notification to specific users Vyřešeno
odoo17 Odoo17 odoo17EE
Avatar
Avatar
2
zář 25
1188
Error when entering settings
odoo odoo17 Odoo17
Avatar
Avatar
Avatar
2
dub 25
4176
Owl : want to patch the protected method in owl js. Vyřešeno
OWL odoo17 Odoo17
Avatar
Avatar
1
pro 24
2103
Free Sing Up ?? Vyřešeno
Odooenterprise odoo17 Odoo17
Avatar
Avatar
Avatar
2
srp 24
5559
Cannot find module "Meeting Rooms" in Odoo17 Vyřešeno
odoo17 rooms Odoo17
Avatar
Avatar
1
čvc 24
2299
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now