svtools/source/misc/langtab.cxx |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

New commits:
commit 5f163d605b0522e8afde8a5ef84c74281c6b955a
Author:     Andras Timar <[email protected]>
AuthorDate: Thu Feb 26 07:49:58 2026 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Feb 26 16:48:57 2026 +0100

    svtools: rebuild language table on UI language change in LOKit
    
    The SvtLanguageTableImpl singleton caches translated language display
    names at first access. In the LOKit pre-initialization (preloadData),
    the singleton is force-loaded before any UI language is set, so all
    ~450 language names are cached as their untranslated English strings.
    When a document is later loaded with an actual UI language, the cached
    English names persist, causing language dropdowns (e.g. in Format >
    Characters) to always show English names regardless of the view's UI
    language.
    
    Track the UI language used to build the table and, in LOKit mode, check
    on each access whether it has changed. If so, rebuild the table with the
    correct translations.
    
    Change-Id: I88a9611a88281f9294d6f30dbcd8e1149203e70a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200383
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/svtools/source/misc/langtab.cxx b/svtools/source/misc/langtab.cxx
index 56dd955fac39..d2ad35064009 100644
--- a/svtools/source/misc/langtab.cxx
+++ b/svtools/source/misc/langtab.cxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/uno/Any.h>
 
+#include <comphelper/lok.hxx>
 #include <i18nlangtag/lang.h>
 #include <i18nlangtag/mslangid.hxx>
 #include <i18nlangtag/languagetag.hxx>
@@ -53,15 +54,20 @@ class SvtLanguageTableImpl
 {
 private:
     std::vector<std::pair<OUString, LanguageType>> m_aStrings;
+    OUString m_aUILanguage; // UI language used to build the table
     void            AddItem(const OUString& rLanguage, const LanguageType 
eType)
     {
         m_aStrings.emplace_back(rLanguage, eType);
     }
+    void            Build();
 
 public:
 
     SvtLanguageTableImpl();
 
+    // In LOKit mode, rebuild the table if the UI language has changed.
+    void            RebuildIfNeeded();
+
     bool            HasType( const LanguageType eType ) const;
     OUString        GetString( const LanguageType eType ) const;
     LanguageType    GetType( std::u16string_view rStr ) const;
@@ -87,6 +93,7 @@ public:
 SvtLanguageTableImpl& theLanguageTable()
 {
     static SvtLanguageTableImpl aTable;
+    aTable.RebuildIfNeeded();
     return aTable;
 }
 }
@@ -190,6 +197,13 @@ static OUString lcl_getDescription( const LanguageTag& 
rTag )
 
 SvtLanguageTableImpl::SvtLanguageTableImpl()
 {
+    Build();
+}
+
+void SvtLanguageTableImpl::Build()
+{
+    m_aStrings.clear();
+
     for (const auto& [rResId, rType] : STR_ARR_SVT_LANGUAGE_TABLE)
     {
         m_aStrings.emplace_back(SvtResId(rResId), rType);
@@ -216,6 +230,18 @@ SvtLanguageTableImpl::SvtLanguageTableImpl()
                 AddEntry( (aName.isEmpty() ? lcl_getDescription(aLang) : 
aName), nLangType);
         }
     }
+
+    m_aUILanguage = SvtSysLocale().GetUILanguageTag().getBcp47();
+}
+
+void SvtLanguageTableImpl::RebuildIfNeeded()
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return;
+
+    OUString aCurrLang = SvtSysLocale().GetUILanguageTag().getBcp47();
+    if (m_aUILanguage != aCurrLang)
+        Build();
 }
 
 bool SvtLanguageTableImpl::HasType( const LanguageType eType ) const

Reply via email to