sw/inc/shellres.hxx | 4 + sw/source/core/view/viewsh.cxx | 3 + sw/source/uibase/utlui/initui.cxx | 77 +++++++++++++++++++++++--------------- 3 files changed, 55 insertions(+), 29 deletions(-)
New commits: commit bc940a34ceba0a2b05a9b92ffeaeebe0f2c8db91 Author: Andras Timar <[email protected]> AuthorDate: Thu Feb 26 11:39:38 2026 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Feb 27 09:52:35 2026 +0100 sw: rebuild ShellResource on UI language change in LOKit The ShellResource singleton caches translated UI strings at construction time during InitUI(). In LOKit pre-initialization, this happens before any UI language is set, so all strings are cached as English. When a document is later loaded with an actual UI language, the cached English strings persist. Fix this by extracting the constructor body into a Build() method and adding a RebuildIfNeeded() check that compares the current LOKit UI language against the one used at build time. The check is called from SwViewShell::GetShellRes() before returning the cached pointer. This is the same class of bug fixed in commit I88a9611a88281f9294d6f30dbcd8e1149203e70a for SvtLanguageTableImpl. Change-Id: Ib404b170925503b50bd1d285b4e91eb5175830c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200423 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sw/inc/shellres.hxx b/sw/inc/shellres.hxx index 6cbcd91e8ab0..920da5e3c1f2 100644 --- a/sw/inc/shellres.hxx +++ b/sw/inc/shellres.hxx @@ -77,12 +77,16 @@ struct SW_DLLPUBLIC ShellResource ShellResource(); + void RebuildIfNeeded(); + private: + void Build(); void GetAutoFormatNameLst_() const; mutable std::optional<std::vector<OUString>> mxAutoFormatNameLst; OUString sPageDescFirstName; OUString sPageDescFollowName; OUString sPageDescName; + OUString m_aUILanguage; }; inline const std::vector<OUString>& ShellResource::GetAutoFormatNameLst() const diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx index c00ed44bbf5b..6cb57685fe4e 100644 --- a/sw/source/core/view/viewsh.cxx +++ b/sw/source/core/view/viewsh.cxx @@ -78,6 +78,7 @@ #include <svx/sdrpagewindow.hxx> #include <svx/svdpagv.hxx> #include <comphelper/lok.hxx> +#include <shellres.hxx> #include <sfx2/lokhelper.hxx> #include <tools/UnitConversion.hxx> @@ -2830,6 +2831,8 @@ void SwViewShell::ApplyAccessibilityOptions() ShellResource* SwViewShell::GetShellRes() { + if (spShellRes) + spShellRes->RebuildIfNeeded(); return spShellRes; } diff --git a/sw/source/uibase/utlui/initui.cxx b/sw/source/uibase/utlui/initui.cxx index f24cded867f5..2a59efd625ee 100644 --- a/sw/source/uibase/utlui/initui.cxx +++ b/sw/source/uibase/utlui/initui.cxx @@ -32,6 +32,7 @@ #include <utlui.hrc> #include <authfld.hxx> #include <unotools/syslocale.hxx> +#include <comphelper/lok.hxx> // Global Pointer @@ -105,38 +106,56 @@ const TranslateId FLD_DOCINFO_ARY[] = }; ShellResource::ShellResource() - : aPostItAuthor( SwResId( STR_POSTIT_AUTHOR ) ), - aPostItPage( SwResId( STR_POSTIT_PAGE ) ), - aPostItLine( SwResId( STR_POSTIT_LINE ) ), - - aCalc_Syntax( SwResId( STR_CALC_SYNTAX ) ), - aCalc_ZeroDiv( SwResId( STR_CALC_ZERODIV ) ), - aCalc_Brack( SwResId( STR_CALC_BRACK ) ), - aCalc_Pow( SwResId( STR_CALC_POW ) ), - aCalc_Overflow( SwResId( STR_CALC_OVERFLOW ) ), - aCalc_Default( SwResId( STR_CALC_DEFAULT ) ), - aCalc_Error( SwResId( STR_CALC_ERROR ) ), - - // #i81002# - aGetRefField_RefItemNotFound( SwResId( STR_GETREFFLD_REFITEMNOTFOUND ) ), - aStrNone( SwResId( STR_TEMPLATE_NONE )), - aFixedStr( SwResId( STR_FIELD_FIXED )), - sDurationFormat( SwResId( STR_DURATION_FORMAT )), - - aTOXIndexName( SwResId(STR_TOI)), - aTOXUserName( SwResId(STR_TOU)), - aTOXContentName( SwResId(STR_TOC)), - aTOXIllustrationsName( SwResId(STR_TOX_ILL)), - aTOXObjectsName( SwResId(STR_TOX_OBJ)), - aTOXTablesName( SwResId(STR_TOX_TBL)), - aTOXAuthoritiesName( SwResId(STR_TOX_AUTH)), - aTOXCitationName( SwResId(STR_TOX_CITATION)), - sPageDescFirstName( SwResId(STR_PAGEDESC_FIRSTNAME)), - sPageDescFollowName( SwResId(STR_PAGEDESC_FOLLOWNAME)), - sPageDescName( SwResId(STR_PAGEDESC_NAME)) { + Build(); +} + +void ShellResource::Build() +{ + aPostItAuthor = SwResId(STR_POSTIT_AUTHOR); + aPostItPage = SwResId(STR_POSTIT_PAGE); + aPostItLine = SwResId(STR_POSTIT_LINE); + aCalc_Syntax = SwResId(STR_CALC_SYNTAX); + aCalc_ZeroDiv = SwResId(STR_CALC_ZERODIV); + aCalc_Brack = SwResId(STR_CALC_BRACK); + aCalc_Pow = SwResId(STR_CALC_POW); + aCalc_Overflow = SwResId(STR_CALC_OVERFLOW); + aCalc_Default = SwResId(STR_CALC_DEFAULT); + aCalc_Error = SwResId(STR_CALC_ERROR); + aGetRefField_RefItemNotFound = SwResId(STR_GETREFFLD_REFITEMNOTFOUND); + aStrNone = SwResId(STR_TEMPLATE_NONE); + aFixedStr = SwResId(STR_FIELD_FIXED); + sDurationFormat = SwResId(STR_DURATION_FORMAT); + aTOXIndexName = SwResId(STR_TOI); + aTOXUserName = SwResId(STR_TOU); + aTOXContentName = SwResId(STR_TOC); + aTOXIllustrationsName = SwResId(STR_TOX_ILL); + aTOXObjectsName = SwResId(STR_TOX_OBJ); + aTOXTablesName = SwResId(STR_TOX_TBL); + aTOXAuthoritiesName = SwResId(STR_TOX_AUTH); + aTOXCitationName = SwResId(STR_TOX_CITATION); + sPageDescFirstName = SwResId(STR_PAGEDESC_FIRSTNAME); + sPageDescFollowName = SwResId(STR_PAGEDESC_FOLLOWNAME); + sPageDescName = SwResId(STR_PAGEDESC_NAME); + + aDocInfoLst.clear(); for (auto const& aID : FLD_DOCINFO_ARY) aDocInfoLst.push_back(SwResId(aID)); + + mxAutoFormatNameLst.reset(); + + if (comphelper::LibreOfficeKit::isActive()) + m_aUILanguage = comphelper::LibreOfficeKit::getLanguageTag().getBcp47(); +} + +void ShellResource::RebuildIfNeeded() +{ + if (!comphelper::LibreOfficeKit::isActive()) + return; + + OUString aCurrLang = comphelper::LibreOfficeKit::getLanguageTag().getBcp47(); + if (aCurrLang != m_aUILanguage) + Build(); } OUString ShellResource::GetPageDescName(sal_uInt16 nNo, PageNameMode eMode)
