1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
24 #include <boost/noncopyable.hpp>
25 #include <boost/scoped_ptr.hpp>
26 #include <i18nlangtag/languagetag.hxx>
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>
34 #include "getstringresource.hxx"
38 class ResMgrMap
: private boost::noncopyable
{
42 SimpleResMgr
* get(LanguageTag
const & locale
);
45 typedef std::map
< OUString
, SimpleResMgr
* > Map
;
48 // one SimpleResMgr for each language for which a resource was requested
49 // (when using the "non-simple" resmgr, the first request for any
50 // language wins, any further requests for any other languages supply
51 // the resmgr of the first call; for the simple resmgr we have a mgr
52 // for each language ever requested)
55 ResMgrMap::~ResMgrMap() {
56 for (Map::iterator
i(map_
.begin()); i
!= map_
.end(); ++i
) {
61 SimpleResMgr
* ResMgrMap::get(LanguageTag
const & locale
) {
62 OUString
code( locale
.getBcp47());
63 Map::iterator
i(map_
.find(code
));
64 if (i
== map_
.end()) {
65 boost::scoped_ptr
< SimpleResMgr
> mgr(
66 new SimpleResMgr("svl", locale
));
67 i
= map_
.insert(Map::value_type(code
, mgr
.get())).first
;
73 struct theResMgrMap
: public rtl::Static
< ResMgrMap
, theResMgrMap
> {};
79 OUString
getStringResource(sal_uInt16 id
, LanguageTag
const & locale
)
81 return theResMgrMap::get().get(locale
)->ReadString(id
);
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */