summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2020-09-03 21:07:22 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2020-09-18 13:30:37 +0200
commit8de58b6fd63302544affb90df347323b82b7d259 (patch)
treeeb4e081d34731c459d15a98c49ea4b0e419a4957 /framework
parent10aac52bafc8a0430d1da3fe8f45832c64d6bf34 (diff)
lok: make labels and tooltips translated for commands
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102960 Tested-by: Jenkins Tested-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/inc/uielement/uicommanddescription.hxx7
-rw-r--r--framework/source/uiconfiguration/uicategorydescription.cxx12
-rw-r--r--framework/source/uielement/uicommanddescription.cxx50
3 files changed, 50 insertions, 19 deletions
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 <unordered_map>
+#include <map>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/XModuleManager2.hpp>
@@ -29,6 +30,7 @@
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <rtl/ustring.hxx>
+#include <i18nlangtag/languagetag.hxx>
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<LanguageTag, UICommandsHashMap> m_aUICommandsHashMap;
+ std::map<LanguageTag, css::uno::Reference< css::container::XNameAccess > > 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 <sal/log.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <unotools/configmgr.hxx>
+#include <unotools/syslocale.hxx>
#include <comphelper/propertysequence.hxx>
@@ -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 <cppuhelper/implbase.hxx>
#include <unotools/configmgr.hxx>
+#include <unotools/syslocale.hxx>
#include <vcl/mnemonic.hxx>
#include <comphelper/propertysequence.hxx>
@@ -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
{