bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / misc / getstringresource.cxx
blob086c704d59cc43f3f2bdd5b0eac10dfffc53ff89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <map>
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"
36 namespace {
38 class ResMgrMap: private boost::noncopyable {
39 public:
40 ~ResMgrMap();
42 SimpleResMgr * get(LanguageTag const & locale);
44 private:
45 typedef std::map< OUString, SimpleResMgr * > Map;
47 Map 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) {
57 delete i->second;
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;
68 mgr.reset();
70 return i->second;
73 struct theResMgrMap: public rtl::Static< ResMgrMap, theResMgrMap > {};
77 namespace svl {
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: */