office-gobmx/scaddins/source/datefunc/datefunc.hxx
Caolán McNamara 00657aef09 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::resource::OfficeResourceLoader
      com::sun::resource::XResourceBundleLoader
      com::sun::resource::XResourceBundle
    when translating strings via uno apis
      com.sun.star.resource.StringResourceWithLocation
    can continue to be used

Change-Id: Ia2594a2672b7301d9c3421fdf31b6cfe7f3f8d0a
2017-07-21 08:20:50 +01:00

199 lines
8.8 KiB
C++

/* -*- 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 .
*/
// date functions add in
#ifndef INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
#define INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
#include <string.h>
#include <vector>
#include <memory>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sheet/XAddIn.hpp>
#include <com/sun/star/sheet/XCompatibilityNames.hpp>
#include <com/sun/star/sheet/addin/XDateFunctions.hpp>
#include <com/sun/star/sheet/addin/XMiscFunctions.hpp>
#include <cppuhelper/implbase.hxx>
enum class ScaCategory
{
DateTime,
Text,
Finance,
Inf,
Math,
Tech
};
struct ScaFuncDataBase
{
const sal_Char* pIntName; // internal name (get***)
const char* pUINameID; // resource ID to UI name
const char** pDescrID; // resource ID to description, parameter names and ~ description
const char** pCompListID; // list of valid names
sal_uInt16 nParamCount; // number of named / described parameters
ScaCategory eCat; // function category
bool bDouble; // name already exist in Calc
bool bWithOpt; // first parameter is internal
};
class ScaFuncData final
{
private:
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
public:
ScaFuncData(const ScaFuncDataBase& rBaseData);
~ScaFuncData();
const char* GetUINameID() const { return pUINameID; }
const char** GetDescrID() const { return pDescrID; }
ScaCategory GetCategory() const { return eCat; }
bool IsDouble() const { return bDouble; }
sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
bool Is( const OUString& rCompare ) const
{ return aIntName == rCompare; }
const std::vector<OUString>& GetCompNameList() const { return aCompList; }
};
typedef std::vector<ScaFuncData> ScaFuncDataList;
// Predicate for use with std::find_if
struct FindScaFuncData
{
const OUString& m_rId;
explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
};
css::uno::Reference< css::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance(
const css::uno::Reference< css::lang::XMultiServiceFactory >& );
// THE AddIn class for date functions
class ScaDateAddIn : public ::cppu::WeakImplHelper<
css::sheet::XAddIn,
css::sheet::XCompatibilityNames,
css::sheet::addin::XDateFunctions,
css::sheet::addin::XMiscFunctions,
css::lang::XServiceName,
css::lang::XServiceInfo >
{
private:
css::lang::Locale aFuncLoc;
std::unique_ptr< css::lang::Locale[] > pDefLocales;
std::locale aResLocale;
std::unique_ptr< ScaFuncDataList > pFuncDataList;
void InitDefLocales();
const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
void InitData();
/// @throws css::uno::RuntimeException
OUString GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex);
public:
ScaDateAddIn();
OUString ScaResId(const char* pId);
static OUString getImplementationName_Static();
static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
// XAddIn
virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
// XCompatibilityNames
virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
// XLocalizable
virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
virtual css::lang::Locale SAL_CALL getLocale() override;
// XServiceName
virtual OUString SAL_CALL getServiceName() override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
// methods from own interfaces start here
// XDateFunctions
virtual sal_Int32 SAL_CALL getDiffWeeks(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nEndDate, sal_Int32 nStartDate,
sal_Int32 nMode ) override;
virtual sal_Int32 SAL_CALL getDiffMonths(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nEndDate, sal_Int32 nStartDate,
sal_Int32 nMode ) override;
virtual sal_Int32 SAL_CALL getDiffYears(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nEndDate, sal_Int32 nStartDate,
sal_Int32 nMode ) override;
virtual sal_Int32 SAL_CALL getIsLeapYear(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nDate ) override;
virtual sal_Int32 SAL_CALL getDaysInMonth(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nDate ) override;
virtual sal_Int32 SAL_CALL getDaysInYear(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nDate ) override;
virtual sal_Int32 SAL_CALL getWeeksInYear(
const css::uno::Reference< css::beans::XPropertySet >& xOptions,
sal_Int32 nDate ) override;
// XMiscFunctions
virtual OUString SAL_CALL getRot13(
const OUString& aSrcText ) override;
};
#endif // INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */