Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "sal/config.h"
21 : :
22 : : #include <map>
23 : :
24 : : #include "boost/noncopyable.hpp"
25 : : #include "boost/scoped_ptr.hpp"
26 : : #include "com/sun/star/lang/Locale.hpp"
27 : : #include "rtl/instance.hxx"
28 : : #include "rtl/ustrbuf.hxx"
29 : : #include "rtl/ustring.hxx"
30 : : #include "sal/types.h"
31 : : #include "tools/resmgr.hxx"
32 : : #include "tools/simplerm.hxx"
33 : :
34 : : #include "getstringresource.hxx"
35 : :
36 : : namespace {
37 : :
38 : : namespace css = com::sun::star;
39 : :
40 [ # # ]: 0 : class ResMgrMap: private boost::noncopyable {
41 : : public:
42 : : ~ResMgrMap();
43 : :
44 : : SimpleResMgr * get(css::lang::Locale const & locale);
45 : :
46 : : private:
47 : : typedef std::map< rtl::OUString, SimpleResMgr * > Map;
48 : :
49 : : Map map_;
50 : : // one SimpleResMgr for each language for which a resource was requested
51 : : // (when using the "non-simple" resmgr, the first request for any
52 : : // language wins, any further requests for any other languages supply
53 : : // the resmgr of the first call; for the simple resmgr we have a mgr
54 : : // for each language ever requested)
55 : : };
56 : :
57 : 0 : ResMgrMap::~ResMgrMap() {
58 [ # # ]: 0 : for (Map::iterator i(map_.begin()); i != map_.end(); ++i) {
59 [ # # ][ # # ]: 0 : delete i->second;
60 : : }
61 : 0 : }
62 : :
63 : 0 : SimpleResMgr * ResMgrMap::get(css::lang::Locale const & locale) {
64 [ # # ]: 0 : rtl::OUStringBuffer buf(locale.Language);
65 [ # # ]: 0 : buf.append(sal_Unicode('-'));
66 [ # # ]: 0 : buf.append(locale.Country);
67 [ # # ]: 0 : rtl::OUString code(buf.makeStringAndClear());
68 [ # # ]: 0 : Map::iterator i(map_.find(code));
69 [ # # ]: 0 : if (i == map_.end()) {
70 : : boost::scoped_ptr< SimpleResMgr > mgr(
71 [ # # ][ # # ]: 0 : new SimpleResMgr("svl", locale));
72 [ # # ]: 0 : i = map_.insert(Map::value_type(code, mgr.get())).first;
73 [ # # ][ # # ]: 0 : mgr.reset();
74 : : }
75 : 0 : return i->second;
76 : : }
77 : :
78 : : struct theResMgrMap: public rtl::Static< ResMgrMap, theResMgrMap > {};
79 : :
80 : : }
81 : :
82 : : namespace svl {
83 : :
84 : 0 : rtl::OUString getStringResource(sal_uInt16 id, css::lang::Locale const & locale)
85 : : {
86 : 0 : return theResMgrMap::get().get(locale)->ReadString(id);
87 : : }
88 : :
89 : : }
90 : :
91 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|