From 8de58b6fd63302544affb90df347323b82b7d259 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Thu, 3 Sep 2020 21:07:22 +0200 Subject: lok: make labels and tooltips translated for commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the online we can have multiple sessions with different languages so load cached translations only if match current language Change-Id: I6fcf23f1c340c0c0daffa8862f0b74e4e458c1fc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102016 Tested-by: Jenkins CollaboraOffice Reviewed-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102960 Tested-by: Jenkins Tested-by: Szymon Kłos --- framework/inc/uielement/uicommanddescription.hxx | 7 ++- .../uiconfiguration/uicategorydescription.cxx | 12 ++++-- .../source/uielement/uicommanddescription.cxx | 50 ++++++++++++++++------ 3 files changed, 50 insertions(+), 19 deletions(-) (limited to 'framework') diff --git a/framework/inc/uielement/uicommanddescription.hxx b/framework/inc/uielement/uicommanddescription.hxx index 6886224ceb00..146b4f42db3a 100644 --- a/framework/inc/uielement/uicommanddescription.hxx +++ b/framework/inc/uielement/uicommanddescription.hxx @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include namespace framework { @@ -80,12 +82,13 @@ public: protected: UICommandDescription( const css::uno::Reference< css::uno::XComponentContext>& rxContext, bool ); void impl_fillElements(const char* _pName); + void ensureGenericUICommandsForLanguage(const LanguageTag& rLanguage); OUString m_aPrivateResourceURL; css::uno::Reference< css::uno::XComponentContext > m_xContext; ModuleToCommandFileMap m_aModuleToCommandFileMap; - UICommandsHashMap m_aUICommandsHashMap; - css::uno::Reference< css::container::XNameAccess > m_xGenericUICommands; + std::map m_aUICommandsHashMap; + std::map > m_xGenericUICommands; css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager; }; diff --git a/framework/source/uiconfiguration/uicategorydescription.cxx b/framework/source/uiconfiguration/uicategorydescription.cxx index 517a8d47f5b4..471bd67ca7c7 100644 --- a/framework/source/uiconfiguration/uicategorydescription.cxx +++ b/framework/source/uiconfiguration/uicategorydescription.cxx @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include @@ -362,16 +364,18 @@ public: UICategoryDescription::UICategoryDescription( const Reference< XComponentContext >& rxContext ) : UICommandDescription(rxContext,true) { + LanguageTag aCurrentLanguage = SvtSysLocale().GetUILanguageTag(); Reference< XNameAccess > xEmpty; OUString aGenericCategories( "GenericCategories" ); - m_xGenericUICommands = new ConfigurationAccess_UICategory( aGenericCategories, xEmpty, rxContext ); + m_xGenericUICommands[aCurrentLanguage] = new ConfigurationAccess_UICategory( aGenericCategories, xEmpty, rxContext ); // insert generic categories mappings m_aModuleToCommandFileMap.emplace( OUString("generic"), aGenericCategories ); - UICommandsHashMap::iterator pCatIter = m_aUICommandsHashMap.find( aGenericCategories ); - if ( pCatIter != m_aUICommandsHashMap.end() ) - pCatIter->second = m_xGenericUICommands; + auto& rMap = m_aUICommandsHashMap[aCurrentLanguage]; + UICommandsHashMap::iterator pCatIter = rMap.find( aGenericCategories ); + if ( pCatIter != rMap.end() ) + pCatIter->second = m_xGenericUICommands[aCurrentLanguage]; impl_fillElements("ooSetupFactoryCmdCategoryConfigRef"); } diff --git a/framework/source/uielement/uicommanddescription.cxx b/framework/source/uielement/uicommanddescription.cxx index f53c2a5cb1fc..28c606ea96a4 100644 --- a/framework/source/uielement/uicommanddescription.cxx +++ b/framework/source/uielement/uicommanddescription.cxx @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -552,21 +553,32 @@ void SAL_CALL ConfigurationAccess_UICommand::disposing( const EventObject& aEven } } +void UICommandDescription::ensureGenericUICommandsForLanguage(const LanguageTag& rLanguage) +{ + auto xGenericUICommands = m_xGenericUICommands.find(rLanguage); + if (xGenericUICommands == m_xGenericUICommands.end()) + { + Reference< XNameAccess > xEmpty; + m_xGenericUICommands[rLanguage] = new ConfigurationAccess_UICommand( "GenericCommands", xEmpty, m_xContext ); + } +} + UICommandDescription::UICommandDescription(const Reference< XComponentContext >& rxContext) : UICommandDescription_BASE(m_aMutex) , m_aPrivateResourceURL(PRIVATE_RESOURCE_URL) , m_xContext(rxContext) { - Reference< XNameAccess > xEmpty; - OUString aGenericUICommand( "GenericCommands" ); - m_xGenericUICommands = new ConfigurationAccess_UICommand( aGenericUICommand, xEmpty, m_xContext ); + LanguageTag aCurrentLanguage = SvtSysLocale().GetUILanguageTag(); + + ensureGenericUICommandsForLanguage(aCurrentLanguage); impl_fillElements("ooSetupFactoryCommandConfigRef"); // insert generic commands - UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aGenericUICommand ); - if ( pIter != m_aUICommandsHashMap.end() ) - pIter->second = m_xGenericUICommands; + auto& rMap = m_aUICommandsHashMap[aCurrentLanguage]; + UICommandsHashMap::iterator pIter = rMap.find( "GenericCommands" ); + if ( pIter != rMap.end() ) + pIter->second = m_xGenericUICommands[aCurrentLanguage]; } UICommandDescription::UICommandDescription(const Reference< XComponentContext >& rxContext, bool) @@ -606,15 +618,18 @@ void UICommandDescription::impl_fillElements(const char* _pName) m_aModuleToCommandFileMap.emplace( aModuleIdentifier, aCommandStr ); // Create second mapping Command File ==> commands instance - UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandStr ); - if ( pIter == m_aUICommandsHashMap.end() ) - m_aUICommandsHashMap.emplace( aCommandStr, Reference< XNameAccess >() ); + LanguageTag aCurrentLanguage = SvtSysLocale().GetUILanguageTag(); + auto& rMap = m_aUICommandsHashMap[aCurrentLanguage]; + UICommandsHashMap::iterator pIter = rMap.find( aCommandStr ); + if ( pIter == rMap.end() ) + rMap.emplace( aCommandStr, Reference< XNameAccess >() ); } } // for ( sal_Int32 i = 0; i < aElementNames.(); i++ ) } Any SAL_CALL UICommandDescription::getByName( const OUString& aName ) { + LanguageTag aCurrentLanguage = SvtSysLocale().GetUILanguageTag(); Any a; osl::MutexGuard g(rBHelper.rMutex); @@ -623,16 +638,23 @@ Any SAL_CALL UICommandDescription::getByName( const OUString& aName ) if ( pM2CIter != m_aModuleToCommandFileMap.end() ) { OUString aCommandFile( pM2CIter->second ); - UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandFile ); - if ( pIter != m_aUICommandsHashMap.end() ) + auto pMapIter = m_aUICommandsHashMap.find( aCurrentLanguage ); + if ( pMapIter == m_aUICommandsHashMap.end() ) + impl_fillElements("ooSetupFactoryCommandConfigRef"); + + auto& rMap = m_aUICommandsHashMap[aCurrentLanguage]; + UICommandsHashMap::iterator pIter = rMap.find( aCommandFile ); + if ( pIter != rMap.end() ) { if ( pIter->second.is() ) a <<= pIter->second; else { + ensureGenericUICommandsForLanguage(aCurrentLanguage); + Reference< XNameAccess > xUICommands; ConfigurationAccess_UICommand* pUICommands = new ConfigurationAccess_UICommand( aCommandFile, - m_xGenericUICommands, + m_xGenericUICommands[aCurrentLanguage], m_xContext ); xUICommands.set( static_cast< cppu::OWeakObject* >( pUICommands ),UNO_QUERY ); pIter->second = xUICommands; @@ -642,8 +664,10 @@ Any SAL_CALL UICommandDescription::getByName( const OUString& aName ) } else if ( !m_aPrivateResourceURL.isEmpty() && aName.startsWith( m_aPrivateResourceURL ) ) { + ensureGenericUICommandsForLanguage(aCurrentLanguage); + // special keys to retrieve information about a set of commands - return m_xGenericUICommands->getByName( aName ); + return m_xGenericUICommands[aCurrentLanguage]->getByName( aName ); } else { -- cgit