summaryrefslogtreecommitdiff
path: root/scaddins/source/pricing
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-06-11 20:56:30 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-07-21 08:20:50 +0100
commit00657aef09d854c74fb426a935a3e8b1fc390bb0 (patch)
treefd1a9bb264fe15dcc129498e62060ecd256b1ee7 /scaddins/source/pricing
parentfa987cbb813cfd729fe490f2f1258b7c8d7fb174 (diff)
migrate to boost::gettext
* all .ui files go from <interface> to <interface domain="MODULE"> e.g. vcl * all .src files go away and the english source strings folded into the .hrc as NC_("context", "source string") * ResMgr is dropped in favour of std::locale imbued by boost::locale::generator pointed at matching MODULE .mo files * UIConfig translations are folded into the module .mo, so e.g. UIConfig_cui goes from l10n target to normal one, so the res/lang.zips of UI files go away * translation via Translation::get(hrc-define-key, imbued-std::locale) * python can now be translated with its inbuilt gettext support (we keep the name strings.hrc there to keep finding the .hrc file uniform) so magic numbers can go away there * java and starbasic components can be translated via the pre-existing css.resource.StringResourceWithLocation mechanism * en-US res files go away, their strings are now the .hrc keys in the source code * remaining .res files are replaced by .mo files * in .res/.ui-lang-zip files, the old scheme missing translations of strings results in inserting the english original so something can be found, now the standard fallback of using the english original from the source key is used, so partial translations shrink dramatically in size * extract .hrc strings with hrcex which backs onto xgettext -C --add-comments --keyword=NC_:1c,2 --from-code=UTF-8 --no-wrap * extract .ui strings with uiex which backs onto xgettext --add-comments --no-wrap * qtz for gettext translations is generated at runtime as ascii-ified crc32 of content + "|" + msgid * [API CHANGE] remove deprecated binary .res resouce loader related uno apis com::sun::star::resource::OfficeResourceLoader com::sun::star::resource::XResourceBundleLoader com::sun::star::resource::XResourceBundle when translating strings via uno apis com.sun.star.resource.StringResourceWithLocation can continue to be used Change-Id: Ia2594a2672b7301d9c3421fdf31b6cfe7f3f8d0a
Diffstat (limited to 'scaddins/source/pricing')
-rw-r--r--scaddins/source/pricing/pricing.cxx51
-rw-r--r--scaddins/source/pricing/pricing.hrc41
-rw-r--r--scaddins/source/pricing/pricing.hxx36
-rw-r--r--scaddins/source/pricing/pricing.src153
4 files changed, 28 insertions, 253 deletions
diff --git a/scaddins/source/pricing/pricing.cxx b/scaddins/source/pricing/pricing.cxx
index 466c0e78fd44..3df3fe78a061 100644
--- a/scaddins/source/pricing/pricing.cxx
+++ b/scaddins/source/pricing/pricing.cxx
@@ -25,6 +25,7 @@
#include "pricing.hxx"
#include "black_scholes.hxx"
#include "pricing.hrc"
+#include "strings.hrc"
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -32,7 +33,6 @@
#include <algorithm>
#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
-#include <tools/rcid.h>
#include <tools/resmgr.hxx>
using namespace ::com::sun::star;
@@ -43,11 +43,6 @@ using namespace sca::pricing;
#define MY_SERVICE "com.sun.star.sheet.addin.PricingFunctions"
#define MY_IMPLNAME "com.sun.star.sheet.addin.PricingFunctionsImpl"
-ScaResId::ScaResId( sal_uInt16 nId, ResMgr& rResMgr ) :
- ResId( nId, rResMgr )
-{
-}
-
#define UNIQUE false // function name does not exist in Calc
#define STDPAR false // all parameters are described
@@ -67,8 +62,8 @@ const ScaFuncDataBase pFuncDataArr[] =
ScaFuncData::ScaFuncData( const ScaFuncDataBase& rBaseData ) :
aIntName( OUString::createFromAscii( rBaseData.pIntName ) ),
- nUINameID( rBaseData.nUINameID ),
- nDescrID( rBaseData.nDescrID ),
+ pUINameID( rBaseData.pUINameID ),
+ pDescrID( rBaseData.pDescrID ),
nParamCount( rBaseData.nParamCount ),
eCat( rBaseData.eCat ),
bDouble( rBaseData.bDouble ),
@@ -132,7 +127,6 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL pricing_component_getFactory(
// "normal" service implementation
ScaPricingAddIn::ScaPricingAddIn() :
pDefLocales( nullptr ),
- pResMgr( nullptr ),
pFuncDataList( nullptr )
{
}
@@ -140,7 +134,6 @@ ScaPricingAddIn::ScaPricingAddIn() :
ScaPricingAddIn::~ScaPricingAddIn()
{
delete pFuncDataList;
- delete pResMgr;
delete[] pDefLocales;
}
@@ -167,32 +160,13 @@ const lang::Locale& ScaPricingAddIn::GetLocale( sal_uInt32 nIndex )
return (nIndex < sizeof( pLang )) ? pDefLocales[ nIndex ] : aFuncLoc;
}
-ResMgr& ScaPricingAddIn::GetResMgr()
-{
- if( !pResMgr )
- {
- InitData(); // try to get resource manager
- if( !pResMgr )
- throw uno::RuntimeException();
- }
- return *pResMgr;
-}
-
void ScaPricingAddIn::InitData()
{
- delete pResMgr;
- pResMgr = ResMgr::CreateResMgr("pricing", LanguageTag( aFuncLoc) );
+ aResLocale = Translate::Create("sca", LanguageTag(aFuncLoc));
delete pFuncDataList;
- if(pResMgr)
- {
- pFuncDataList = new ScaFuncDataList;
- InitScaFuncDataList(*pFuncDataList);
- }
- else
- {
- pFuncDataList = nullptr;
- }
+ pFuncDataList = new ScaFuncDataList;
+ InitScaFuncDataList(*pFuncDataList);
if( pDefLocales )
{
@@ -201,10 +175,9 @@ void ScaPricingAddIn::InitData()
}
}
-OUString ScaPricingAddIn::GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex )
+OUString ScaPricingAddIn::GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex)
{
- ResStringArray aArr(ScaResId(nResId, GetResMgr()));
- return aArr.GetString(nStrIndex - 1);
+ return ScaResId(pResId[nStrIndex - 1]);
}
OUString ScaPricingAddIn::getImplementationName_Static()
@@ -271,9 +244,9 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayFunctionName( const OUString& aProg
auto fDataIt = std::find_if(pFuncDataList->begin(), pFuncDataList->end(),
FindScaFuncData( aProgrammaticName ) );
- if(fDataIt != pFuncDataList->end() )
+ if (fDataIt != pFuncDataList->end() )
{
- aRet = ScaResId(fDataIt->GetUINameID(), GetResMgr());
+ aRet = ScaResId(fDataIt->GetUINameID());
if( fDataIt->IsDouble() )
aRet += "_ADD";
}
@@ -583,5 +556,9 @@ double SAL_CALL ScaPricingAddIn::getOptProbInMoney( double spot, double vol,
RETURN_FINITE( fRet );
}
+OUString ScaPricingAddIn::ScaResId(const char* pResId)
+{
+ return Translate::get(pResId, aResLocale);
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/scaddins/source/pricing/pricing.hrc b/scaddins/source/pricing/pricing.hrc
deleted file mode 100644
index af516650eb75..000000000000
--- a/scaddins/source/pricing/pricing.hrc
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HRC
-#define INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HRC
-
-#define PRICING_RESOURCE_START 1000
-
-#define PRICING_FUNCDESC_START PRICING_RESOURCE_START
-
-#define PRICING_FUNCDESC_OptBarrier (PRICING_FUNCDESC_START)
-#define PRICING_FUNCDESC_OptTouch (PRICING_FUNCDESC_START+1)
-#define PRICING_FUNCDESC_OptProbHit (PRICING_FUNCDESC_START+2)
-#define PRICING_FUNCDESC_OptProbInMoney (PRICING_FUNCDESC_START+3)
-
-#define PRICING_FUNCNAME_START (PRICING_RESOURCE_START+1000)
-
-#define PRICING_FUNCNAME_OptBarrier (PRICING_FUNCNAME_START)
-#define PRICING_FUNCNAME_OptTouch (PRICING_FUNCNAME_START+1)
-#define PRICING_FUNCNAME_OptProbHit (PRICING_FUNCNAME_START+2)
-#define PRICING_FUNCNAME_OptProbInMoney (PRICING_FUNCNAME_START+3)
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/scaddins/source/pricing/pricing.hxx b/scaddins/source/pricing/pricing.hxx
index 18acc54c811f..82fbbb6cacc5 100644
--- a/scaddins/source/pricing/pricing.hxx
+++ b/scaddins/source/pricing/pricing.hxx
@@ -37,8 +37,6 @@
#include <com/sun/star/sheet/XCompatibilityNames.hpp>
#include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
#include <cppuhelper/implbase.hxx>
-#include <tools/resid.hxx>
-#include <tools/resary.hxx>
#define RETURN_FINITE(d) if( ::rtl::math::isFinite( d ) ) return d; else throw css::lang::IllegalArgumentException()
@@ -46,12 +44,6 @@
namespace sca {
namespace pricing {
-class ScaResId : public ResId
-{
-public:
- ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
-};
-
enum class ScaCategory
{
DateTime,
@@ -65,8 +57,8 @@ enum class ScaCategory
struct ScaFuncDataBase
{
const sal_Char* pIntName; // internal name (get***)
- sal_uInt16 nUINameID; // resource ID to UI name
- sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description
+ const char* pUINameID; // resource ID to UI name
+ const char** pDescrID; // resource ID to description, parameter names and ~ description
// pCompName was originally meant to be able to load Excel documents that for
// some time were stored with localized function names.
// This is not relevant to this add-in, so we only supply the same
@@ -82,12 +74,12 @@ struct ScaFuncDataBase
class ScaFuncData final
{
private:
- OUString aIntName; // internal name (get***)
- sal_uInt16 nUINameID; // resource ID to UI name
- sal_uInt16 nDescrID; // leads also to parameter descriptions!
- sal_uInt16 nParamCount; // num of parameters
- std::vector<OUString> aCompList; // list of all valid names
- ScaCategory eCat; // function category
+ OUString aIntName; // internal name (get***)
+ const char* pUINameID; // resource ID to UI name
+ const char** pDescrID; // leads also to parameter descriptions!
+ sal_uInt16 nParamCount; // num of parameters
+ std::vector<OUString> aCompList; // list of all valid names
+ ScaCategory eCat; // function category
bool bDouble; // name already exist in Calc
bool bWithOpt; // first parameter is internal
@@ -95,8 +87,8 @@ public:
ScaFuncData(const ScaFuncDataBase& rBaseData);
~ScaFuncData();
- sal_uInt16 GetUINameID() const { return nUINameID; }
- sal_uInt16 GetDescrID() const { return nDescrID; }
+ const char* GetUINameID() const { return pUINameID; }
+ const char** GetDescrID() const { return pDescrID; }
ScaCategory GetCategory() const { return eCat; }
bool IsDouble() const { return bDouble; }
@@ -140,23 +132,23 @@ class ScaPricingAddIn : public ::cppu::WeakImplHelper<
private:
css::lang::Locale aFuncLoc;
css::lang::Locale* pDefLocales;
- ResMgr* pResMgr;
+ std::locale aResLocale;
sca::pricing::ScaFuncDataList* pFuncDataList;
void InitDefLocales();
const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
- /// @throws css::uno::RuntimeException
- ResMgr& GetResMgr();
void InitData();
/// @throws css::uno::RuntimeException
- OUString GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex );
+ OUString GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex);
public:
ScaPricingAddIn();
virtual ~ScaPricingAddIn() override;
+ OUString ScaResId(const char* pResId);
+
static OUString getImplementationName_Static();
static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
diff --git a/scaddins/source/pricing/pricing.src b/scaddins/source/pricing/pricing.src
deleted file mode 100644
index d1ed46a08898..000000000000
--- a/scaddins/source/pricing/pricing.src
+++ /dev/null
@@ -1,153 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include "pricing.hrc"
-
-// function and parameter description
-StringArray PRICING_FUNCDESC_OptBarrier
-{
- ItemList [ en-US ] =
- {
- < "Pricing of a barrier option"; > ;
- < "spot"; > ;
- < "Price/value of the underlying asset"; > ;
- < "vol"; > ;
- < "Annual volatility of the underlying asset"; > ;
- < "r"; > ;
- < "Interest rate (continuously compounded)"; > ;
- < "rf"; > ;
- < "Foreign interest rate (continuously compounded)"; > ;
- < "T"; > ;
- < "Time to maturity of the option in years"; > ;
- < "strike"; > ;
- < "Strike level of the option"; > ;
- < "barrier_low"; > ;
- < "Lower barrier (set to 0 for no lower barrier)"; > ;
- < "barrier_up"; > ;
- < "Upper barrier (set to 0 for no upper barrier)"; > ;
- < "rebate"; > ;
- < "Amount of money paid at maturity if barrier was hit"; > ;
- < "put/call"; > ;
- < "String to define if the option is a (p)ut or a (c)all"; > ;
- < "knock in/out"; > ;
- < "String to define if the option is of type knock-(i)n or knock-(o)ut"; > ;
- < "barrier_type"; > ;
- < "String to define whether the barrier is observed (c)ontinuously or only at the (e)nd/maturity"; > ;
- < "greek"; > ;
- < "Optional parameter, if left out then the function simply returns the option price; if set, the function returns price sensitivities (Greeks) to one of the input parameters; possible values are (d)elta, (g)amma, (t)heta, v(e)ga, v(o)lga, v(a)nna, (r)ho, rho(f)"; > ;
- };
-};
-
-StringArray PRICING_FUNCDESC_OptTouch
-{
- ItemList [ en-US ] =
- {
- < "Pricing of a touch/no-touch option"; > ;
- < "spot"; > ;
- < "Price/value of the underlying asset"; > ;
- < "vol"; > ;
- < "Annual volatility of the underlying asset"; > ;
- < "r"; > ;
- < "Interest rate (continuously compounded)"; > ;
- < "rf"; > ;
- < "Foreign interest rate (continuously compounded)"; > ;
- < "T"; > ;
- < "Time to maturity of the option in years"; > ;
- < "barrier_low"; > ;
- < "Lower barrier (set to 0 for no lower barrier)"; > ;
- < "barrier_up"; > ;
- < "Upper barrier (set to 0 for no upper barrier)"; > ;
- < "foreign/domestic"; > ;
- < "String to define if the option pays one unit of (d)omestic currency (cash or nothing) or (f)oreign currency (asset or nothing)"; > ;
- < "knock in/out"; > ;
- < "String to define if the option is of type knock-(i)n (touch) or knock-(o)ut (no-touch)"; > ;
- < "barrier_type"; > ;
- < "String to define whether the barrier is observed (c)ontinuously or only at the (e)nd/maturity"; > ;
- < "greek"; > ;
- < "Optional parameter, if left out then the function simply returns the option price; if set, the function returns price sensitivities (Greeks) to one of the input parameters; possible values are (d)elta, (g)amma, (t)heta, v(e)ga, v(o)lga, v(a)nna, (r)ho, rho(f)"; > ;
- };
-};
-
-StringArray PRICING_FUNCDESC_OptProbHit
-{
- ItemList [ en-US ] =
- {
- < "Probability that an asset hits a barrier assuming it follows dS/S = mu dt + vol dW"; > ;
- < "spot"; > ;
- < "Price/value S of the underlying asset"; > ;
- < "vol"; > ;
- < "Annual volatility of the underlying asset"; > ;
- < "drift"; > ;
- < "Parameter mu in dS/S = mu dt + vol dW"; > ;
- < "T"; > ;
- < "Time to maturity"; > ;
- < "barrier_low"; > ;
- < "Lower barrier (set to 0 for no lower barrier)"; > ;
- < "barrier_up"; > ;
- < "Upper barrier (set to 0 for no upper barrier)"; > ;
- };
-};
-
-StringArray PRICING_FUNCDESC_OptProbInMoney
-{
- ItemList [ en-US ] =
- {
- < "Probability that an asset will at maturity end up between two barrier levels, assuming it follows dS/S = mu dt + vol dW (if the last two optional parameters (strike, put/call) are specified, the probability of S_T in [strike, upper barrier] for a call and S_T in [lower barrier, strike] for a put will be returned)"; > ;
- < "spot"; > ;
- < "Price/value of the asset"; > ;
- < "vol"; > ;
- < "Annual volatility of the asset"; > ;
- < "drift"; > ;
- < "Parameter mu from dS/S = mu dt + vol dW"; > ;
- < "T"; > ;
- < "Time to maturity in years"; > ;
- < "barrier_low"; > ;
- < "Lower barrier (set to 0 for no lower barrier)"; > ;
- < "barrier_up"; > ;
- < "Upper barrier (set to 0 for no upper barrier)"; > ;
- < "put/call"; > ;
- < "Optional (p)ut/(c)all indicator"; > ;
- < "strike"; > ;
- < "Optional strike level"; > ;
- };
-};
-
-// function names as accessible from cells
-
-String PRICING_FUNCNAME_OptBarrier
-{
- Text [ en-US ] = "OPT_BARRIER";
-};
-
-String PRICING_FUNCNAME_OptTouch
-{
- Text [ en-US ] = "OPT_TOUCH";
-};
-
-String PRICING_FUNCNAME_OptProbHit
-{
- Text [ en-US ] = "OPT_PROB_HIT";
-};
-
-String PRICING_FUNCNAME_OptProbInMoney
-{
- Text [ en-US ] = "OPT_PROB_INMONEY";
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */