1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_CELLKEY_TRANSLATOR_HXX 29 #define SC_CELLKEY_TRANSLATOR_HXX 30 31 #include "global.hxx" 32 #include "formula/opcode.hxx" 33 #include "unotools/transliterationwrapper.hxx" 34 #include <hash_map> 35 #include <list> 36 #include <memory> 37 38 #include <com/sun/star/lang/Locale.hpp> 39 40 struct TransItem; 41 42 struct ScCellKeyword 43 { 44 const sal_Char* mpName; 45 OpCode meOpCode; 46 const ::com::sun::star::lang::Locale& mrLocale; 47 48 ScCellKeyword(const sal_Char* pName, OpCode eOpCode, const ::com::sun::star::lang::Locale& rLocale); 49 }; 50 51 typedef ::std::hash_map< String, ::std::list<ScCellKeyword>, ScStringHashCode, ::std::equal_to<String> > ScCellKeywordHashMap; 52 53 /** Translate cell function keywords. 54 55 This class provides a convenient way to translate a string keyword used as 56 a cell function argument. Since Calc's built-in cell functions don't 57 localize string keywords, this class is used mainly to deal with an Excel 58 document where string names may be localized. 59 60 To use, simply call the 61 62 ScCellKeywordTranslator::transKeyword(...) 63 64 function. 65 66 Note that when the locale and/or the opcode is specified, the function 67 tries to find a string with matching locale and/or opcode. But when it 68 fails to find one that satisfies the specified locale and/or opcode, it 69 returns a translated string with non-matching locale and/or opcode if 70 available. */ 71 class ScCellKeywordTranslator 72 { 73 public: 74 static void transKeyword(String& rName, const ::com::sun::star::lang::Locale* pLocale = NULL, OpCode eOpCode = ocNone); 75 ~ScCellKeywordTranslator(); 76 77 private: 78 ScCellKeywordTranslator(); 79 80 void init(); 81 void addToMap(const String& rKey, const sal_Char* pName, 82 const ::com::sun::star::lang::Locale& rLocale, 83 OpCode eOpCode = ocNone); 84 void addToMap(const TransItem* pItems, const ::com::sun::star::lang::Locale& rLocale); 85 86 static ::std::auto_ptr<ScCellKeywordTranslator> spInstance; 87 ScCellKeywordHashMap maStringNameMap; 88 ::utl::TransliterationWrapper maTransWrapper; 89 }; 90 91 #endif 92